Last active
July 17, 2017 14:10
-
-
Save linuxoid69/6874eea0e0b24a99a49fde7d775d08cf to your computer and use it in GitHub Desktop.
python activemq example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
import sys | |
import stomp | |
from stomp import * | |
conn = stomp.Connection() | |
conn.start() | |
conn.connect('admin', 'admin', wait=True) | |
conn.send(body='{"foo":"bar"}', destination='/queue/test') | |
conn.disconnect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
import stomp | |
from stomp import * | |
class MyListener(stomp.ConnectionListener): | |
def on_error(self, headers, message): | |
print('received an error "%s"' % message) | |
def on_message(self, headers, message): | |
print('received a message "%s"' % message) | |
def reconnect(): | |
conn = stomp.Connection(keepalive=True) | |
conn.set_listener('ilisten', MyListener()) | |
conn.start() | |
conn.connect('admin', 'admin', wait=True) | |
conn.subscribe(destination='/queue/test', id=1, ack='auto') | |
return conn | |
conn = reconnect() | |
while True: | |
time.sleep(1) | |
if not conn.is_connected(): | |
time.sleep(5) | |
conn = reconnect() | |
conn.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment