基于 stomp.py 的持久客户端填充 ActiveMQ 中的订阅者列表

发布于 2024-09-24 17:16:46 字数 791 浏览 0 评论 0原文

我对 ActiveMQ 上的持久客户端有疑问。我在Python中使用stomp.py。

 conn.start()
 conn.connect(wait=True, header = {'client-id': 'myhostname' })
 conn.subscribe(
            '/topic/testTopic', ack='auto',
            headers = {
                'activemq.subscriptionName': 'myhostname',
                'selector': "clientid <> '%s'" % 'myhostname'
            }
)

正如您从我的代码中看到的,我将 clientId 设置为我自己的主机名。如所附屏幕截图(如下)所示,clientId 显示为“ID:Atlas...”之类的内容。

问题是,每次我断开基于 stomp.py 的客户端时,下次再次连接时都会得到一个新的“clientId”。这会导致 ActiveMQ 中的订阅者列表填满: 替代文字 (上图显示了我的 ActiveMQ 代理上的订阅者。下次我断开连接然后连接时,上面的条目仍将保留,并且将添加另一个条目。很快列表中就会有许多订阅者)。

奇怪的是,选择器 100% 工作(我通过将 <> 更改为 = 来验证这一点,以便消息返回给我),因此 clientId 必须以某种方式工作。

I have a problem with a durable client on ActiveMQ. I am using stomp.py in Python.

 conn.start()
 conn.connect(wait=True, header = {'client-id': 'myhostname' })
 conn.subscribe(
            '/topic/testTopic', ack='auto',
            headers = {
                'activemq.subscriptionName': 'myhostname',
                'selector': "clientid <> '%s'" % 'myhostname'
            }
)

As you can see from my code, I am setting my clientId to be my own hostname. As shown in the attached screenshot (below), the clientId is shown to be something like "ID:Atlas....".

The problem is that every time I disconnect my stomp.py-based client, I get a new "clientId" the next time I connect again. That causes the list of subscribers in ActiveMQ to fill up:
alt text
(The image above shows a subscriber on my ActiveMQ broker. Next time I disconnect and then connect, the entry above will still remain, and another one will be added. Pretty soon I have many subscribers in the list).

The strange thing is that the selector works 100% (I verify that by changing <> to be =, so that the messages come back to me), so the clientId must be working somehow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

段念尘 2024-10-01 17:16:46

我解决了,整件事都是由于一个简单的拼写错误造成的。该行:

conn.connect(wait=True, header = {'client-id': 'myhostname' })

应包含复数形式的“标题”。

I solved it, the whole thing was due to a simple spelling mistake. The line:

conn.connect(wait=True, header = {'client-id': 'myhostname' })

Should contain 'headers' in plural form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文