发布时间:2019-08-14 12:46:25编辑:auto阅读(1780)
# -*- coding: utf-8 -*-
import sys
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' % headers)
conn = stomp.Connection10([('localhost',61613)])
conn.set_listener('logicServerQueue', MyListener())
conn.start()
conn.connect(wait=True)
# 发送消息到testQueue队列,指定consumerId='88.3@6006'
conn.send(body=b'hahah', destination='testQueue', headers={'consumerId': '88.3@6006'})
# 从testQueue队列中接收消息,用selector过滤,只接收consumerId = '88.3@6006'的消息
conn.subscribe(destination='testQueue', headers={'selector' : "consumerId = '88.3@6006'"})
while True:
try:
time.sleep(1)
except:
break
conn.disconnect()
time.sleep(2)
conn.disconnect()
从控制台可以看出consumerId = ‘88.3@6006’被设置到了消息的headers中
上一篇: 使用python通过http发送json
下一篇: Python学习之路1 有序集合和无需集
48880
47950
38732
35872
30295
27056
26081
20914
20725
19083
538°
625°
626°
635°
606°
587°
662°
729°
852°
968°