Simple Client - stompy.simple

class stompy.simple.Client(host='localhost', port=61613)

Simple STOMP client.

  • host – Hostname of the server to connect to (default: localhost)
  • port – Port of the server to connect to (default: 61613)


>>> from stompy.simple import Client
>>> stomp = Client()
>>> stomp.connect()
>>> stomp.put("The quick brown fox...", destination="/queue/test")
>>> stomp.subscribe("/queue/test")
>>> message = stomp.get_nowait()
>>> message.body
'The quick brown fox...'
>>> stomp.ack(message)
>>> stomp.unsubscribe("/queue/test")
>>> stomp.disconnect()
exception Empty

Exception raised by Queue.get(block=0)/get_nowait().


Roll-back current transaction.


Acknowledge message.

  • frame – The message to acknowledge.

Begin transaction.

Every ack() and send() will be affected by this transaction and won’t be real until a commit() is issued. To roll-back any changes since the transaction started use abort().


Commit current transaction.

Client.connect(username=None, password=None, clientid=None)

Connect to the broker.

  • username – Username for connection
  • password – Password for connection
  • clientid – Client identification for persistent connections
:raises stompy.stomp.ConnectionError:
if the connection was unsuccessful.
:raises stompy.stomp.ConnectionTimeoutError:
if the connection timed out.

Disconnect from the broker.

Client.get(block=True, callback=None)

Get message.

  • block – Block if necessary until an item is available. If this is False, return an item if one is immediately available, else raise the Empty exception.
  • callback – Optional function to execute when message recieved.
Raises Empty:

If block is off and no message was receied.


Remove and return an item from the queue without blocking.

Only get an item if one is immediately available. Otherwise raise the Empty exception.

See get().

Client.put(item, destination, persistent=True, conf=None)

Put an item into the queue.

  • item – Body of the message.
  • destination – Destination queue.
  • persistent – Is message persistent? (store on disk).
  • conf – Extra headers to send to the broker.

The resulting stompy.frame.Frame instance.

Client.subscribe(destination, ack='auto', conf=None)

Subscribe to topic/queue.

  • destination – The destination queue/topic to subscribe to.
  • ack – How to handle acknowledgment, either auto - ack is handled by the server automatically, or client - ack is handled by the client itself by calling ack().
  • conf – Additional headers to send with the subscribe request.
Client.unsubscribe(destination, conf=None)

Unsubscribe from topic/queue previously subscribed to.

  • destination – The destination queue/topic to unsubscribe from.
  • conf – Additional headers to send with the unsubscribe request.
exception stompy.simple.TransactionError

Transaction related error.

Previous topic

Frames and communication - stompy.frame

This Page