前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python stomp 收发指定的消息

python stomp 收发指定的消息

作者头像
py3study
发布2020-01-12 21:03:03
1.4K2
发布2020-01-12 21:03:03
举报
文章被收录于专栏:python3python3

python stomp收发指定的消息

代码语言:javascript
复制
# -*- 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中

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-08-14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • python stomp收发指定的消息
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档