如何在现实世界的JMS分布式架构中利用Spring Integration? [英] How to leverage Spring Integration in a real-world JMS distributed architecture?

查看:99
本文介绍了如何在现实世界的JMS分布式架构中利用Spring Integration?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于以下情况,我正在寻找有关最佳做法的建议和提示:

For the following scenario I am looking for your advices and tips on best practices:

在具有以下功能的分布式(主要是基于Java的)系统中:

In a distributed (mainly Java-based) system with:


  • 许多(不同的)客户端应用程序(网络应用程序,命令行工具,REST API)

  • 多个独立处理节点(在多个远程计算机上运行,​​计算由JMS消息有效负载指定的不同类型的昂贵操作)的JMS消息代理(目前支持使用ActiveMQ)


如何最好地应用由 Spring Integration 框架以将客户端与工作节点分离?当阅读参考文档和一些非常先进的实验时,它看起来像JMS入站适配器的配置本身就需要使用一个订户,这在一个解耦的情况下是不存在的。

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.

小侧注:通信应通过JMS短信发送(使用JSON数据结构以便将来可扩展)。

Small side note: communication should happen via JMS text messages (using a JSON data structure for future extensibility).

推荐答案

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

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.

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

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>

我们的Spring应用程序中需要启动Camel并开始处理消息。

That's all that's necessary in our Spring application to fire up Camel and start processing messages.

这篇关于如何在现实世界的JMS分布式架构中利用Spring Integration?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆