activemq如何配置在python中使用stomp

时间:2011-06-04 04:09:50

标签: python activemq 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()

错误:

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

3 个答案:

答案 0 :(得分:5)

乍一看,我会说你正试图连接到错误的端口。开箱即用ActiveMQ配置为在端口61616上使用OpenWire协议,并且未启用Stomp。您需要检查ActiveMQ配置文件并确保已启用Stomp传输,我们使用的标准端口为Stomp的61613。有关配置Stomp:ActiveMQ Stomp Guide

的一些信息,请参阅此页面

答案 1 :(得分:0)

我不知道直接的答案,这可能太迂回而无用,但一条路线可能是查看Celery的旧代码。他们曾经通过胡萝卜支持activemq / stomp(例如http://jasonmbaker.com/how-celery-carrot-and-your-messaging-stack-wo) - 我认为他们仍然这样做但看起来他们已经没有了(根据FAQ:http://ask.github.com/celery/faq.html#can-i-use-celery-with-activemq-stomp)。尽管如此,他们确实做了你想要的时间,所以你可能会看到一个较旧的实现。可能是太多的研究 - 不确定得到答案有多难。我很想知道自己是否有一个简单的答案。

答案 2 :(得分:0)

我今天遇到了类似的问题。这是由于端口不正确造成的。默认情况下,stomp将连接到61613.使用此端口或更新代理以支持其他端口。

相关问题