For the following scenario I am looking for your advices and tips on best practices:
In a distributed (mainly Java-based) system with:
How would one best apply the JMS support provided by the Spring Integration framework to decouple the clients from the worker nodes? When reading through the reference documentation and some very first experiments it looks like the configuration of an JMS inbound adapter inherently require to use a subscriber, which in a decoupled scenario does not exist.
Small side note: communication should happen via JMS text messages (using a JSON data structure for future extensibility).
Spring Integration provides Channel Adapters for receiving and sending JMS messages. There are actually two JMS-based inbound Channel Adapters. The first uses Spring's JmsTemplate to receive based on a polling period. The second is "message-driven" and relies upon a Spring MessageListener container.
JMS is a standard Java API that allows a Java application to send messages to another application. It is highly scalable and allows us to loosely couple applications using asynchronous messaging. Using JMS we can read, send and read messages.
Spring Integration enables lightweight messaging within Spring-based applications and supports integration with external systems via declarative adapters. Those adapters provide a higher-level of abstraction over Spring's support for remoting, messaging, and scheduling.
This doesn't really answer your question, but make sure you look into Apache Camel for connecting your different components. I found it extremely useful for connecting a JMS queue up to an existing web service and plan to use it for other components also.
An example that monitors an ActiveMQ queue for messages, transforms them, and posts them to a web service:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring-2.3.0.xsd">
<bean id="callbackProcessor" class="com.package.CallbackProcessor"/>
<bean id="activemq" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsFactory" />
</bean>
<camel:camelContext id="camel">
<!-- Must put this in camel:endpoint because camel:from doesn't support property substitution -->
<camel:endpoint id="callbackQueue" uri="activemq:queue:${jms.callback-queue-name}"/>
<camel:route>
<camel:from ref="callbackQueue"/>
<camel:process ref="callbackProcessor"/>
<camel:to uri="http://dummy"/><!-- This will be replaced by the callbackProcessor with the callback URL in the message -->
</camel:route>
</camel:camelContext>
</beans>
That's all that's necessary in our Spring application to fire up Camel and start processing messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With