DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Use JMS ActiveMQ With Mule 4: Part 2
  • Google Calendar Integration with Ruby on Rails Development
  • How To Use IBM App Connect To Build Flows
  • Enabling Business Transaction Monitoring for App Connect Enterprise

Trending

  • Unlocking AI Coding Assistants Part 4: Generate Spring Boot Application
  • Breaking Bottlenecks: Applying the Theory of Constraints to Software Development
  • Unlocking AI Coding Assistants Part 3: Generating Diagrams, Open API Specs, And Test Data
  • Testing SingleStore's MCP Server
  1. DZone
  2. Data Engineering
  3. Databases
  4. How To Use JMS ActiveMQ With Mule 4 - Part 6

How To Use JMS ActiveMQ With Mule 4 - Part 6

In this blog, we will see how we can use Durable topics to ensure that no message is lost in case the subscriber goes offline.

By 
Anand Joshi user avatar
Anand Joshi
·
Aug. 17, 21 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
15.5K Views

Join the DZone community and get the full member experience.

Join For Free

This is the 6th part of the JMS ActiveMQ with the Mule 4 series. You can read previous parts here: Part 1, Part 2, Part 3, Part 4, Part 5  In this post, we will learn about the durable topic and how we can use it in MuleSoft. 

JMS topics are used to implement a pub-sub model where the same message is broadcasted to multiple subscribers. In simple words, A message published to a topic can be consumed by any number of subscribers. But a topic subscriber can only pick the message if it listens to the topic at the time of publishing of Message means the subscriber will miss the message if not listening to the topic.

We can ensure that the topic subscriber can pick the messages that were published when the subscriber was not listening to the topic or was inactive/offline. This could be done by using Durable Topic.

A durable topic ensures that a message would be delivered to the subscriber. If the subscriber is active and listening to the topic then message would be delivered instantaneously, but if the subscriber is offline and not listening to the topic when the message is published then the message would be stored by JMS broker and once the subscriber comes online, all the stored messages would be delivered.

We can understand how this works with the help of below example.

We will create a mule flow where we have On New Message Listener which is pointing to the topic and a logger that will print and displays the received messages. In the configuration, we selected Consumer type as Topic, Marked Durable and provided a unique subscription Name.

Mule flow configuration

JMS configuration is done as shown below, where we are giving a unique client Id for JMS connection along with username, password, broker url.

Note: JMS identifies a durable topic subscriber by combination of clientID and durable subscriber name.

JMS configuration with unique clientID

We can test the connection, after filling the required fields. If JMS is running then we will get a successful connection.

Connection testing

So, we are good with our mule flow and config. Now lets have a look at the JMS console. We can see my_topic1 in the list.

The JMS console

On clicking, at subscribers we can see that there are no subscriber present at the moment for JMS.

The JMS console

To make our Durable topic subscriber work, we need to first register subscriber with JMS. This would be done automatically when we run our Mule application.

After running mule application, we can see that there is an active subscriber in the Active Durable Subscribers list. We can also see that it has same client ID (myClient1) , Subscription Name (my_subscription1) and topic (my_topic1) that we configured in our mule flow.

Active Durable Subscribers list

Lets try to send a message into topic and understand how it works when subscriber is active. For this we will add the message content in Message Body section and click on Send.

Message Body section

As the mule app is running, this message would be immediately picked by On New Message Listener in our mule flow and processed. We can see the details for same in below mule logs:

**********************************************************************

INFO  2021-07-29 19:11:15,663 [[MuleRuntime].uber.01: [jms-demo].jms-durable-demoFlow1.CPU_LITE @7ada34fb] [processor: jms-durable-demoFlow1/processors/0; event: ] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: "Recevied message is : " {

"Message" : "This is a test" 

}

On JMS Console we can see that my_topic1 has 1 subscriber and 1 message has been published and successfully delivered.

The JMS console

On switching to Subscribers tab, We can see that the subscriber is in active state and it has successfully delivered 1 message and there is no pending message to be delivered.

The JMS console

Now we will stop our mule app and try to publish a new message into the topic from JMS console. After stopping mule app, if we look at JMS subscriber tab we can see that our subscription is now moved to Offline Durable Topic Section.

The JMS console

Now, we will try to publish below message into topic my_topic1. 

Publishing message into topic my_topic1

On sending the message, when we see JMS topic we can confirm that there are 2 messages published into the topic.

The Subscriber tab

On the Subscriber tab, we can see that our subscriber is now moved into the offline Durable Topic Subscriber Section and there is 1 message in Pending Queue Size column. This is the same message that was just published, and as Subscriber is offline, it is stored. 

Similarly, all the message that would be sent, when subscriber is offline, are going to be stored and seen under column Pending Queue Size.

Column Pending Queue Size

On starting the mule api again, firstly we will receive the message which was published into the topic when the subscriber was offline. We can see the details for same in below Mule logs: 

INFO  2021-07-29 19:30:36,408 [[MuleRuntime].uber.01: [jms-demo].jms-durable-demoFlow1.CPU_LITE @72a5b6b0] [processor: jms-durable-demoFlow1/processors/0; event: ] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: "Recevied message is : " {

"Message" : "This message is sent when subscriber is offline"

}

On looking at JMS Topic we can confirm that there are 2 messages published into the topic and both are delivered to the subscriber.

The JMS Topic

When we have a look at Subscribers tab, we can see that Subscriber has been moved to Active Durable Topic Subscriber section and there is 0 messages pending and total message processed count is updated to 2.

Active Durable Topic Subscriber section

In this way we can use Durable Topic subscription and ensure that no message is loss when subscriber is inactive or offline.

app Flow (web browser) application Console (video game CLI) Connection (dance) Testing Column (database) Event

Opinions expressed by DZone contributors are their own.

Related

  • How to Use JMS ActiveMQ With Mule 4: Part 2
  • Google Calendar Integration with Ruby on Rails Development
  • How To Use IBM App Connect To Build Flows
  • Enabling Business Transaction Monitoring for App Connect Enterprise

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!