Python can also connect to MQ, taking ACTIVEMQ as an example to install stomp.py:
https://github.com/jasonrbriggs/stomp.py
Install after download:
Python setup.py Install
Very simple, then a simple example:
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)
#The connection code of the official example is also behind, and it is now divided into protocol versions
conn = stomp.Connection10 ([(‘ip ...‘, 61613)])
conn.set_listener (‘‘, MyListener ())
conn.start ()
conn.connect ()
conn.subscribe (destination = ‘/ queue / test’, id = 1, ack = ‘auto’)
#Note that it is problematic to send a message like this in the official example
# 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 ()
OK, you can send and receive messages!
Python+stomp+activemq