Python JMS Stomp客户端和Apache ActiveMQ-侦听器不起作用 [英] Python JMS Stomp client and Apache ActiveMQ - Listener does not work

查看:269
本文介绍了Python JMS Stomp客户端和Apache ActiveMQ-侦听器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Stomp用python编写的JMS客户端.我正在运行Apache activemq 5.10.0.

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

我有一个名为TEST的队列,并且我的客户端打印了日志消息,说它正在从队列中读取消息,但是onMessage方法中的print语句不起作用. ActiveMQ显示客户端已经阅读了该消息,并且Stomp库中的logger记录了一条消息,但是onMessage()打印语句未显示.

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.

有什么建议吗?

这是代码:

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)

推荐答案

找到它,当然是在发布后约30分钟..onMessage方法应为on_message.

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.

这篇关于Python JMS Stomp客户端和Apache ActiveMQ-侦听器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆