我有一个Mule流,我需要从Database中获取行并写入一个文件。现在我在数据库中有100行,我需要一次从DB中获取5行并再次写入文件经过几个时间间隔说30秒后再获取5行并将有效负载写入文件中..现在我的流程如下: -
<spring:beans>
<spring:bean id="DB_Source" name="DB_Source" class="org.enhydra.jdbc.standard.StandardDataSource">
<spring:property name="url" value="${url}"/>
<spring:property name="driverName" value="${driverName}"/>
</spring:bean>
</spring:beans>
<jdbc-ee:connector name="Database_Global" dataSource-ref="DB_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database" transactionPerMessage="true">
<!-- Here transactionPerMessage="false" so that it retrieve and display all the row at once-->
<jdbc-ee:query key="RetriveQuery" value="select * from getData"/> <!-- or we can use CALL sp_retrieveData(@Id=13) -->
</jdbc-ee:connector>
<context:property-placeholder location="classpath:conf/DBConnectionProp.properties"/>
<flow name="InboundJDBC" doc:name="InboundJDBC" initialState="started">
<jdbc-ee:inbound-endpoint queryTimeout="-1" pollingFrequency="1000" doc:name="Database" connector-ref="Database_Global" queryKey="RetriveQuery">
<jdbc-ee:transaction action="ALWAYS_BEGIN" />
<!-- <property key="receiveMessageInTransaction" value="true"/> --><!-- This to receive all the row in once -->
</jdbc-ee:inbound-endpoint>
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="MULE_CORRELATION_GROUP_SIZE" value="5"/> <!-- Set the number of rows to be return at a time -->
<add-message-property key="MULE_CORRELATION_ID" value="1"/>
</message-properties-transformer>
<collection-aggregator timeout="5000" failOnTimeout="false" doc:name="Collection Aggregator"/>
<logger message="JDBC Transaction #[message.payload] **************" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="E:\backup\test\ss" outputPattern="#[java.util.UUID.randomUUID().toString()].txt" responseTimeout="10000" doc:name="File"/>
</flow>
</mule>
现在的问题是,当应用程序启动时,它只从100行中的DB中获取5行并写入文件,然后不会获取剩余的行并且不会创建新文件...但我想要每30秒后获取5行并在最后将其写入新文件中..我做错了什么?我已将以下内容作为参考: - How do I get a Mule to return multiple rows from a JDBC query as a single transaction?
更新了流程: -
<flow name="InboundJDBC" doc:name="InboundJDBC" initialState="started">
<jdbc-ee:inbound-endpoint queryTimeout="-1" pollingFrequency="1000" doc:name="Database" connector-ref="Database_Global" queryKey="RetriveQuery">
<jdbc-ee:transaction action="ALWAYS_BEGIN" />
<!-- <property key="receiveMessageInTransaction" value="true"/> --><!-- This to receive all the row in once -->
</jdbc-ee:inbound-endpoint>
<set-property propertyName="#[message.inboundProperties['requestId']]" value="#[java.util.UUID.randomUUID().toString()]" doc:name="Property"/>
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="MULE_CORRELATION_GROUP_SIZE" value="5"/> <!-- Set the number of rows to be return at a time -->
<add-message-property key="MULE_CORRELATION_ID" value="#[message.inboundProperties['requestId']]"/>
</message-properties-transformer>
<collection-aggregator timeout="5000" failOnTimeout="false" doc:name="Collection Aggregator"/>
<logger message="JDBC Transaction #[message.payload] **************" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="E:\backup\test\ss" outputPattern="#[java.util.UUID.randomUUID().toString()].txt" responseTimeout="10000" doc:name="File"/>
</flow>
现在它每行创建文件......
答案 0 :(得分:0)
我看到几个问题:
<add-message-property key="MULE_CORRELATION_ID" value="1"/>
。由于相关ID是固定的,collection-aggregator
将为此ID聚合5条消息并将停在那里。此ID的任何新消息都将被丢弃。而是使用MEL表达式为五行产生相同的值:要使用的表达式取决于您,例如,它可以是某种模时,为30秒时间窗口提供常量值... < / LI>
答案 1 :(得分:0)
所以,根据David关于第3点的建议,我将correlation ID
修改为:<add-message-property key="MULE_CORRELATION_ID" value="1"/>
。
从现在开始,correlation ID
被修复,集合聚合器聚合此ID的所有消息并停在那里
希望这可以帮助其他人有同样的问题,并为我工作。