2. • 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.
3. Global and Local States
• The Anypoint MQ connector provides global and local states for
specifying how your Studio application receives messages from a
queue.
4. 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:
5. • 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.
6. 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:
7. 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:
8.
9. • 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.
10. 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"/>
11. Creating a Manual Acknowledge Flow in Anypoint
Studio
• You can set the Manual Acknowledgement Mode from the Anypoint
MQ connector’s Global Element Properties:
12. • 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.
13.
14. 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"/>
16. • 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:
18. 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