-
-
Save carlosabalde/956af228116cd638ff0a to your computer and use it in GitHub Desktop.
Simple STOMP consumer for debugging purposes. Depends on stomp.py Python package (https://github.com/kwoli/stomp.py).
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
import time | |
import logging | |
import stomp | |
class SimpleListener(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 | |
def consume(host, port, destination): | |
logging.basicConfig(level=logging.DEBUG) | |
connection = stomp.Connection(host_and_ports=[(host, port)]) | |
try: | |
connection.set_listener('', SimpleListener()) | |
connection.start() | |
connection.connect() | |
connection.subscribe(destination=destination, ack='auto') | |
while True: | |
time.sleep(1) | |
finally: | |
connection.disconnect() | |
if __name__ == '__main__': | |
consume('127.0.0.1', 61613, '/topic/whatever') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment