如何在真实的JMS分布式架构中利用Spring Integration?

nge*_*eek 5 java spring jms spring-integration

对于以下场景,我正在寻找有关最佳实践的建议和提示:

在分布式(主要是基于Java)系统中:

  • 许多(不同的)客户端应用程序(web-app,命令行工具,REST API)
  • 中央JMS消息代理(目前支持使用ActiveMQ)
  • 多个独立处理节点(在多个远程机器上运行,计算由JMS消息有效负载指定的不同类型的昂贵操作)

如何最好地应用Spring Integration框架提供的JMS支持来将客户端与工作节点分离?在阅读参考文档和一些初步实验时,看起来JMS入站适配器的配置本身就需要使用订户,而订户在解耦的情况下不存在.

小旁注:通过JMS文本消息进行通信(使用JSON数据结构以实现未来的可扩展性).

Edw*_*ale 4

这并不能真正回答您的问题,但请确保您研究Apache Camel来连接不同的组件。我发现它对于将 JMS 队列连接到现有 Web 服务非常有用,并计划也将其用于其他组件。

监视 ActiveMQ 队列中的消息、转换它们并将它们发布到 Web 服务的示例:

<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>
Run Code Online (Sandbox Code Playgroud)

这就是我们的 Spring 应用程序中启动 Camel 并开始处理消息所需的全部内容。