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 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
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
  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

Krishna Prasad user avatar by
Krishna Prasad
·
Nov. 08, 12 · Interview
Like (0)
Save
Tweet
Share
12.58K 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.

Popular on DZone

  • Securing VMs, Hosts, Kubernetes, and Cloud Services
  • SAST: How Code Analysis Tools Look for Security Flaws
  • Why You Should Automate Code Reviews
  • 3 Ways That You Can Operate Record Beyond DTO [Video]

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

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: