API

Clients

This part of the documentation covers the primary API for interacting with Strava.

Simplex

Support for basic, one-way (publish-only) communication with stomp server.

class stompclient.simplex.BaseClient(host, port=61613, socket_timeout=3.0, connection_pool=None)[source]

Bases: object

An abstract STOMP client base class with shared functionality.

Variables:
  • host – The STOMP server hostname or IP address.
  • port – The STOMP server port.
  • socket_timeout – How long to block on reading from sockets before raising exception.
  • connection_pool – Object responsible for issuing STOMP connections.
abort(transaction, extra_headers=None)[source]

Abort (rollback) transaction.

Parameters:transaction (C{str}) – The transaction ID.
ack(message_id, transaction=None, extra_headers=None)[source]

Acknowledge receipt of a message.

Parameters:transaction (C{str}) – (optional) The transaction ID associated with this ACK.
begin(transaction, extra_headers=None)[source]

Begin transaction.

Parameters:transaction (C{str}) – The transaction ID.
commit(transaction, extra_headers=None)[source]

Commit transaction.

Parameters:transaction (C{str}) – The transaction ID.
connect(login=None, passcode=None, extra_headers=None)[source]

Send CONNECT frame to the STOMP server.

connection

A connection object from the configured pool. :rtype: stompclient.connection.Connection

disconnect(conf=None, extra_headers=None)[source]

Disconnect from the server.

send(destination, body=None, transaction=None, extra_headers=None)[source]

Sends a message to STOMP server.

Parameters:
  • destination (C{str}) – The destination “path” for message.
  • body (C{str}) – The body (bytes) of the message.
  • transaction (C{str}) – (optional) The transaction ID associated with this ACK.
send_frame(frame)[source]

Send a frame to the STOMP server and return result (if applicable).

Parameters:frame (stomp.frame.Frame) – The frame instance to send.
Returns:The “response” frame from stomp server (if applicable).
Return type:stompclient.frame.Frame
subscribe(destination, extra_headers=None)[source]

Subscribe to a given destination.

Parameters:destination (C{str}) – The destination “path” to subscribe to.
unsubscribe(destination=None, extra_headers=None)[source]

Unsubscribe from a given destination.

Parameters:destination (C{str}) – The destination “path” to unsubscribe from.
class stompclient.simplex.PublishClient(host, port=61613, socket_timeout=None, connection_pool=None)[source]

Bases: stompclient.simplex.BaseClient

A basic STOMP client that provides a publish-only interaction with server.

This client does not support subscribing to destinations, the ‘receipt’ header (which expects acknowledgement of message from server), and does not process CONNECTED frames to keep track of session id (which is not actually used by the protocol anyway).

This client is ideally suited for use in a multi-threaded server environment, since it can be used with a ThreadLocalConnection pool (since there is no need for a message- receiving thread).

Variables:connection_pool – Object responsible for issuing STOMP connections (defaults to using stompclient.connection.ThreadLocalConnectionPool for this client impl).
abort(transaction, extra_headers=None)

Abort (rollback) transaction.

Parameters:transaction (C{str}) – The transaction ID.
ack(message_id, transaction=None, extra_headers=None)

Acknowledge receipt of a message.

Parameters:transaction (C{str}) – (optional) The transaction ID associated with this ACK.
begin(transaction, extra_headers=None)

Begin transaction.

Parameters:transaction (C{str}) – The transaction ID.
commit(transaction, extra_headers=None)

Commit transaction.

Parameters:transaction (C{str}) – The transaction ID.
connect(login=None, passcode=None, extra_headers=None)

Send CONNECT frame to the STOMP server.

connection

A connection object from the configured pool. :rtype: stompclient.connection.Connection

disconnect(conf=None, extra_headers=None)

Disconnect from the server.

send(destination, body=None, transaction=None, extra_headers=None)

Sends a message to STOMP server.

Parameters:
  • destination (C{str}) – The destination “path” for message.
  • body (C{str}) – The body (bytes) of the message.
  • transaction (C{str}) – (optional) The transaction ID associated with this ACK.
send_frame(frame)[source]

Send a frame to the STOMP server.

This implementation does not support the ‘receipt’ header; it can be overridden in subclasses to support reading responses from the server socket.

Parameters:frame (stomp.frame.Frame) – The frame instance to send.
Raises NotImplementedError:
 If the frame includes a ‘receipt’ header, since this implementation does not support receiving data from the STOMP broker.
subscribe(destination, extra_headers=None)[source]

Subscribe to a given destination.

Parameters:destination (C{str}) – The destination “path” to subscribe to.
unsubscribe(destination, extra_headers=None)[source]

Unsubscribe from a given destination.

Parameters:destination (C{str}) – The destination to subscribe to.

Duplex

Clients that support both sending and receiving messages (produce & consume).

class stompclient.duplex.BaseBlockingDuplexClient(host, port=61613, socket_timeout=3.0, connection_pool=None)[source]

Bases: stompclient.simplex.BaseClient

Base class for STOMP client that uses listener loop to receive frames.

This client uses the listen_forever() method to receive frames from the server. Typically, this would be run in its own thread:

listener_thread = threading.Thread(target=client.listen_forever)
listener_thread.start()
client.listening_event.wait()
Variables:
  • listening_event – A threading event that will be set when the listening loop is running, meaning that client is receiving frames.
  • shutdown_event – An event that will be set when the listening loop should terminate. This is set internally by the disconnect() method.
  • subscribed_destinations – A dict of subscribed destinations (only keys are required in base impl).
  • subscription_lock – A threading.RLock used to guard access to subscribed_destionations property.
abort(transaction, extra_headers=None)

Abort (rollback) transaction.

Parameters:transaction (C{str}) – The transaction ID.
ack(message_id, transaction=None, extra_headers=None)

Acknowledge receipt of a message.

Parameters:transaction (C{str}) – (optional) The transaction ID associated with this ACK.
begin(transaction, extra_headers=None)

Begin transaction.

Parameters:transaction (C{str}) – The transaction ID.
commit(transaction, extra_headers=None)

Commit transaction.

Parameters:transaction (C{str}) – The transaction ID.
connect(login=None, passcode=None, extra_headers=None)

Send CONNECT frame to the STOMP server.

connection

A connection object from the configured pool. :rtype: stompclient.connection.Connection

disconnect(extra_headers=None)[source]

Sends DISCONNECT frame and disconnect from the server.

dispatch_frame(frame)[source]

Route the frame to the appropriate destination.

Parameters:frame (stompclient.frame.Frame) – Received frame.
listen_forever()[source]

Blocking method that reads from connection socket.

This would typically be started within its own thread, since it will block until error or shutdown_event is set.

send(destination, body=None, transaction=None, extra_headers=None)

Sends a message to STOMP server.

Parameters:
  • destination (C{str}) – The destination “path” for message.
  • body (C{str}) – The body (bytes) of the message.
  • transaction (C{str}) – (optional) The transaction ID associated with this ACK.
send_frame(frame)

Send a frame to the STOMP server and return result (if applicable).

Parameters:frame (stomp.frame.Frame) – The frame instance to send.
Returns:The “response” frame from stomp server (if applicable).
Return type:stompclient.frame.Frame
subscribe(destination, extra_headers=None)

Subscribe to a given destination.

Parameters:destination (C{str}) – The destination “path” to subscribe to.
unsubscribe(destination=None, extra_headers=None)

Unsubscribe from a given destination.

Parameters:destination (C{str}) – The destination “path” to unsubscribe from.
class stompclient.duplex.PublishSubscribeClient(host, port=61613, socket_timeout=3.0, connection_pool=None, queue_timeout=5.0)[source]

Bases: stompclient.duplex.QueueingDuplexClient

A publish-subscribe client that supports providing callback functions for subscriptions.

Variables:subscribed_destinations – A dict of subscribed destinations to callables.
abort(transaction, extra_headers=None)

Abort (rollback) transaction.

Parameters:transaction (C{str}) – The transaction ID.
ack(message_id, transaction=None, extra_headers=None)

Acknowledge receipt of a message.

Parameters:transaction (C{str}) – (optional) The transaction ID associated with this ACK.
begin(transaction, extra_headers=None)

Begin transaction.

Parameters:transaction (C{str}) – The transaction ID.
commit(transaction, extra_headers=None)

Commit transaction.

Parameters:transaction (C{str}) – The transaction ID.
connect(login=None, passcode=None, extra_headers=None)

Send CONNECT frame to the STOMP server and return CONNECTED frame (if possible).

This method will issue a warning (warnings.warn) if the listener loop is not running.

Returns:The CONNECTED frame from the server.
Return type:stompclient.frame.Frame
connection

A connection object from the configured pool. :rtype: stompclient.connection.Connection

disconnect(extra_headers=None)

Sends DISCONNECT frame and disconnect from the server.

dispatch_frame(frame)[source]

Route the frame to the appropriate destination.

Parameters:frame (stompclient.frame.Frame) – Received frame.
listen_forever()

Blocking method that reads from connection socket.

This would typically be started within its own thread, since it will block until error or shutdown_event is set.

send(destination, body=None, transaction=None, extra_headers=None)

Sends a message to STOMP server.

Parameters:
  • destination (C{str}) – The destination “path” for message.
  • body (C{str}) – The body (bytes) of the message.
  • transaction (C{str}) – (optional) The transaction ID associated with this ACK.
send_frame(frame)

Send a frame to the STOMP server.

This implementation does support the ‘receipt’ header, blocking on the receipt queue until a receipt frame is received.

This implementation does NOT attempt to disconnect/reconnect if connection error received, because disconnecting the socket royally pisses off the listen_forever blocking loop.

Parameters:frame (L{stomp.frame.Frame}) – The frame instance to send.
Raises NotImplementedError:
 If the frame includes a ‘receipt’ header, since this implementation does not support receiving data from the STOMP broker.
subscribe(destination, callback, ack=None, extra_headers=None)[source]

Subscribe to a given destination with specified callback function.

The callable will be passed the received stompclient.frame.Frame object.

Parameters:
  • destination (str) – The destination “path” to subscribe to.
  • callback (callable) – The callable that will be sent frames received at specified destination.
  • ack (str) – If set to ‘client’ will require clients to explicitly ack() any frames received (in order for server to consider them delivered).
unsubscribe(destination, extra_headers=None)

Unsubscribe from a given destination (or id).

One of the ‘destination’ or ‘id’ parameters must be specified.

Parameters:destination (str) – The destination to subscribe to.
Raises ValueError:
 Underlying code will raise if neither destination nor id params are specified.
class stompclient.duplex.QueueingDuplexClient(host, port=61613, socket_timeout=3.0, connection_pool=None, queue_timeout=5.0)[source]

Bases: stompclient.duplex.BaseBlockingDuplexClient

A STOMP client that supports both producer and consumer roles, depositing received frames onto thread-safe queues.

This class can be used directly; however, it requires that the calling code pull frames from the queues and dispatch them. More typically, this class can be used as a basis for a more convenient frame-dispatching client.

Because this class must be run in a multi-threaded context (thread for listening loop), it IS NOT thread-safe. Specifically is must be used with a non-threadsafe connecton pool, so that the same connection can be accessed from multipl threads.

Variables:
  • connected_queue – A queue to hold CONNECTED frames from the server.
  • message_queue – A queue of all the MESSAGE frames from the server to a destination that has been subscribed to.
  • receipt_queue – A queue of RECEPT frames from the server (these are replies to requests that included the ‘receipt’ header).
  • error_queue – A queue of ERROR frames from the server.
  • queue_timeout – How long should calls block on fetching frames from queue before timeout and exception?
abort(transaction, extra_headers=None)

Abort (rollback) transaction.

Parameters:transaction (C{str}) – The transaction ID.
ack(message_id, transaction=None, extra_headers=None)

Acknowledge receipt of a message.

Parameters:transaction (C{str}) – (optional) The transaction ID associated with this ACK.
begin(transaction, extra_headers=None)

Begin transaction.

Parameters:transaction (C{str}) – The transaction ID.
commit(transaction, extra_headers=None)

Commit transaction.

Parameters:transaction (C{str}) – The transaction ID.
connect(login=None, passcode=None, extra_headers=None)[source]

Send CONNECT frame to the STOMP server and return CONNECTED frame (if possible).

This method will issue a warning (warnings.warn) if the listener loop is not running.

Returns:The CONNECTED frame from the server.
Return type:stompclient.frame.Frame
connection

A connection object from the configured pool. :rtype: stompclient.connection.Connection

disconnect(extra_headers=None)

Sends DISCONNECT frame and disconnect from the server.

dispatch_frame(frame)[source]

Route the frame to the appropriate destination.

Parameters:frame (stompclient.frame.Frame) – Received frame.
listen_forever()

Blocking method that reads from connection socket.

This would typically be started within its own thread, since it will block until error or shutdown_event is set.

send(destination, body=None, transaction=None, extra_headers=None)

Sends a message to STOMP server.

Parameters:
  • destination (C{str}) – The destination “path” for message.
  • body (C{str}) – The body (bytes) of the message.
  • transaction (C{str}) – (optional) The transaction ID associated with this ACK.
send_frame(frame)[source]

Send a frame to the STOMP server.

This implementation does support the ‘receipt’ header, blocking on the receipt queue until a receipt frame is received.

This implementation does NOT attempt to disconnect/reconnect if connection error received, because disconnecting the socket royally pisses off the listen_forever blocking loop.

Parameters:frame (L{stomp.frame.Frame}) – The frame instance to send.
Raises NotImplementedError:
 If the frame includes a ‘receipt’ header, since this implementation does not support receiving data from the STOMP broker.
subscribe(destination, ack=None, extra_headers=None)[source]

Subscribe to a given destination.

Parameters:
  • destination (str) – The destination “path” to subscribe to.
  • ack (str) – If set to ‘client’ will require clients to explicitly ack() any frames received (in order for server to consider them delivered).
unsubscribe(destination, extra_headers=None)[source]

Unsubscribe from a given destination (or id).

One of the ‘destination’ or ‘id’ parameters must be specified.

Parameters:destination (str) – The destination to subscribe to.
Raises ValueError:
 Underlying code will raise if neither destination nor id params are specified.

Connections

class stompclient.connection.Connection(host, port=61613, socket_timeout=None)[source]

Bases: object

Manages TCP connection to the STOMP server and provides an abstracted interface for sending and receiving STOMP frames.

This class provides some basic synchronization to avoid threads stepping on eachother. Specifically the following activities are each protected by [their own] threading.RLock instances:

  • connect() and disconnect() methods (share a lock).
  • read()
  • send()

It is assumed that send() and recv() should be allowed to happen concurrently, so these do not share a lock. If you need more thread-isolation, consider using a thread-safe connection pool implementation (e.g. stompclient.connection.ThreadLocalConnectionPool).

Variables:
  • host – The hostname/address for this connection.
  • port – The port for this connection.
  • socket_timeout – Socket timeout (in seconds).
connect()[source]

Connects to the STOMP server if not already connected.

connected

Whether this connection thinks it is currently connected.

disconnect(conf=None)[source]

Disconnect from the server, if connected.

Raises NotConnectedError:
 If the connection is not currently connected.
read()[source]

Blocking call to read and return a frame from underlying socket.

Frames are buffered using a stompclient.util.FrameBuffer internally, so subsequent calls to this method may simply return an already-buffered frame.

Returns:A frame read from socket or buffered from previous socket read.
Return type:stompclient.frame.Frame
send(frame)[source]

Sends the specified frame to STOMP server.

Parameters:frame (stompclient.frame.Frame) – The frame to send to server.
class stompclient.connection.ConnectionPool[source]

Bases: object

A global pool of connections keyed by host:port.

This pool does not provide any thread-localization for the connections that it stores; use the ThreadLocalConnectionPool subclass if you want to ensure that connections cannot be shared between threads.

get_all_connections()[source]

Return a list of all connection objects the manager knows about

get_connection(host, port, socket_timeout=None)[source]

Return a specific connection for the specified host and port.

make_connection_key(host, port)[source]

Create a unique key for the specified host and port.

class stompclient.connection.ThreadLocalConnectionPool[source]

Bases: stompclient.connection.ConnectionPool, thread._local

A connection pool that ensures that connections are not shared between threads.

This is useful for publish-only clients when desiring a connection pool to be used in a multi-threaded context (e.g. web servers). This notably does NOT work for publish- subscribe clients, since a listener thread needs to be able to share the same socket with other publisher thread(s).

Errors

The exception classes raised by the library.

Exception classes used by the stompclient library.

exception stompclient.exceptions.ConnectionError[source]

Bases: socket.error

Couldn’t connect to the STOMP server.

errno

exception errno

filename

exception filename

strerror

exception strerror

exception stompclient.exceptions.ConnectionTimeoutError[source]

Bases: socket.timeout

Timed-out while establishing connection to the STOMP server.

errno

exception errno

filename

exception filename

strerror

exception strerror

exception stompclient.exceptions.FrameError[source]

Bases: exceptions.Exception

Raise for problem with frame generation or parsing.

exception stompclient.exceptions.NotConnectedError[source]

Bases: exceptions.Exception

No longer connected to the STOMP server.

Under-the-Hood

Message Frames

Classes to support reading and writing STOMP frames.

This is a mixture of code from the stomper project and the stompy project codebases.

class stompclient.frame.AbortFrame(transaction, extra_headers=None)[source]

Bases: stompclient.frame.Frame

An ABORT client frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.AckFrame(message_id, transaction=None, extra_headers=None)[source]

Bases: stompclient.frame.Frame

An ACK client frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.BeginFrame(transaction, extra_headers=None)[source]

Bases: stompclient.frame.Frame

A BEGIN client frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.CommitFrame(transaction, extra_headers=None)[source]

Bases: stompclient.frame.Frame

A COMMIT client frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.ConnectFrame(login=None, passcode=None, extra_headers=None)[source]

Bases: stompclient.frame.Frame

A CONNECT client frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.ConnectedFrame(session, extra_headers=None)[source]

Bases: stompclient.frame.Frame

A CONNECTED server frame (response to CONNECT).

Variables:session – The (throw-away) session ID to include in response.
command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.DisconnectFrame(extra_headers=None)[source]

Bases: stompclient.frame.Frame

A DISCONNECT client frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.ErrorFrame(message, body=None, extra_headers=None)[source]

Bases: stompclient.frame.Frame

An ERROR server frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.Frame(command=None, headers=None, body=None)[source]

Bases: object

Class to hold a STOMP message frame.

This class is based on code from the Stomper project, with a few modifications.

Variables:
  • command – The STOMP command. When assigned it is validated against the VALID_COMMANDS module-level list.
  • headers – A dictionary of headers for this frame.
  • body – The body of the message (bytes).
command

Returns the command for this frame.

pack()[source]

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)[source]

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)[source]

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)[source]

Parse data from received bytes into this frame object.

class stompclient.frame.HeaderValue(calculator)[source]

Bases: object

An descriptor class that can be used when a calculated header value is needed.

This class is a descriptor, implementing __get__ to return the calculated value. While according to U{http://docs.codehaus.org/display/STOMP/Character+Encoding} there seems to some general idea about having UTF-8 as the character encoding for headers; however the stomper lib does not support this currently.

For example, to use this class to generate the content-length header:

>>> body = 'asdf'
>>> headers = {}
>>> headers['content-length'] = HeaderValue(calculator=lambda: len(body))
>>> str(headers['content-length'])
'4' 
Variables:calc – The calculator function.
class stompclient.frame.MessageFrame(destination, body=None, message_id=None, extra_headers=None)[source]

Bases: stompclient.frame.Frame

A MESSAGE server frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.ReceiptFrame(receipt, extra_headers=None)[source]

Bases: stompclient.frame.Frame

A RECEIPT server frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.SendFrame(destination, body=None, transaction=None, extra_headers=None)[source]

Bases: stompclient.frame.Frame

A SEND client frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.SubscribeFrame(destination, ack=None, id=None, selector=None, extra_headers=None)[source]

Bases: stompclient.frame.Frame

A SUBSCRIBE client frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

class stompclient.frame.UnsubscribeFrame(destination=None, id=None, extra_headers=None)[source]

Bases: stompclient.frame.Frame

An UNSUBSCRIBE client frame.

command

Returns the command for this frame.

pack()

Create a string representation from object state.

Returns:The string (bytes) for this stomp frame.
Return type:str
parse_command(framebytes)

Parse command received from the server.

Returns:The command.
Return type:str
parse_headers(headers_str)

Parse headers received from the servers and convert to a dict.

Returns:The headers dict.
Return type:dict
unpack(framebytes)

Parse data from received bytes into this frame object.

Utility functions and classes.

class stompclient.util.FrameBuffer[source]

Bases: object

A customized version of the StompBuffer class from Stomper project that returns frame objects and supports iteration.

This version of the parser also assumes that stomp messages with no content-lengh end in a simple x00 char, not x00n as is assumed by stomper.stompbuffer.StompBuffer. Additionally, this class differs from Stomper version by conforming to PEP-8 coding style.

This class can be used to smooth over a transport that may provide partial frames (or may provide multiple frames in one data buffer).

Variables:
  • buffer – The internal byte buffer.
  • debug – Log extra parsing debug (logs will be DEBUG level).
append(data)[source]

Appends bytes to the internal buffer (may or may not contain full stomp frames).

Parameters:data (str) – The bytes to append.
buffer_empty()[source]
Returns:True if buffer is empty, False otherwise.
Return type:bool
buffer_len()[source]
Returns:Number of bytes in the internal buffer.
Return type:int
clear()[source]

Clears (empties) the internal buffer.

extract_frame()[source]

Pulls one complete frame off the buffer and returns it.

If there is no complete message in the buffer, returns None.

Note that the buffer can contain more than once message. You should therefore call this method in a loop (or use iterator functionality exposed by class) until None returned.

Returns:The next complete frame in the buffer.
Return type:stompclient.frame.Frame
next()[source]

Return the next STOMP message in the buffer (supporting iteration).

Return type:stompclient.frame.Frame
sync_buffer()[source]

Method to detect and correct corruption in the buffer.

Corruption in the buffer is defined as the following conditions both being true:

  1. The buffer contains at least one newline;
  2. The text until the first newline is not a STOMP command.

In this case, we heuristically try to flush bits of the buffer until one of the following conditions becomes true:

  1. the buffer starts with a STOMP command;
  2. the buffer does not contain a newline.
  3. the buffer is empty;

If the buffer is deemed corrupt, the first step is to flush the buffer up to and including the first occurrence of the string ‘’, which is likely to be a frame boundary.

Note that this is not guaranteed to be a frame boundary, as a binary payload could contain the string ‘’. That condition would get handled on the next loop iteration.

If the string ‘’ does not occur, the entire buffer is cleared. An earlier version progressively removed strings until the next newline, but this gets complicated because the body could contain strings that look like STOMP commands.

Note that we do not check “partial” strings to see if they could match a command; that would be too resource-intensive. In other words, a buffer containing the string ‘BUNK’ with no newline is clearly corrupt, but we sit and wait until the buffer contains a newline before attempting to see if it’s a STOMP command.