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).
The idea is to use RabbitMQ as the messaging infrastructure and Spring AMQP to handle protocol specific details.
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:
Message sent to RabbitMQ ====> Spring AMQP ====> Spring Integration ====> MyService ====> reply all the way back to RabbitMQ
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.
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? :-)
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?
<?xml version="1.0" encoding="UTF-8"?>
<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
">
<context:component-scan base-package="com.myprogram.etc" />
<!-- Messaging infrastructure: RabbitMQ -->
<bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<constructor-arg value="${ei.messaging.amqp.servername}" />
<property name="username" value="${ei.messaging.amqp.username}" />
<property name="password" value="${ei.messaging.amqp.password}" />
</bean>
<rabbit:connection-factory id="connectionFactory" />
<rabbit:admin connection-factory="connectionFactory"/>
<!-- From RabbitMQ -->
<int-amqp:inbound-gateway request-channel="fromAMQP" reply-channel="toAMQP" queue-names="our-product-name-queue" connection-factory="connectionFactory"/>
<!-- Spring Integration configuration -->
<int:channel id="fromAMQP">
<!-- Is this necessary?? -->
<int:queue/>
</int:channel>
<!-- JobService is a @Service with a @ServiceActivator annotation -->
<int:service-activator input-channel="fromAMQP" ref="jobService"/>
</beans>