0

Mule フローがあり、データベースから行をフェッチしてファイルに書き込む必要があります。現在、データベースには 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>

問題は、アプリケーションの起動時に、DB から 100 行のうち 5 行のみをフェッチしてファイルに書き込み、残りの行がフェッチされず、新しいファイルが作成されないことです...しかし、5 をフェッチしたい30秒ごとに行を削除し、最後に新しいファイルに書き込みます..私は何か間違ったことをしていますか?? 以下を参考にしました:- Mule が JDBC クエリから複数の行を 1 つのトランザクションとして返すようにするにはどうすればよいですか?

更新されたフロー:-

<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>

現在、行ごとにファイルを作成しています...

4

2 に答える 2

0

したがって、ポイント 3 に関する David の提案に従って、次のようにcorrelation ID修正しました<add-message-property key="MULE_CORRELATION_ID" value="1"/>
が修正されたためcorrelation ID、collection-aggregator はこの ID のすべてのメッセージを集約し、そこで停止しています。
これが同じ問題を抱えている他の誰かに役立ち、私のために働いていることを願っています.

于 2017-04-09T19:39:56.070 に答える
0

いくつかの問題があります。

  • クエリは、5 行だけではなくすべての行を選択します。
  • 選択したレコードをマークするための更新クエリがないため、同じレコードが何度も取得されます。
  • 相関 ID は次のように固定されています<add-message-property key="MULE_CORRELATION_ID" value="1"/>。相関 ID が固定されているcollection-aggregatorため、 はこの ID の 5 つのメッセージを集約し、そこで停止します。この ID 宛ての新しいメッセージは破棄されます。代わりに、5 つの行に同じ値を生成する MEL 式を使用します。どの式を使用するかは自由です。たとえば、30 秒の時間ウィンドウに一定の値を提供する時間のモジュロのようなものにすることができます...
于 2014-07-23T19:22:55.027 に答える