7

我在本地安装并运行了 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进行进程间通信。

4

3 回答 3

6

乍一看,我会说您正在尝试连接到错误的端口。开箱即用的 ActiveMQ 配置为在端口 61616 上使用 OpenWire 协议,并且未启用 Stomp。您需要检查您的 ActiveMQ 配置文件并确保启用 Stomp 传输,我们使用的标准端口是 Stomp 的 61613。有关配置 Stomp 的一些信息,请参阅此页面:ActiveMQ Stomp 指南

于 2011-06-04T11:20:05.650 回答
0

我不知道直接的答案,这可能太迂回而无用,但一种方法可能是查看 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)。尽管如此,他们确实做了你想要的,所以你可能会看一个旧的实现。可能研究太多了——不确定得到答案有多难。我很想看看自己是否有一个简单的答案。

于 2011-06-04T09:30:57.577 回答
0

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.

于 2014-12-10T04:43:48.917 回答