python使用stomp连接activemq
一、安装ActiveMQ服务
1. 当使用windows时,安装参考:https://blog.csdn.net/WuLex/article/details/78323811
启动:运行activemq.bat
2. 当使用linux时,安装参考:https://www.cnblogs.com/andylhc/p/9337628.html
启动:./activemq start
二、python使用stomp连接activemq
安装模块:pip3 install stomp.py (注意是python3)
Python脚本如下:
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 19 09:54:08 2018 @author: lihc
""" # -*-coding:utf-8-*-
import stomp
import time queue_name = '/queue/SampleQueue'
topic_name = '/topic/SampleTopic'
listener_name = 'SampleListener'
post=61613 class SampleListener(object):
def on_message(self, headers, message):
print ('headers: %s' % headers)
print ('message: %s' % message) # 推送到队列queue
def send_to_queue(msg):
conn = stomp.Connection10([('127.0.0.1',post)])
conn.start()
conn.connect()
conn.send(queue_name, msg)
conn.disconnect() #推送到主题
def send_to_topic(msg):
conn = stomp.Connection10([('127.0.0.1',post)])
conn.start()
conn.connect()
conn.send(topic_name, msg)
conn.disconnect() ##从队列接收消息
def receive_from_queue():
conn = stomp.Connection10([('127.0.0.1',61613)])
conn.set_listener(listener_name, SampleListener())
conn.start()
conn.connect()
conn.subscribe(queue_name)
time.sleep(1) # secs
conn.disconnect() ##从主题接收消息
def receive_from_topic():
conn = stomp.Connection10([('127.0.0.1',post)])
conn.set_listener(listener_name, SampleListener())
conn.start()
conn.connect()
conn.subscribe(topic_name)
while 1:
send_to_topic('topic')
time.sleep(3) # secs
conn.disconnect() if __name__=='__main__':
send_to_queue('len 123')
receive_from_queue()
# send_to_topic('len 345')
# receive_from_topic()
原文:https://blog.csdn.net/five3/article/details/79569587
另外参考:http://www.cnblogs.com/GarfieldTom/p/4153957.html
python使用stomp连接activemq的更多相关文章
- php 通过stomp协议连接ActiveMQ
一.安装php的stomp扩展 http://pecl.php.net/package/stomp 如:stomp-2.0.0.tgz > tar xf stomp-1.0.9.tgz > ...
- golang连接activemq,发送接收数据
介绍 使用golang连接activemq发送数据的话,需要使用一个叫做stomp的包,直接go get github.com/go-stomp/stomp即可 代码 生产者 package main ...
- python 使用pymssql连接sql server数据库
python 使用pymssql连接sql server数据库 #coding=utf-8 #!/usr/bin/env python#------------------------------ ...
- Python中HTTPS连接
permike 原文 Python中HTTPS连接 今天写代码时碰到一个问题,花了几个小时的时间google, 首先需要安装openssl,更新到最新版本后,在浏览器里看是否可访问,如果是可以的,所以 ...
- 消费者端的Spring JMS 连接ActiveMQ接收生产者Oozie Server发送的Oozie作业执行结果
一,介绍 Oozie是一个Hadoop工作流服务器,接收Client提交的作业(MapReduce作业)请求,并把该作业提交给MapReduce执行.同时,Oozie还可以实现消息通知功能,只要配置好 ...
- boto3--通过Python的SDK连接aws
通过Python的SDK连接aws 参考: https://aws.amazon.com/cn/developers/getting-started/python/ aws上生成访问密钥 ID 和私有 ...
- 【Python】Windows平台下Python、Pydev连接Mysql数据库
Mysql数据库是跨平台的,不是说Python一定就要连接Mongodb. Python连接Mysql数据库是非常easy的. 首先,你要配置好Python的开发环境,详见<[Python]Wi ...
- python使用sqlalchemy连接pymysql数据库
python使用sqlalchemy连接mysql数据库 字数833 阅读461 评论0 喜欢1 sqlalchemy是python当中比较出名的orm程序. 什么是orm? orm英文全称objec ...
- python:字符串的连接
python中有很多字符串连接方式,今天在写代码,顺便总结一下: 最原始的字符串连接方式:str1 + str2 python 新字符串连接语法:str1, str2 奇怪的字符串方式:str1 st ...
随机推荐
- springboot项目利用Swagger2生成在线接口文档
Swagger简介. Swagger2是一款restful接口文档在线生成和在线调试工具.很多项目团队利用Swagger自动生成接口文档,保证接口文档和代码同步更新.在线调试.简单地说,你可以利用这个 ...
- SystemCheckError: System check identified some issues: ERRORS: users.Test.groups: (fields.E304) Reverse accessor for 'Test.groups' clashes with reverse accessor for 'User.groups'.
Error Msg: SystemCheckError: System check identified some issues: ERRORS: users.Test.groups: (fields ...
- python xlwt模块生成excel文件并写入数据 xlrd读取数据
python中一般使用 xlwt (excel write)来生成Excel文件(可以控制单元格格式),用 xlrd 来读取Excel文件,用xlrd读取excel是不能对其进行操作的. 1.xlrd ...
- 动态生成table 列
table.render({ elem: '#test-table-comelist' ,url: layui.setter.base + 'list/comelist' ,cols: [[]] ,d ...
- Luogu5289 十二省联考2019皮配(动态规划)
将选择导师看成先选阵营再选派系,这样有显然的O(nm2)暴力,即按城市排序后,设f[i][j][k]为前i个学校中第一个阵营有j人第一个派系有k人的方案数,暴力背包. 对于k=0,可以发现选阵营和选派 ...
- https://oi-wiki.org/
OI网站 https://oi-wiki.org/
- MYSQL IN 出现的慢查询问题
IN = https://blog.csdn.net/solmyr_biti/article/details/54293492 https://www.cnblogs.com/wxw16/p/6105 ...
- rt-thread 之组件与设备初始化配置
@2019-03-08 [小记] rt-thread 初始化配置有两个分支: 第一,板级设备初始化 rt_components_board_init() 第二,内核组件初始化 rt_component ...
- jieba 库的使用和好玩的词云
jieba库的使用: (1) jieba库是一款优秀的 Python 第三方中文分词库,jieba 支持三种分词模式:精确模式.全模式和搜索引擎模式,下面是三种模式的特点. 精确模式:试图将语句最精 ...
- python+turtle 笔记
用Python+turtle绘制佩琪: from turtle import * def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 ...