メッセージの肯定応答 (ACK) は、メッセージが処理されたので再配信されないようにキューから削除する必要があることをブローカーに通知します。
手動モードを使用して ACK 操作を実行する場合、肯定応答トークン (ackToken) を使用してメッセージを識別する必要があります。これはメッセージ属性の ackToken 項目にあります。
<flow name="consumerWithManualAck">
<scheduler>
<scheduling-strategy >
<fixed-frequency />
</scheduling-strategy>
</scheduler>
<!-- Consume a message -->
<anypoint-mq:consume destination="${destination}"
acknowledgementMode="MANUAL"
config-ref="Anypoint_MQ_Config"/>
<!-- Save the ackToken for future acknowledgment -->
<set-variable variableName="currentAckToken"
value="#[attributes.ackToken]"/>
<!-- Do the required processing of the message -->
<flow-ref name="process-message"/>
<!-- Use the ackToken to ACK the message -->
<anypoint-mq:ack ackToken="#[vars.currentAckToken]"
config-ref="Anypoint_MQ_Config" />
</flow>
メッセージの処理中に void でない操作が起動された場合、Mule メッセージのペイロードと属性が変更されます。処理後に ACK 操作を実行するには、変数に ackToken を保存する必要があります。
後で使用するために属性を保存するには、target および targetValue パラメーターを使用して変数にメッセージ全体を保存します。
<flow name="consumerWithManualAck">
<scheduler>
<scheduling-strategy >
<fixed-frequency />
</scheduling-strategy>
</scheduler>
<!-- Consume a message -->
<anypoint-mq:consume destination="${destination}"
acknowledgementMode="MANUAL"
config-ref="Anypoint_MQ_Config"
target="mqMessage"
targetValue="#[message]"/>
<!--Do any message processing-->
<jms:publish-consume destination="#[vars.mqMessage.attributes.targetDestination]"
config-ref="JMS_Config">
<jms:message>
<jms:body>#[vars.mqMessage.payload]</jms:body>
</jms:message>
</jms:publish-consume>
<!-- Use the ackToken to ACK the message -->
<anypoint-mq:ack ackToken="#[vars.mqMessage.attributes.ackToken]"
config-ref="Anypoint_MQ_Config" />
</flow>