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
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Build a Flow Collectibles Portal Using Cadence (Part 2)
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)
  • Error Handling Inside Kumologica Subflow

Trending

  • Monkey-Patching in Java
  • Podman Desktop Review
  • Software Verification and Validation With Simple Examples
  • Build a Serverless App Fast With Zipper: Write TypeScript, Offload Everything Else

Delay With JMS: From Configuration to Flow Testing

Mule ESB has powerful connectivity with message queues. Here's a quick tutorial for sending and receiving messages, message scheduling, and testing a flow.

Anirban Sen Chowdhary user avatar by
Anirban Sen Chowdhary
·
Updated Jul. 06, 16 · Analysis
Like (6)
Save
Tweet
Share
7.79K Views

Join the DZone community and get the full member experience.

Join For Free

Mule ESB has an amazing capacity to connect with message queues and send/receive message between them. We all know how to send/receive messages in a message queue, and that I am not going to demonstrate here. But yes, I like to demonstrate about how to schedule and delay a JMS messages going to a message queue.What I actually mean is, we can configure our JMS in Mule so that it dispatch the messages to the queue not immediately, but on delay with a time that we decide dynamically.

How can We Configure and Schedule the Delay of Our JMS Messages???

We will take a very simple example to demonstrate and understand how can we configure. In Mule, we can configure various properties of our messages. Here also, we need to configure a property of our JMS messages. We can set the following property dynamically in our message before dispatching it to the message queue.

<message-properties-transformer doc:name="Message Properties">
<add-message-property key="AMQ_SCHEDULED_DELAY" value="10000"/>
</message-properties-transformer>

What Does That Mean???

AMQ_SCHEDULED_DELAY: The time in milliseconds that a message will wait before being scheduled to be delivered by the broker. So, what we did here, is we set a property in our message, which will make the message to wait for the time we mentioned in milliseconds and then it will get dispatched in the queue.

Here we will configure the milliseconds as 10000 dynamically say from an input JSON request payload, so we need to wait till that time to get the message dispatched.

So, we will be designing our flow in following way:

<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<flow name="JMSDelayFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/jms" doc:name="HTTP"/>
<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object" />
<set-variable variableName="delay" value="#[message.payload.jmsDelay]" doc:name="Variable"/>
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="AMQ_SCHEDULED_DELAY" value="#[flowVars.delay]"/>
</message-properties-transformer>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<jms:outbound-endpoint queue="testqueue" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>

As we can see, we have added AMQ_SCHEDULED_DELAY before dispatching it to the message queue testqueue with a flow variable which is storing the value of delay from a JSON request.

Image title

Testing Our Flow

We will hit the URL http://localhost:8081/jms to dispatch the message to the queue, with a JSON payload that will contains the value of the delay we want to set to our JMS message.

We will able to set the value dynamically from our message payload directly as follows:

Image title

Now, we will check our queue testqueue and will find no message has be collected:

Image title

We will see here there no queue has been created and no message is there in the queue.

We will wait for some time and if we refresh the page after 10000 milliseconds, we will find queue testqueue is created the message is deposited in our queue:

Image title

Conclusion…

So this was a very simple demonstration with a very simple use case to hold, schedule and delay a JMS Message before dispatching it into a message queue dynamically from a message payload.

Hope you will like the article and hope to see your comments...

Flow (web browser)

Published at DZone with permission of Anirban Sen Chowdhary, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Build a Flow Collectibles Portal Using Cadence (Part 2)
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)
  • Error Handling Inside Kumologica Subflow

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • 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: