activemq 如何配置与 python 中的 stomp 一起使用
我在本地安装并运行了 activemq,但是当我运行以下脚本时,出现错误:
#!/usr/bin/env python
import time
import sys
import stomp
class MyListener(object):
def on_error(self, headers, message):
print 'received an error %s' % message
def on_message(self, headers, message):
print 'received a message %s' % message
conn = stomp.Connection(host_and_ports=[('localhost', 61616)])
conn.set_listener('', MyListener())
conn.start()
conn.connect()
conn.subscribe(destination='/home/bitcycle/svn/cass/queue.test', ack='auto')
conn.send('Test', destination='/home/bitcycle/svn/cass/queue.test')
time.sleep(2)
conn.disconnect()
error:
./proc.py
No handlers could be found for logger "stomp.py"
Traceback (most recent call last):
File "./proc.py", line 20, in
conn.disconnect()
File "/usr/local/lib/python2.7/dist-packages/stomp.py-3.0.3-py2.7.egg/stomp/connect.py", line 387, in disconnect
self.__send_frame_helper('DISCONNECT', '', utils.merge_headers([self.__connect_headers, headers, keyword_headers]), [ ])
File "/usr/local/lib/python2.7/dist-packages/stomp.py-3.0.3-py2.7.egg/stomp/connect.py", line 453, in __send_frame_helper
self.__send_frame(command, headers, payload)
File "/usr/local/lib/python2.7/dist-packages/stomp.py-3.0.3-py2.7.egg/stomp/connect.py", line 489, in __send_frame
raise exception.NotConnectedException()
stomp.exception.NotConnectedException
有人可以帮助我了解我需要做什么才能使其正常工作吗?我想使用 activemq 进行进程间通信。
I have activemq installed and running locally, but when I run the following script, I get an error:
#!/usr/bin/env python
import time
import sys
import stomp
class MyListener(object):
def on_error(self, headers, message):
print 'received an error %s' % message
def on_message(self, headers, message):
print 'received a message %s' % message
conn = stomp.Connection(host_and_ports=[('localhost', 61616)])
conn.set_listener('', MyListener())
conn.start()
conn.connect()
conn.subscribe(destination='/home/bitcycle/svn/cass/queue.test', ack='auto')
conn.send('Test', destination='/home/bitcycle/svn/cass/queue.test')
time.sleep(2)
conn.disconnect()
error:
./proc.py
No handlers could be found for logger "stomp.py"
Traceback (most recent call last):
File "./proc.py", line 20, in
conn.disconnect()
File "/usr/local/lib/python2.7/dist-packages/stomp.py-3.0.3-py2.7.egg/stomp/connect.py", line 387, in disconnect
self.__send_frame_helper('DISCONNECT', '', utils.merge_headers([self.__connect_headers, headers, keyword_headers]), [ ])
File "/usr/local/lib/python2.7/dist-packages/stomp.py-3.0.3-py2.7.egg/stomp/connect.py", line 453, in __send_frame_helper
self.__send_frame(command, headers, payload)
File "/usr/local/lib/python2.7/dist-packages/stomp.py-3.0.3-py2.7.egg/stomp/connect.py", line 489, in __send_frame
raise exception.NotConnectedException()
stomp.exception.NotConnectedException
Can someone help me to understand what i need to do to get this to work? I would like to use activemq for inter-process communication.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
乍一看,我会说你正在尝试连接到错误的端口。开箱即用的 ActiveMQ 配置为在端口 61616 上使用 OpenWire 协议,并且未启用 Stomp。您需要检查 ActiveMQ 配置文件并确保启用了 Stomp 传输,我们使用的 Stomp 标准端口是 61613。有关配置 Stomp 的一些信息,请参阅此页面:ActiveMQ Stomp 指南
At first glance I'd say you are trying to connect to the wrong port. Out of the box ActiveMQ is configured to use OpenWire protocol on port 61616, and Stomp is not enabled. You need to check your ActiveMQ configuration file and ensure that the Stomp transport is enabled, the standard port we use is 61613 for Stomp. See this page for some info on configuring Stomp: ActiveMQ Stomp Guide
我不知道直接的答案,这可能太迂回而无用,但一种途径可能是研究 Celery 的旧代码。他们曾经通过胡萝卜支持activemq/stomp(例如http:// jasonmbaker.com/how-celery-carrot-and-your-messaging-stack-wo )-- 我以为他们仍然这样做,但看起来他们不再这样做了(根据常见问题解答:http://ask.github.com/celery /faq.html#can-i-use-celery-with-activemq-stomp)。尽管如此,他们确实做了你想要的事情,所以你可以看看旧的实现。可能是太多的研究——不知道得到答案有多难。我很有兴趣看看自己是否有一个简单的答案。
I don't know a direct answer, and this may be too circuitous to be useful, but one route might be to look into Celery's older code. They used to support activemq/stomp through carrot (e.g. http://jasonmbaker.com/how-celery-carrot-and-your-messaging-stack-wo )-- I thought they still did but it looks like they don't anymore (according to the FAQ: http://ask.github.com/celery/faq.html#can-i-use-celery-with-activemq-stomp). Still, they did do exactly what you want some time back, so you could potentially look at an older implementation. Might be too much research-- not sure how hard it is to get an answer. I'll be interested to see if there's an easy answer myself.
我今天遇到了类似的问题。这是由于端口不正确造成的。默认情况下,stomp 将连接到 61613。使用此端口或更新代理以支持其他端口。
I faced the similar issue today. This is due to incorrect port. By default stomp would connect to 61613. Use this port or update the broker to support other ports.