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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How to Marry MDC With Spring Integration
  • Introducing Stalactite ORM
  • Spring Boot Microservices + Apache Camel: A Hello World Example
  • Why 200 OK Is the Most Dangerous Lie in Enterprise Integration

Trending

  • When Production Stops Moving: Running Claude Code Across a Distributed Enterprise Integration Team
  • Agentic Test Creation: From Plain-Language Requirements to End-to-End Test Cases
  • Building IoT Time-Series Applications With Java and Apache IoTDB
  • Data Integration Landscape 2026: Event Streaming, API, and Batch in the Era of Agentic AI

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Nov. 08, 12 · Interview
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
13.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Marry MDC With Spring Integration
  • Introducing Stalactite ORM
  • Spring Boot Microservices + Apache Camel: A Hello World Example
  • Why 200 OK Is the Most Dangerous Lie in Enterprise Integration

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook