首先这个stomp是需要我们手动安装的,他的下载地址是https://github.com/jasonrbriggs/stomp.py,选择"clone or download",然后把整个压缩文件传递到linux服务器里,解压缩之后,在stomp文件夹里使用# python setup.py install,然后就看见如下文字可以证明stomp已经安装成功了:
然后我们来写一个简单的测试队列的脚本,脚本内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[iyunv@zabbix ~]# cat mqtest.py
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' % message)
conn = stomp.Connection([('mq的内网ip地址',61613)])
conn.set_listener('', MyListener())
conn.start()
conn.connect('mq的账号','mq的密码')
conn.subscribe(destination='/queue/chenshuo', id=1, ack='auto')
conn.send(body='hello,this is my test message!', destination='/queue/chenshuo')
time.sleep(2)
conn.disconnect()