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
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
  • How Retry Storms Crash API-Led Systems: Bounded Reliability Patterns for Distributed Architectures

Trending

  • Why DDoS Protection Is an Architectural Decision for Developers
  • Edge Computing in Utility IoT: Two Architecture Patterns That Actually Work
  • How to Format Articles for DZone
  • LLM-Powered Deep Parsing for Industrial Inventory Search
  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.7K 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. 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
  • How Retry Storms Crash API-Led Systems: Bounded Reliability Patterns for Distributed Architectures

Partner Resources

×

Comments

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

  • 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