Simple Client - stompy.simple

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

Simple STOMP client.

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

Example

>>> 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().

Client.abort()

Roll-back current transaction.

Client.ack(frame)

Acknowledge message.

Parameters:
  • frame – The message to acknowledge.
Client.begin(transaction)

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().

Client.commit(transaction)

Commit current transaction.

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

Connect to the broker.

Parameters:
  • 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.
Client.disconnect()

Disconnect from the broker.

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

Get message.

Parameters:
  • 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.

Client.get_nowait()

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.

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

The resulting stompy.frame.Frame instance.

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

Subscribe to topic/queue.

Parameters:
  • 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.

Parameters:
  • 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