活动消息队列如何配置以在Python中使用STOMP

2024-06-28 10:09:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经安装了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()

错误:

/过程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进行进程间通信。


Tags: inpyimportselfsendmessageusrconnect
3条回答

乍一看,我想说你试图连接到错误的端口。现成的ActiveMQ配置为在端口61616上使用OpenWire协议,而Stomp未启用。您需要检查ActiveMQ配置文件并确保启用Stomp传输,我们使用的标准端口是61613。有关配置Stomp:ActiveMQ Stomp Guide的一些信息,请参阅此页

我今天也面临同样的问题。这是因为端口不正确。默认情况下,stomp将连接到61613。使用此端口或更新代理以支持其他端口。

我不知道一个直接的答案,这可能是太迂回,没有用处,但一个途径可能是研究芹菜的旧代码。他们曾经通过carrot(例如http://jasonmbaker.com/how-celery-carrot-and-your-messaging-stack-wo)支持activemq/stomp——我认为他们仍然支持,但看起来他们不再支持了(根据常见问题解答:http://ask.github.com/celery/faq.html#can-i-use-celery-with-activemq-stomp)。不过,他们确实做了一些你想做的事情,所以你可以潜在地看看一个旧的实现。可能是太多的研究——不知道要得到答案有多难。我很想知道我自己是否有一个简单的答案。

相关问题 更多 >