A Python library that enables simple STOMP communication over WebSockets. Works on the client-side with any STOMP server.
WebSockets have grown into an elementary tool that allow applications to exchange data bi-directionally over the web. In most cases, browsers communicate to webservers in interactive websites. However, there might be cases where services communicate with each other in real time.
For such use-cases, StompWS enables applications written in Python to communicate with STOMP based webservices through a simple API.
STOMP is a frame based protocol. A frame consists of a command, a set of optional headers and an optional body. A STOMP client is a user-agent which can act in two (possibly simultaneous) modes:
- as a producer, sending messages to a destination on the server via a
SEND
frame - as a consumer, sending a
SUBSCRIBE
frame for a given destination and receiving messages from the server asMESSAGE
frames.
The API exposed by the library abstracts away most of this.
We instantiate a Stomp object to obtain a reference to the core API:
stomp = Stomp("hostname/endpoint", sockjs=True, wss=False)
Below are the APIs that are exposed by the object
Attempts to connect to the server using the information provided while instantiating.
Sends message
to destination
on the server. Refer your STOMP server documentation to find out what that is.
Subscribes to a destination
(think topic) on the STOMP server to receive messages that are published on it.
The callback
argument must be a function that accepts a msg
argument:
# define the callback function that should act upon the message
def do_something(msg):
print(msg)
# subscribe to a destination and pass the callback function
stomp.subscribe('/some-destination', do_something)
- logging
- better message passing bw Stomp and Dispatcher (reduce spaghetti code)
- add trace flag