I’m setting up a flow to pull data from a table into another, mark the rows processed, and email the results. I used an Aggregator (see:
How do I get a Mule to return multiple rows from a JDBC query as a single transaction?) to combine all the rows into one email, but after adding the Aggregator the SMTP endpoint fails to run on a second iteration…
- Start Mule Flow.
- Insert Rows which causes the flow to run.
- SQL scripts and SMTP endpoint runs.
- Insert More rows and the flow runs again.
-
Only SQL scripts run… SMTP endpoint doesn’t run at all.
<flow name="Invoice_Workflow2Flow1" doc:name="Ross_invoice_Workflow2Flow1" processingStrategy="asynchronous"> <jdbc:inbound-endpoint queryKey="GetUnprocessedInvoices" queryTimeout="10000" pollingFrequency="10000" connector-ref="Database" doc:name="Get invoice run"> <jdbc:query key="GetUnprocessedInvoices" value="SELECT INVOICE_NUMBER, ROWID FROM FIN.LHF_INVOICE_WORKFLOW WHERE (STATUS_FLAG = 'N')"/> </jdbc:inbound-endpoint> <jdbc:outbound-endpoint exchange-pattern="one-way" queryKey="insert_invoice_run" queryTimeout="10000" connector-ref="SPTSQL01_APPS_custom_app_data" doc:name="Load to custom_app_data"> <jdbc:query key="insert_invoice_run" value="INSERT INTO lhf_ros_invoice_workflow ([INVOICE_NUMBER] VALUES #[map-payload:INVOICE_NUMBER])"/> </jdbc:outbound-endpoint> <jdbc:outbound-endpoint exchange-pattern="one-way" queryKey="MarkAsProcessed" queryTimeout="10000" connector-ref="DatabaseMuleLogin" doc:name="Mark Processed in Ross"> <jdbc:query key="MarkAsProcessed" value="UPDATE FIN.LHF_INVOICE_WORKFLOW SET STATUS_FLAG = 'P' WHERE (ROWID = #[map-payload:ROWID])"/> </jdbc:outbound-endpoint> <message-properties-transformer doc:name="Message Properties"> <add-message-property key="MULE_CORRELATION_GROUP_SIZE" value="1000"/> <add-message-property key="MULE_CORRELATION_ID" value="1"/> </message-properties-transformer> <collection-aggregator timeout="1000" failOnTimeout="false" doc:name="Collection Aggregator"/> <smtp:outbound-endpoint host="mail.example.com" to="test@example.com" from="muleservice@example.com" subject="[Invoice Workflow] Exceptions" responseTimeout="10000" doc:name="SMTP"/> </flow>
Here’s the log of what happens if it’s useful…
(first run works fine, SMTP endpoint runs)
INFO 2012-12-06 09:08:52,143 [[ross_invoice_workflow].DatabaseMuleLogin.dispatcher.02] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:08:52,159 [[ross_invoice_workflow].DatabaseMuleLogin.dispatcher.03] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:08:52,180 [[ross_invoice_workflow].DatabaseMuleLogin.dispatcher.01] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:08:52,223 [[ross_invoice_workflow].SPTSQL01_APPS_custom_app_data.dispatcher.01] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:08:52,223 [[ross_invoice_workflow].SPTSQL01_APPS_custom_app_data.dispatcher.03] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:08:52,223 [[ross_invoice_workflow].SPTSQL01_APPS_custom_app_data.dispatcher.02] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:08:53,131 [[ross_invoice_workflow].connector.smtp.mule.default.dispatcher.01] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.email.transformers.ObjectToMimeMessage
INFO 2012-12-06 09:08:53,138 [[ross_invoice_workflow].connector.smtp.mule.default.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Initialising: ‘connector.smtp.mule.default.dispatcher.1935379626’. Object is: SmtpMessageDispatcher
INFO 2012-12-06 09:08:53,174 [[ross_invoice_workflow].connector.smtp.mule.default.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Starting: ‘connector.smtp.mule.default.dispatcher.1935379626’. Object is: SmtpMessageDispatcher
(insert more rows, SQL endpoints run but SMTP does not…)
INFO 2012-12-06 09:09:22,111 [[ross_invoice_workflow].DatabaseMuleLogin.dispatcher.03] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:09:22,129 [[ross_invoice_workflow].DatabaseMuleLogin.dispatcher.02] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:09:22,146 [[ross_invoice_workflow].DatabaseMuleLogin.dispatcher.01] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:09:22,168 [[ross_invoice_workflow].SPTSQL01_APPS_custom_app_data.dispatcher.03] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:09:22,168 [[ross_invoice_workflow].SPTSQL01_APPS_custom_app_data.dispatcher.01] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:09:22,168 [[ross_invoice_workflow].SPTSQL01_APPS_custom_app_data.dispatcher.02] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
(insert more rows, same thing)
INFO 2012-12-06 09:09:22,111 [[ross_invoice_workflow].DatabaseMuleLogin.dispatcher.03] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:09:22,129 [[ross_invoice_workflow].DatabaseMuleLogin.dispatcher.02] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:09:22,146 [[ross_invoice_workflow].DatabaseMuleLogin.dispatcher.01] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:09:22,168 [[ross_invoice_workflow].SPTSQL01_APPS_custom_app_data.dispatcher.03] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:09:22,168 [[ross_invoice_workflow].SPTSQL01_APPS_custom_app_data.dispatcher.01] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2012-12-06 09:09:22,168 [[ross_invoice_workflow].SPTSQL01_APPS_custom_app_data.dispatcher.02] org.mule.transport.jdbc.sqlstrategy.SimpleUpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
The problem comes from the fact that the
MULE_CORRELATION_IDis set to1. Since the group with this correlation ID has been processed, it’s impossible to keep using this ID after the group has been delivered. In my striped down test, I actually receive errors when I try to feed more events with the same correlation ID after the first group has been released.I suggest you add a column in the select query that returns the same value for all the selected rows but that changes every time Mule runs the query. For example, the query could receive a UUID generated by Mule with an expression like
#[java.util.UUID.randomUUID().toString()]and return the value in a column. Then you could use this value as the correlation ID as it will be the same for the group of selected record.Assuming the added column is called “CID”, then the config would be:
(Note that
set-propertyis a more expressive config element thanmessage-properties-transformer)