zoukankan      html  css  js  c++  java
  • python+stomp+activemq

    python也可以连接MQ,以ActiveMQ为例,安装stomp.py:

    https://github.com/jasonrbriggs/stomp.py

    下载后安装:

    python setup.py install

    很简单,然后一个简单的示例:

    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([('ip...',61613)])
    conn.set_listener('', MyListener())
    conn.start()
    conn.connect()
    
    conn.subscribe(destination='/queue/test', id=1, ack='auto')
    #注意,官方示例这样发送消息的  $ python simple.py hello world
    #conn.send(body='hello,garfield! this is '.join(sys.argv[1:]), destination='/queue/test')
    conn.send(body='hello,garfield!', destination='/queue/test')
    
    time.sleep(2)
    conn.disconnect()

    好了,可以发送、接收消息了!

  • 相关阅读:
    U-Boot新手入门
    安装交叉编译工具
    Makefile 工程管理
    gcc基本用法
    poj 3264 Balanced Lineup
    hdoj 1166 敌兵布阵
    poj 1363 Rails
    poj 1028 Web Navigation
    zoj 3621 Factorial Problem in Base K
    poj1861最小生成树
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/4153957.html
Copyright © 2011-2022 走看看