JMS Message Rollback and Redelivery icon

JMS Message Rollback and Redelivery

(1 review)

home

Shows how to implement JMS rollback and redelivery within the Anypoint Studio. The JMS connectors in this example are configured to the activeMQ MOM.

screenshot from Anypoint Studio

Example

In this example, a JMS message in a transaction inside Anypoint Studio throws an exception. This message is handled by the Rollback Exception Strategy Component, which rolls back and retries to deliver the same message. After 4 unsuccessful attempts to commit, it successfully sends the message.

Set Up and Run the Example

  1. Open the example application in Anypoint Studio. Do not run the application yet.

  2. Start the ActiveMQ server

    • Navigate to the activeMQ home directory in the command terminal and then use the following command to start the activeMQ server

      bin/activemq start
    • You should get a message that is similar to the one shown below in your command terminal when your activeMQ server is running

      INFO: Using java '/System/Library/Frameworks/JavaVM.framework/Home/bin/java'
      INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
      INFO: pidfile created : . . .
  3. Check if activemq-all-5.10.0.jar is configured to the java build path. Else, if you are running a different version of activeMQ you need to manually configure this. You can do so by following these steps:

    • Configure the project build path by adding the activeMQ jar file to the project folder.
    • Right click the project folder in the Package Explorer. Click Properties/Java Build Path. Under the Libraries tab, click Add External Jars.
    • Now browse to the ActiveMQ home directory and add the jar file named activemq-all-5.10.0.jar - the ActiveMQ version at the time of this topic was 5.10.0). Click Open/Ok.
  4. In the Package Explorer, right-click the project, then select Run As/Mule Application. Studio runs the application in the embedded server.

    Your Mule application is now running!

  5. Log into the ActiveMQ admin console at http://localhost:8161/admin/send.jsp with the default username and password admin. Type in in the Destination field and click Send.

  6. The transaction fails with "MyException" the first four attempts (to simulate an error condition), and then the message is delivered correctly.

  7. Search for "topic1" in http://localhost:8161/admin/topics.jsp and notice that the number under the Messages Enqueued column has increased by 1. This verifies that the message has been delivered correctly and the transaction was successful.

  8. Try removing the maxRedelivery settings from the Active MQ connector configuration. If the transaction fails in a second attempt due to a different error such as maxRedelivery setting exceeded, it is still committed.

Documentation

Read full documentation in GitHub

Examples to Try Next

If you understood this example
Using Transactional Scope in JMS to Database - Understand the concept of transactional scope and rollback error handling strategy.View
If you struggled with this example
Sending JSON to a JMS Queue - Learn how to connect to JMS Queues and Topics.View

Reviews

TypeExample
OrganizationMuleSoft
Published by
MuleSoft Organization
Published onJun 22, 2017
Asset overview

Asset versions for 1.4.x

Asset versions
VersionActions
1.4.0