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. AMQP Backed Spring Integration using vFabric RabbitMQ

AMQP Backed Spring Integration using vFabric RabbitMQ

Krishna Prasad user avatar by
Krishna Prasad
·
Dec. 25, 12 · Interview
Like (0)
Save
Tweet
Share
5.42K Views

Join the DZone community and get the full member experience.

Join For Free
for people in hurry, refer the following steps to run the demo .

introduction

combining vfabric rabbitmq and spring integration we can create loosely coupled enterprise class message-based workflows using spring amqp . refer to the spring integration, amqp backed message channels documentation.

in this demo, we will design a spring integration workflow, wherein a message is published on to a p2p-pollable-channel and a publish-subscribe-channel is listening to it, it will pickup that message and pass it to 2 different service activators to further process it. i will also demonstrate that, both these message channels are on their own, listening to an external applications and when an external application publishes a message to these queues they will process from there on in the workflow. a typical use case of this is in an enterprise it environment where we can create robust workflows, wherein if a message is not processed in a particular step, we can message the data and process it from there on. since spring amqp is a wire protocol the external application can be used by any network protocol to publish the message to the vfabric rabbitmq queue and the spring integration flow is triggered.

amqp backed message channel in spring integration flow

amqp based message channel within spring integration

as always in my blog, as per tdd , i will be writing the test first as seen below,

public class publishersubscribertest {

@test
public void testintegration() {
try {
string request = streamtostring(getclass().getresourceasstream(
"/data/payload.xml"));
message<string> message = messagebuilder.withpayload(request)
.build();
channel.send(message);
//assert various messages
} catch (ioexception e) {
// todo auto-generated catch block
e.printstacktrace();
}
}

the spring integration configuration flow:

<int:bridge input-channel="p2p-pollable-channel"
output-channel="pub-sub-channel" />

<int:service-activator input-channel="pub-sub-channel"
id="serviceactivator1" ref="serviceactivator1bean" method="logxml" />

<int:service-activator input-channel="pub-sub-channel"
id="serviceactivator2" ref="serviceactivator2bean" method="logxml" />

<bean id="serviceactivator1bean"
class="com.gosmarter.amqp.service.subscriber1serviceactivator">
</bean>

<bean id="serviceactivator2bean"
class="com.gosmarter.amqp.service.subscriber2serviceactivator">
</bean>

test channel definition:

<int:poller default="true" fixed-rate="1000" />
<int:channel id="p2p-pollable-channel" />
<int:publish-subscribe-channel id="pub-sub-channel" />

actual channel definition used as a part of web.xml is seen here

<!-- a reference to the org.springframework.amqp.rabbit.connection.connectionfactory -->
<rabbit:connection-factory id="connectionfactory" />
<!-- creates a org.springframework.amqp.rabbit.core.rabbitadmin to manage
exchanges, queues and bindings -->
<rabbit:admin connection-factory="connectionfactory" />

<int-amqp:channel id="p2p-pollable-channel" connection-factory="connectionfactory" />
<int-amqp:publish-subscribe-channel id="pub-sub-channel" connection-factory="connectionfactory" />

when you run this application in sts as “run on server” for the 1st time, you will notice in the vfabric rabbitmq admin console will have one queue, p2p-pollable-channel and exchange called si.fanout.pub-sub-channel. you'll notice the spring integration framework appended “si.fanout” in front of pub-sub-channel. if you want to test if the end to end is working, you can post a message on either the queue or exchange , it will continue the workflow from that point onwards.

if you are using amqp backed channels, you can reply a payload from any channels to continue the workflow, this will be useful in error handling and payload retry.

conclusion

in this sample, we have demonstrated that with a single component backed by amqp, we can build a loosely coupled workflow. based on the context, there can be 2 different ways of building publish subscriber workflow, one is as described above and another one is one publisher component will have several subscriber components.

i hope this blog helped you.




Spring Integration Spring Framework Integration

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

  • Why Open Source Is Much More Than Just a Free Tier
  • Why Does DevOps Recommend Shift-Left Testing Principles?
  • Using the PostgreSQL Pager With MariaDB Xpand
  • Top Authentication Trends to Watch Out for in 2023

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: