Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Spring Integration with RabbitMQ
    text
    copied!<p>I'm in the process of developing a messaging interface for one of our applications. The application is a service which is designed to accept a "Job", do some processing, and return the result (in the form of a File actually).</p> <p>The idea is to use RabbitMQ as the messaging infrastructure and Spring AMQP to handle protocol specific details.</p> <p>I do not want to have a tight coupling from my code to Spring AMQP, so I would like to use Spring Integration to hide the messaging api. So basically I want this:</p> <p>Message sent to RabbitMQ ====> Spring AMQP ====> Spring Integration ====> MyService ====> reply all the way back to RabbitMQ</p> <p>I'm trying to work out the XML configuration required to wire this together, but I'm having problems with the multiple levels of abstraction and different terminology. Finding a working example that demonstrates Spring Integration on top of Spring AMQP/RabbitMQ has proven to be surprisingly difficult, despite the fact that this sort of setup feels very "best practice" to me.</p> <p>1) So.. Could some brilliant soul out there take a quick look at this and perhaps push me in the right direction? What do I need and what don't I need? :-)</p> <p>2) Ideally the queue should be multithreaded, meaning that a taskExecutor should hand off multiple messages to my jobService for parallel processing. What configuration would be required?</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context" xmlns:rabbit="http://www.springframework.org/schema/rabbit" xmlns:int="http://www.springframework.org/schema/integration" xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp" xmlns:int-stream="http://www.springframework.org/schema/integration/stream" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/amqp http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd "&gt; &lt;context:component-scan base-package="com.myprogram.etc" /&gt; &lt;!-- Messaging infrastructure: RabbitMQ --&gt; &lt;bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory"&gt; &lt;constructor-arg value="${ei.messaging.amqp.servername}" /&gt; &lt;property name="username" value="${ei.messaging.amqp.username}" /&gt; &lt;property name="password" value="${ei.messaging.amqp.password}" /&gt; &lt;/bean&gt; &lt;rabbit:connection-factory id="connectionFactory" /&gt; &lt;rabbit:admin connection-factory="connectionFactory"/&gt; &lt;!-- From RabbitMQ --&gt; &lt;int-amqp:inbound-gateway request-channel="fromAMQP" reply-channel="toAMQP" queue-names="our-product-name-queue" connection-factory="connectionFactory"/&gt; &lt;!-- Spring Integration configuration --&gt; &lt;int:channel id="fromAMQP"&gt; &lt;!-- Is this necessary?? --&gt; &lt;int:queue/&gt; &lt;/int:channel&gt; &lt;!-- JobService is a @Service with a @ServiceActivator annotation --&gt; &lt;int:service-activator input-channel="fromAMQP" ref="jobService"/&gt; &lt;/beans&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload