客户端ID在Artemis中是否必须在同一个应用程序内是唯一的?

huangapple go评论91阅读模式
英文:

Does the ClientID have to be unique within the same app in Artemis

问题

这是我所了解的内容:
我们有两个应用程序,一个用于生产,一个用于消费。两者在不同的JVM上运行。它们向持久主题发送消息,并且使用相同的ClientId。

我想知道在JMS 2.0规范下是否允许以下操作,以及在Artemis中是否可以这样做。

  • 在消费端,我有一个连接工厂。
  • 我在实例化ActiveMQConnectionFactory bean时通过以下方法设置了clientID:.setClientId("clientId").setEnabledSharedClientId(true)
  • 然后,我有一个类A,它在其参数中接受ActiveMQConnectionFactory类型。在这个类中,有一个发送方法,它会检查是否存在连接,如果不存在,它会通过this.connectionFactory.createConnection();创建连接。
  • 然后,我有另一个类,它在其中接受类型为A的对象。在这个类中有一个BlockingQueue数组。在每个元素中,它包含一个ArrayBlockingQueue。实际上,这个类的目的是创建不同的线程,以便从ArrayBlockingQueue中消费消息,因为消息被放在这些队列中。每个线程从自己的ArrayBlockingQueue中读取消息,在自己的线程中进行处理。

现在我的问题是,根据JMS 2.0规范,这样做是否被允许?从同一个connectionFactory创建不同线程上的连接是否可以?每个线程是否应该有自己的ClientID?

英文:

This is what I have:
We have 2 apps, one producing and one consuming. Both are running on different JVMs. They are sending a message to a durable topic and are using the same ClientId.

I wanted to know if the following is allowed under JMS 2.0 spec and if it's okay to do in Artemis.

  • On the consuming side, I have a connection factory.
  • I set the clientID on the factory by the following methods when instantiating the ActiveMQConnectionFactory bean: .setClientId("clientId") and .setEnabledSharedClientId(true)
  • I have then have a class A which takes in the ActiveMQConnectionFactory type in its params. In this class there's a send method in which it checks if a connection exists, if not it creates the connection via this.connectionFactory.createConnection();.
  • I then have another class which takes a type of A object in it. In this class there is an BlockingQueue array. in each element, it contains a ArrayBlockingQueue. Essentially the purpose of this class is to create create different threads to consume messages from the ArrayBlockingQueue as messages are put on them. Each thread reads from it's arrayblcokingqueue it's assigned too in it's own thread.

Now my question is is that is this allowed under JMS 2.0 spec? Is it okay that a connection is being created on different thread which is being created from the ONE/SAME connectionFactory? Should each thread have it's own ClientID?

答案1

得分: 1

正如 JMS 2 规范的第 2.14 节所述,javax.jms.ConnectionFactory 对象支持并发使用。因此,多个线程可以使用相同的 ConnectionFactory 来创建 javax.jms.Connection 实例。

至于客户端 ID,以下是规范第 6.1.2 节中相关的部分:

> 根据定义,由客户端标识符标识的客户端状态一次只能被一个客户端“使用”。
>
> ...
>
> JMS 定义的客户端标识符的唯一用途是在标识独占持久订阅时强制使用,或在标识共享持久或非持久订阅时选择性使用。

由于您的消费者似乎在主题上共享一个持久订阅,因此对于客户端 ID 的使用是可选的

此外,值得注意的是,org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory#setEnableSharedClientID 实际上是一个内部方法,专为在 JCA 资源适配器中使用,以及涉及特定情况的向后兼容性。

英文:

As noted in section 2.14 of the JMS 2 specification the javax.jms.ConnectionFactory object supports concurrent use. Therefore, it's fine for multiple threads to use the same ConnectionFactory to create instances of javax.jms.Connection.

As far as the client ID goes, this is the relevant bit from section 6.1.2 of the specification:

> By definition, the client state identified by a client identifier can be ‘in use’ by only one
client at a time.
>
> ...
>
> The only use of a client identifier defined by JMS is its mandatory use in identifying an unshared durable subscription or its optional use in identifying a shared durable or non-durable subscription.

Since your consumers appear to be sharing a durable subscription on a topic then your use of the client ID is optional.

Also, it's worth noting that org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory#setEnableSharedClientID is really an internal method designed for use in the JCA resource adapter and for certain cases involving backwards compatibility.

huangapple
  • 本文由 发表于 2020年8月16日 18:04:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63435533.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定