18
Anypoint MQ Acknowledgement Mode

Anypoint mq acknowledgement mode

Embed Size (px)

Citation preview

Page 1: Anypoint mq acknowledgement mode

Anypoint MQ Acknowledgement Mode

Page 2: Anypoint mq acknowledgement mode

• Anypoint MQ lets you determine how to process messages in Anypoint Studio using the Anypoint MQ connector.

• Two acknowledgement responses can occur:

• Acknowledgement (ack) - Indicates that an application has received a message.

• Negative Acknowledgement (nack) - Indicates that an application doesn’t want the current message. MQ returns the message to the queue so that another application can receive the message.

• The Anypoint MQ connector provides tools for setting these states globally or locally in your Studio application.

Page 3: Anypoint mq acknowledgement mode

Global and Local States

• The Anypoint MQ connector provides global and local states for specifying how your Studio application receives messages from a queue.

Page 4: Anypoint mq acknowledgement mode

Global State

• Lets you specify use the Studio Global Element Properties menu to specify a strategy for processing all messages in a flow. The global state provides these choices:

• AUTO - The Anypoint MQ connector automatically sends an Ack or Nack at the end of a flow depending on whether the MQ connector detects a Catch Exception Strategy (ACK) or a Rollback Exception Strategy (NACK). See Creating an Auto Acknowledge Flow in Anypoint Studio for an example.

• There are two possible outcomes:

• ACK - The flow succeeds or a Catch Exception Strategy occurs. This code shows the Catch Exception Strategy:

Page 5: Anypoint mq acknowledgement mode

• MANUAL - An application indicates that it sends its own Ack or Nack using the Anypoint MQ connector local state. The MQ connector doesn’t provide any actions automatically. See Creating a Manual Acknowledge Flow in Anypoint Studio for an example.

• NONE - An application receives a message and the MQ connector immediately acknowledges and deletes the message. This state risks losing the message if it is not consumed correctly, but is typically used when there is a flow of constantly updating messages, such as a news feed where each subsequent message provides more detail on any messages that preceded the message. This state takes a risk, but makes coding easier. See Creating a None Acknowledge Flow in Anypoint Studio for an example.

Page 6: Anypoint mq acknowledgement mode

Local State

• Lets you manually add Anypoint MQ connector instances into your flow with the Operation field set to ack or nack depending on whether the application is receiving or rejecting a message.

• You can set a local state using the Anypoint MQ connector’s Operation field:

Page 7: Anypoint mq acknowledgement mode

Creating an Auto Acknowledge Flow in Anypoint Studio

• If you are using the auto state, set a choice-exception-strategy and the Anypoint MQ connector automatically sends the ack or nack depending on what exception choices you make. The code that follows illustrates the use of the auto state.

• The following code demonstrates the Studio flows:

Page 8: Anypoint mq acknowledgement mode
Page 9: Anypoint mq acknowledgement mode

• In this example, are these two flows:

• autoHttp - Sets up an HTTP Connector to listen at 0.0.0.0:8081, sets an Anypoint MQ connector to publish messages, and sets the acknowledgement mode to auto.

• autoMq - Sets an Anypoint MQ connector to consume messages and uses the Java class RandomError to create possible exceptions to cause the Auto function to send an acknowledgment or a negative acknowledgement depending on the choices. The logger lists the ACK or NACK choices on the console.

• The Error handling section of the flow contains a Catch Exception Strategy to cause the MQ connector to send the ACK, and a Rollback Exception Strategy to cause the MQ connector to send the NACK.

Page 10: Anypoint mq acknowledgement mode

Auto XML Code

• See Random Error Generator for an explanation of how exceptions are thrown using a Java testing program, which is called in this statement:

• <component class="ackmodes.RandomError" doc:name="Java"/>

Page 11: Anypoint mq acknowledgement mode

Creating a Manual Acknowledge Flow in Anypoint Studio

• You can set the Manual Acknowledgement Mode from the Anypoint MQ connector’s Global Element Properties:

Page 12: Anypoint mq acknowledgement mode

• In the manual flow, the choice-exception-strategy is also set as in the flow. In this case, the application uses individual Anypoint MQ connector instances with the operation set to either Ack or Nack depending on exceptions sent by the Random Error Java Class.

Page 13: Anypoint mq acknowledgement mode
Page 14: Anypoint mq acknowledgement mode

Manual XML Code

• See Random Error Generator for an explanation of how exceptions are thrown using a Java testing program, which is called in this statement:

• <component class="ackmodes.RandomError" doc:name="Java"/>

Page 15: Anypoint mq acknowledgement mode

Creating a None Acknowledge Mode in Anypoint Studio

Page 16: Anypoint mq acknowledgement mode

• In the NONE flow, the Anypoint MQ connector always sends an ACK no matter what occurs. The example that follows emphasizes this risk by using the Java class RandomError to create possible exceptions, but ignores the exceptions and sends the ACK regardless:

Page 17: Anypoint mq acknowledgement mode

None XML Code• <http:listener-config name="HTTP_Listener_Configuration_none" host="0.0.0.0" port="8083" doc:name="HTTP

Listener Configuration"/>

• <flow name="noneHttp">• <http:listener config-ref="HTTP_Listener_Configuration_none" path="/" doc:name="HTTP"/>• <anypoint-mq:publish config-ref="Anypoint_MQ_Configuration" destination="none" doc:name="Anypoint MQ"/>• </flow>

• <flow name="noneMq">• <anypoint-mq:subscriber config-ref="Anypoint_MQ_Configuration" destination="none" doc:name="Anypoint MQ"

pollingTime="10000" acknowledgementMode="NONE"/>• <component class="ackmodes.RandomError" doc:name="Java"/>• <logger level="ERROR" doc:name="Logger" message="Always ACKs as soon as a message is received"/>• </flow>

Page 18: Anypoint mq acknowledgement mode

Random Error Generator

Value Error State What happens in the Studio Flow

0 - 32 No error, returns the passed event context.

Passes through and the application sends an ACK

33 - 65 Error, returns an illegal state exception.

Application sends a NACK

66 - 100 Error, returns an unsupported operation exception.

Application sends an ACK