Python JMS Stomp client and Apache ActiveMQ - Listener does not work

风格不统一 提交于 2020-03-03 06:00:26

问题


I have a JMS client written in python using Stomp. I'm running Apache activemq 5.10.0.

I have a queue called TEST, and the client I have prints log messages saying that it is reading messages from the queue, but the print statements in my onMessage method do not work. ActiveMQ shows that the client has read the message, and the logger in the Stomp lib prints a message, but the onMessage() print statements do not show up.

Any suggestions?

Here is the code:

import time
import sys
import logging
import stomp
from stomp import ConnectionListener

queuename = sys.argv[1]

logging.basicConfig( level=logging.DEBUG)

class MyListener(ConnectionListener):
    message_count = 0
    def on_error(self, headers, message):
        print 'received an error %s' % message

    # onMessage is WRONG - should be on_message
    # def onMessage(self, headers, message):
    def on_message(self, headers, message):
        print headers
        print str(message)
        print type(message)
        print "Message %d" %(message_count)
        message_count = message_count + 1
        print 'received a message ...%s...' % message


conn = stomp.Connection()
conn.set_listener('', MyListener())
conn.start()
conn.connect()

queue = '/queue/%s' % queuename
print "Queue is [%s]" % queue
print "subscribe: %s" % conn.subscribe
conn.subscribe(destination=queue, id=123421, ack='auto')

while 1:
    time.sleep(2)

回答1:


Found it, of course about 30 minutes after posting.. The method onMessage should be on_message.

This was example code that I modified and was not correct.

Make that change and it works fine.



来源:https://stackoverflow.com/questions/26598375/python-jms-stomp-client-and-apache-activemq-listener-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!