开发者

activemq how to configure to work with stomp in python

I have activemq installed and running locally, but whe开发者_如何转开发n 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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜