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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Introducing Stalactite ORM
  • Spring Boot Microservices + Apache Camel: A Hello World Example
  • Incorporating Fault-Tolerance Into Your Microservice Architecture
  • How Spring and Hibernate Simplify Web and Database Management

Trending

  • Chat With Your Knowledge Base: A Hands-On Java and LangChain4j Guide
  • Traditional Testing and RAGAS: A Hybrid Strategy for Evaluating AI Chatbots
  • Monolith: The Good, The Bad and The Ugly
  • AI Agents: A New Era for Integration Professionals
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Control Bus Pattern with Spring Integration and JMS

Control Bus Pattern with Spring Integration and JMS

By 
Krishna Prasad user avatar
Krishna Prasad
·
Nov. 08, 12 · Interview
Likes (0)
Comment
Save
Tweet
Share
13.5K Views

Join the DZone community and get the full member experience.

Join For Free

for people in hurry, refer the steps and the demo .

introduction

control bus pattern is a enterprise integration pattern is used to control distributed systems in spring integration . in this blog, i will show you how a control bus can control your application or a component to start or stop listening to jms message . in this example, we are using jms queue to start and stop the jms inbound-channel-adapter , we can also do this with jdbc inbound-channel-adapter and control this thru an external application. the other way to do the same is by using mbean as in this example .

in this use case, there is a spring integration flow. this spring integration flow can be controlled by sending start / stop message to inbound-channel-adapter from a activemq jms queue.

details control bus with spring integration

control bus spring integration jms

control bus spring integration jms

to start implementing this use case, we write the junit test 1st. if you notice once the inboundadapter is started the message is received from the adapteroutchannel. once the inboundadapter is stopped no message is received. this is demonstrated as below,

@test
public void democontrolbus() {
assertnull(adapteroutputchanel.receive(1000));
controlchannel.send(new genericmessage<string>("@inboundadapter.start()"));
assertnotnull(adapteroutputchanel.receive(1000));
controlchannel.send(new genericmessage<string>("@inboundadapter.stop()"));
assertnull(adapteroutputchanel.receive(1000));
}

the test configuration looks as below,

<int:inbound-channel-adapter id="inboundadapter"
channel="controlbus-managed-p2p-pollable-channel" expression="'hello'"
auto-startup="false">
<int:poller fixed-rate="6000" />
</int:inbound-channel-adapter>

if you run the “mvn test” the tests work. in the main configuration, we will be configuring actual queues and jms inbound-channel-adapter as below,

<int-jms:inbound-channel-adapter id="inboundadapter"
channel="controlbus-managed-p2p-pollable-channel"
jms-template="jmstemplate">
<int:poller fixed-rate="6000" />
</int-jms:inbound-channel-adapter>

<int-jms:inbound-channel-adapter id="controlbusadapter"
channel="control-channel"
jms-template="controlbusjmstemplate">
<int:poller fixed-rate="6000" />
</int-jms:inbound-channel-adapter>

now when you start the component as “run on server” in sts ide and post a message on
myqueue, you can see the subscribers received the messages on the console. you can issue “@inboundadapter.stop()” on the controlbusqueue, it will stop the inbound-channel-adapter, it will also throw java.lang.interruptedexception, it looks like a false alarm. to test if the inbound-channel-adapter is stopped, post a message on to myqueue, the component will not process the message. now issue “@inboundadapter.start()” on the controlbusqueue, it will process the earlier message and start listening for new messages.

conclusion

if you notice in this blog, we can control the component to listen to message using control bus.  the other way to do the same is by using mbean as in this example .

Spring Integration Enterprise integration Spring Framework

Published at DZone with permission of Krishna Prasad, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Introducing Stalactite ORM
  • Spring Boot Microservices + Apache Camel: A Hello World Example
  • Incorporating Fault-Tolerance Into Your Microservice Architecture
  • How Spring and Hibernate Simplify Web and Database Management

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!