【发布时间】:2021-05-25 01:48:18
【问题描述】:
我在这里做错了什么?我正在尝试使用 Stomp 在 Artemis 2.13.0 中测试一些东西,但是当我使用 Python 脚本的命令行实用程序时,我无法订阅队列,即使在我使用该实用程序发布消息之后也是如此到一个地址。
另外,如果我给它一个新的队列名称,它会创建它,但不会拉取我发布到它的消息。这令人困惑。我实际的 Java 应用程序的行为与此完全不同——它使用的是 JMS
我与实用程序的连接是这样的:
stomp -H 192.168.56.105 -P 61616 -U user -W password
> subscribe test3.topic::test.A.queue
这给了我这个错误:
Subscribing to 'test3.topic::test.A.queue' with acknowledge set to 'auto', id set to '1'
>
AMQ229019: Queue test.A.queue already exists on address test3.topic
这让我觉得 Stomp 在订阅时试图创建队列,但我在文档中看不到如何管理它。 http://jasonrbriggs.github.io/stomp.py/api.html
我也有一个 Python 脚本给我同样的问题。
import os
import time
import stomp
def connect_and_subscribe(conn):
conn.connect('user', 'password', wait=True)
conn.subscribe(destination='test3.topic::test.A.queue', id=1, ack='auto')
class MyListener(stomp.ConnectionListener):
def __init__(self, conn):
self.conn = conn
def on_error(self, headers, message):
print('received an error "%s"' % message)
def on_message(self, headers, message):
print('received a message "%s"' % message)
"""for x in range(10):
print(x)
time.sleep(1)
print('processed message')"""
def on_disconnected(self):
print('disconnected')
connect_and_subscribe(self.conn)
conn = stomp.Connection([('192.168.56.105', 61616)], heartbeats=(4000, 4000))
conn.set_listener('', MyListener(conn))
connect_and_subscribe(conn)
time.sleep(1000)
conn.disconnect()
【问题讨论】:
-
您为什么使用完全限定队列名称 (FQQN)?正常用例不需要这个。另外,您使用的是什么版本的 ActiveMQ Artemis?
-
我也试过只使用队列名称。我希望队列由订阅创建,然后在断开连接后消失,而 FQQN 最适合这个。
-
多播(又名发布订阅或主题)和任播(又名点对点或队列)语义的工作方式之间存在明显差异。你在寻找什么确切的行为?另外,您使用的是什么版本的 ActiveMQ Artemis?
-
Artemis 2.13.0 多播。我正在发布到一个地址,目的是在订阅者连接时创建要订阅的队列。
-
如果您使用多播并且希望您的客户端接收发布到某个地址的消息,那么为什么不订阅多播地址(即主题)而不是 FQQN?这就是这个用例通常要做的事情。
标签: python stomp activemq-artemis