简体   繁体   English

如何使用Glassfish的JMS Broker将消息“代理”到Internet上的JMS代理?

[英]How can I use Glassfish's JMS Broker to “proxy” a message on to a JMS Broker on the internet?

I am working on a Java EE 6 Enterprise Application that runs on my local Glassfish3 installation. 我正在研究在我的本地 Glassfish3安装上运行的Java EE 6企业应用程序。 One of my EJBs needs to send messages to a remote JMS Broker which is located somewhere on the Internet. 我的一个EJB需要将消息发送到位于Internet上某处的远程 JMS代理。

Unfortunately, the Internet connection is rather unreliable, so my idea is to first send the messages to the local Glassfish's own JMS Broker. 不幸的是,互联网连接相当不可靠,所以我的想法是首先将消息发送给当地的 Glassfish自己的JMS代理。 My local broker would then forward the messages to the remote broker. 然后,我的本地代理将消息转发给远程代理。 Should the internet connection be unavailable, the local broker would simply wait until the connection came back up. 如果互联网连接不可用, 本地经纪人将等到连接恢复。

Am I correct in assuming this will work? 我认为这会有用吗? If so, I would highly appreciate some ideas how to get started. 如果是这样,我会非常感谢一些想法如何开始。

This approach is perfectly valid for this situation (when the remote endpoint is not always available) and is known as "store-and-forward" messaging. 这种方法对于这种情况非常有效(当远程端点不总是可用时)并且被称为“存储转发”消息传递。 In fact, many application servers support this out of the box, for example WebLogic and his Store and Forward service: 实际上,许多应用程序服务器都支持开箱即用,例如WebLogic及其存储转发服务:

The SAF service enables WebLogic Server to deliver messages reliably between applications that are distributed across WebLogic Server instances. SAF服务使WebLogic Server能够在跨WebLogic Server实例分布的应用程序之间可靠地传递消息。 For example, with the SAF service, an application that runs on or connects to a local WebLogic Server instance can reliably send messages to an endpoint that resides on a remote server. 例如,使用SAF服务,在本地WebLogic Server实例上运行或连接的应用程序可以可靠地将消息发送到驻留在远程服务器上的端点。 If the destination is not available at the moment the messages are sent, either because of network problems or system failures, then the messages are saved on a local server instance, and are forwarded to the remote endpoint once it becomes available. 如果在发送消息时目标不可用(由于网络问题或系统故障),则消息将保存在本地服务器实例上,并在消息可用后转发到远程端点。

In the case of Open MQ (GlassFish's JMS implementation), I known that Store and Forward messaging was on the features plans (see this presentation from 2007). Open MQ (GlassFish的JMS实现)的情况下,我知道存储和转发消息是在功能计划上(参见2007年的演示文稿 )。 But I have some difficulties to find an exact status on this (messages like this one don't really clarify the situation). 但是我在这方面找到一个确切的状态有一些困难(像这样的消息并没有真正澄清情况)。 What is sure is that GlassFish v3 uses Open MQ 4.4 and Open MQ 4.4 has JMS bridge (which is required for store and forward) and you may be able to use it for broker to broker communication. 可以肯定的是,GlassFish v3使用Open MQ 4.4, Open MQ 4.4具有JMS桥(存储和转发所需),您可以将它用于代理与代理通信。 See this recent blog post on how to configure it (couldn't find the documentation of Open MQ 4.4!!). 请参阅最近的博客文章 ,了解如何配置它(找不到Open MQ 4.4的文档!!)。 Personally, I'd post a message on the dev mailing list. 就个人而言,我会在开发邮件列表上发布消息。

Now, if this isn't really clear, or if you don't get a satisfying answer, it's always possible to write a custom application to consume messages and forward them to a different broker and it is not that complicated. 现在,如果这不是很清楚,或者你没有得到令人满意的答案,那么总是可以编写一个自定义应用程序来使用消息并将它们转发给不同的代理,这并不复杂。 Basically, store and forward messaging means using a "local" persistent queue for the application and using a MDB to consume the messages and send them to the remote JMS destination (in a single transaction). 基本上,存储和转发消息传递意味着为应用程序使用“本地”持久队列,并使用MDB来使用消息并将它们发送到远程JMS目标(在单个事务中)。 This would require some further testing but, as a JMS client, the MDB that handles the forwarding should be able to reconnect transparently to the remote destination. 这需要进行一些进一步的测试,但作为JMS客户端,处理转发的MDB应该能够透明地重新连接到远程目标。

JMS is well suited when the clients (producer or consumer) are not reliable, but in the case the broker itself is not reliable you are in trouble. 客户 (生产者或消费者)不可靠时,JMS非常适合,但如果经纪人本身不可靠,则您遇到麻烦。

You could try to play with the redelivery parameters (timeout, # of retry, etc) of the "staging" broker. 您可以尝试使用“登台”代理的重新传递参数(超时,重试次数等)。 You however still need a dummy MDB that act as a forwarer: the stating broker attempts to deliver to the dummy MDB which tries to connect the the external broker. 但是,您仍然需要一个充当forwarer的虚拟MDB:说明代理尝试传递到尝试连接外部代理的虚拟MDB。 If it can't the transaction fails and the message remains in the staging broker. 如果它不能导致事务失败并且消息仍在暂存代理中。 The stating broker will then try to redeliver the message to the dummy MDB later on. 然后,说明代理将尝试将消息重新传递给虚拟MDB。

The redelivery capabilities of the "staging" broker could then help to manage connectivity issues in case the MDB can't forward the message to the "external" brokers. 然后,“暂存”代理的重新传递功能可以帮助管理连接问题,以防MDB无法将消息转发给“外部”代理。 Beware nevertheless that at a point in time the message may go the dead message queue (DMQ) of the "staging" broker or even be discarded depending depending on how it's configured. 但要注意,在某个时间点,消息可能会进入“分段”代理的死消息队列(DMQ),甚至可能会被丢弃,具体取决于它的配置方式。

But this still sounds a bit strange to me... 但这对我来说仍然有点奇怪......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM