本文介绍了HornetQ中JMS主题的确切示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了hornetQ文档,非常困惑.有人可以举一个确切的例子在hornetQ中创建一个JMS主题.我的意思是hornetq-jms.xmlhornetq-configuration.xml中的xml配置.假设我们有一个名为top的主题和2个名为sub1sub2的订阅者.我得到的是,我们应该定义两个队列(每个订阅者一个),并将它们绑定到实际上是主题名称的地址,但是订阅者如何知道他们应该连接到哪个队列(他们只知道主题名称).

I read the hornetQ documentation, confused a lot. Can someone give an exact example to create a JMS topic in hornetQ. I mean the xml configurations in hornetq-jms.xml and hornetq-configuration.xml. assume we have a topic named top and 2 subscribers named: sub1, sub2. what I get is that we should define two queues(one for each subscribers) and bind them to an address which is the topic name actually, but how the subscriber would know they should connect to which one?(They only know the topic name)

推荐答案

与JMS规范描述主题的方式相比,我认为您对HornetQ内部处理主题的方式感到困惑.

I think you are confused by the way HornetQ handles topics internaly in contrast to the way the JMS specification describes topics.

让我们从JMS规范开始.在这里,您有一个主题,其中n个订阅者可以收听将由客户端发布的消息.在JMS中,我们仅以单数谈论目的地,例如.我们将分别向 the 主题或 the 队列发送消息.

Let's start with the JMS specification. Here you have one topic, where n subscribers can listen to the messages, that will be published by a client. In JMS we talk only about the destination in singular, eg. we'll send a message to the topic, or the queue respectively.

HornetQ是JMS提供程序-实现JMS规范的服务器,因此Java客户端可以连接到该服务器并使用JMS-API. JMS提供程序可能会更改,但是在使用其他JMS提供程序时,该代码仍然可以使用.

HornetQ is a JMS Provider - a server that implements the JMS specification, so Java-clients can connect to it, and use the JMS-API. The JMS Provider might change, but the code should still work when using another JMS provider.

但是,HornetQ不会在内部区分目的地(主题或队列),因为它试图成为通用的消息传递中间件.在HornetQ中,所有主题或队列都实现为地址"和队列".当您使用HornetQ API(CoreAPI)而不是JMS-API时,您必须处理这些事情.您应该阅读 HornetQ文档中的地址"部分. a>:

However, HornetQ does not distinguish internally the destinations (topic or queue), since it tries to be a generic messaging middleware. In HornetQ all topics or queues are implemented as "addresses" and "queues". When you use the HornetQ API (CoreAPI) instead of the JMS-API, you have to deal with such things. You should read the Address section in the HornetQ documentation:

例如,一个JMS主题将通过一个地址来实现 绑定了许多队列.每个队列代表一个订阅 话题. JMS队列将被实现为单个地址,以实现 绑定了哪个队列-该队列代表JMS队列.

For example, a JMS topic would be implemented by a single address to which many queues are bound. Each queue represents a subscription of the topic. A JMS Queue would be implemented as a single address to which one queue is bound - that queue represents the JMS queue.

举例说明如何通过HornetQ在JMS中使用主题,我强烈推荐HornetQ随附的示例.在下载并解压缩hornetq归档文件之后,只需进入examples/jms/topic目录并查看readme.html,以简要概述如何实现和如何执行示例(mvn verify).

For an example how to use a topic with JMS via HornetQ, I stongly recommend the examples that come with HornetQ itself. After donwloading and extracting the hornetq archive, just go to the examples/jms/topic directory and see the readme.html for a brief overview how to implement and how to execute the example (mvn verify).

这篇关于HornetQ中JMS主题的确切示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 10:14