Client - stompy.stomp

exception stompy.stomp.ConnectionError

Couldn’t connect to the STOMP server.

exception stompy.stomp.ConnectionTimeoutError

Timed-out while establishing connection to the STOMP server.

exception stompy.stomp.NotConnectedError

No longer connected to the STOMP server.

class stompy.stomp.Stomp(hostname, port=61613)

STOMP Client.

Parameters:
  • hostname – Hostname of the STOMP server to connect to.
  • port – The port to use. (default 61613)
exception ConnectionError

Couldn’t connect to the STOMP server.

exception Stomp.ConnectionTimeoutError

Timed-out while establishing connection to the STOMP server.

exception Stomp.NotConnectedError

No longer connected to the STOMP server.

Stomp.abort(conf=None)

Abort transaction.

In the case of ActiveMQ, you could do this:

>>> stomp.abort({'transaction':'<randomish_hash_like_thing>'})
Stomp.ack(frame)

Acknowledge receipt of a message

Param :A stompy.frame.Frame instance.

Example

>>> while True:
...     frame = stomp.receive_frame()
...     stomp.ack(frame)
Stomp.begin(conf=None)

Begin transaction.

You will need to pass any headers your STOMP server likes.

destination is required

In the case of ActiveMQ, you could do this:

>>> stomp.begin({'transaction':'<randomish_hash_like_thing>'})
Stomp.commit(conf=None)

Commit transaction.

You will need to pass any headers your STOMP server likes.

destination is required

In the case of ActiveMQ, you could do this:

>>> stomp.commit({'transaction':'<randomish_hash_like_thing>'})
Stomp.connect(username=None, password=None, clientid=None)

Connect to STOMP server.

Parameters:
  • username – Username for connection
  • password – Password for connection
  • clientid – Client identification for persistent connections
Stomp.disconnect(conf=None)

Disconnect from the server.

Stomp.poll(callback=None)

Alias to receive_frame() with nonblocking=True.

Stomp.receive_frame(callback=None, nonblocking=False)

Get a frame from the STOMP server

Parameters:
  • nonblocking – By default this function waits forever until there is a message to be received, however, in non-blocking mode it returns None if there is currently no message available.
  • callback – Optional function to execute when message recieved.

Note that you must be subscribed to one or more destinations. Use subscribe() to subscribe to a topic/queue.

Example: Blocking

>>> while True:
...     frame = stomp.receive_frame()
...     print(frame.headers['message-id'])
...     stomp.ack(frame)

Example: Non-blocking

>>> frame = stomp.recieve_frame(nonblocking=True)
>>> if frame:
...     process_message(frame)
... else:
...     # no messages yet.
Stomp.send(conf=None)

Send message to STOMP server

You’ll need to pass the body and any other headers your STOMP server likes.

destination is required

In the case of ActiveMQ with persistence, you could do this:

>>> for i in xrange(1,1000):
...     stomp.send({'destination': '/queue/foo',
...                 'body': 'Testing',
...                 'persistent': 'true'})
Stomp.send_frame(frame)

Send a custom frame to the STOMP server

Parameters:

Example

>>> from stompy import Frame
>>> frame = Frame().build_frame({
...    "command": "DISCONNECT",
...    "headers": {},
... })
>>> stomp.send_frame(frame)
Stomp.subscribe(conf=None)

Subscribe to a given destination

You will need to pass any headers your STOMP server likes.

destination is required

In the case of ActiveMQ, you could do this:

>>> stomp.subscribe({'destination':'/queue/foo',
...                  'ack':'client'})
Stomp.subscribed

DEPRECATED The queue or topic currently subscribed to.

Stomp.unsubscribe(conf=None)

Unsubscribe from a given destination

You will need to pass any headers your STOMP server likes.

destination is required

>>> stomp.unsubscribe({'destination':'/queue/foo'})

This Page