JMS Message Rollback and Redelivery

(1 review)

home

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

Prerequisites

This document assumes that you are familiar with Mule Runtime and the Anypoint Studio interface. Further, this example assumes that you have Apache Maven and Apache ActiveMQ running on your machine.

Example Use Case

c38cfc60-JMSMessageRollbackAndRedelivery.png

A JMS message in a transaction inside Anypoint Studio throws an exception. This message is then handled by the On Error Propagate Component, which rollbacks and retries to deliver the same message. After 4 unsuccessful attempts to commit (in this example), the message is sent successfully.

Set Up and Run the Example

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

Start the ActiveMQ server:

  • Navigate to the activeMQ home directory in the command terminal and then use the following command to start the activeMQ serverbin/activemq start
  • A message appears 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 : . . .

If activemq-all-5.10.0.jar is not configured to the Java build path, follow 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, then click Properties/Java Build Path. Under the Libraries tab, click Add External Jar.
  • 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 building this documentation was 5.10.0). Click Open/Ok to do so.

Run the Example

In the Package Explorer, right-click the project, then select Run As > Mule Application. Studio runs the application on its embedded server. Your Mule application is now running!

Test the Example

  1. Login to the activeMQ admin console at http://localhost:8161/admin/send.jsp with the default username and password admin. Type "in" in the field marked Destination and then click on Send.
  2. The transaction will fail with "Exception" the first four attempts (to simulate an error condition), and then the message will be delivered correctly.
  3. 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.
  4. Try removing the "maxRedelivery" settings from the Active MQ connector configuration. Now the transaction fails in the second attempt due.

Reviews

TypeExample
OrganizationMuleSoft
Published by
MuleSoft Organization
Published onSep 6, 2018
Asset overview

Asset versions for 2.1.x

Asset versions
VersionActions
2.1.4
2.1.3
2.1.2

Categories

Difficulty
AverageNo values left to add
Functions
Enterprise ITNo values left to add