1
我有一個使用Stomp在Python中編寫的JMS客戶端。我正在運行Apache activemq 5.10.0。Python JMS Stomp客戶端和Apache ActiveMQ - 偵聽器不起作用
我有一個名爲TEST的隊列,客戶端打印日誌消息,表明它正在從隊列中讀取消息,但我的onMessage方法中的打印語句不起作用。 ActiveMQ顯示客戶端已經讀取了消息,並且Stomp庫中的記錄器打印了一條消息,但是onMessage()打印語句不顯示。
有什麼建議嗎?
下面是代碼:
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)