【问题标题】:How to Aggregate Multiple Message in to One Message and print in Mule如何将多条消息聚合为一条消息并在 Mule 中打印
【发布时间】:2014-12-18 23:36:16
【问题描述】:

嗨,我正在使用 Any Point Studio,我有一个场景,Mule 从路径读取假设它正在从某个路径读取 2 个文件,并将这两个文件视为 2 个单独的消息,我想将两者合并为一个.

我也想知道MULE_CORRELATION_GROUP_SIZE的用途为什么要在Aggregator Component之前定义?

请分享代码以使用自定义聚合器实现此目的,或者是他们更好的方法。

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <file:connector name="File" streaming="true" autoDelete="false" validateConnections="true" doc:name="File"/>
    <flow name="mule-file-aggregatorFlow1"  doc:name="mule-file-aggregatorFlow1">
        <file:inbound-endpoint path="\\mulespace\foldername" responseTimeout="10000" doc:name="File" connector-ref="File">
        </file:inbound-endpoint>
        <file:file-to-string-transformer doc:name="File to String"/>
        <message-properties-transformer doc:name="Message Properties">
        <add-message-property key="MULE_CORRELATION_GROUP_SIZE" value="2" />
        </message-properties-transformer>
        <custom-aggregator failOnTimeout="true" class="com.mine.custom.CustomAggregator" doc:name="Custom Aggregator"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
        <logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>

【问题讨论】:

  • 你能描述一下文件的命名模式吗?
  • 是普通的.txt文件
  • 我的意思是名称模式。你应该如何 telate 这两个文件?
  • 在我的场景中,我有 2 个文件,一个是 first.txt,第二个是 second.txt 我想读取两者的内容并合并为一个并打印
  • 如果另一批文件同时到达,会覆盖first.txt和second.txt吗?还会有其他的three.txt和fouth.txt吗?

标签: mule mule-studio mule-el mule-component


【解决方案1】:

在你的文件之后使用它:入站端点:

<scripting:component doc:name="Groovy">
            <scripting:script engine="Groovy"><![CDATA[long now = new java.util.Date().getTime(); 
                long mod = now % 2000; 
                message.setCorrelationId(String.valueOf(now - mod));
                message.setCorrelationGroupSize(100);
                return message;
            ]]></scripting:script>
        </scripting:component>
        <collection-aggregator timeout="3000" failOnTimeout="false" doc:name="Collection Aggregator"/>
        <combine-collections-transformer doc:name="Combine Collections"/>

【讨论】:

  • MULE_CORRELATION_GROUP_SIZE 的用途是什么,在上面的脚本中,如果我是正确的,您正在设置 setCorrelationGroupSize,两者都是相同的,只是想知道设置组大小的用途
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-07
  • 1970-01-01
  • 2016-07-03
相关资源
最近更新 更多