stomp
index
/home/bsmith/Dev/python/stomp/stomp/stomp.py

 
Modules
       
socket

 
Classes
       
Stomp

 
class Stomp
    Dead simple Python STOMP client library
 
This is useful for connecting to and communicating with
Apache ActiveMQ, an open source Java Message Service (JMS)
message broker.
 
The majority of the methods available take a single argument; a dictionary.
This dictionary should contain the necessary bits you need
to pass to the STOMP server.  It is outlined in each method
exactly what it needs to work.
 
For specifics on the protocol, see: http://stomp.codehaus.org/Protocol
 
This library is basically a Python implementation of Perl's Net::Stomp
See: http://search.cpan.org/dist/Net-Stomp/lib/Net/Stomp.pm
 
To enable the ActiveMQ Broker for Stomp add the following to the activemq.xml configuration:
 
<connector>
    <serverTransport uri="stomp://localhost:61613"/>
</connector>
 
  Methods defined here:
__init__(self, hostname, port)
Initialize Stomp object
Also accepts arguments needed to build the TCP connection.
 
>>> from stomp import Stomp
>>> stomp = Stomp('hostname', 61613)
abort(self, 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.abort({'transaction':'<randomish_hash_like_thing>'})
ack(self, frame)
Acknowledge receipt of a message
 
Accepts a frame as an argument and it is *required*.
 
Given that you are already subscribed to a destination
and that the destination has messages for consumption
 
>>> while True:
...     frame = stomp.receive_frame()
...     stomp.ack(frame)
begin(self, 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.begin({'transaction':'<randomish_hash_like_thing>'})
commit(self, 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.commit({'transaction':'<randomish_hash_like_thing>'})
connect(self, conf=None)
Connect to STOMP server
This method does not require any arguments.
 
>>> stomp.connect()
disconnect(self, conf=None)
Disconnect from STOMP server
This method does not require any arguments.
 
>>> stomp.disconnect()
receive_frame(self)
Get a frame from the STOMP server
 
Takes no arguments
 
Given that you are already subscribed to a destination
and that the destination has messages for consumption
 
>>> while True:
...     frame = stomp.receive_frame()
...     print frame.headers['message-id']
...     stomp.ack(frame)
send(self, 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'})
send_frame(self, frame)
Send frame to the STOMP server
 
Takes a frame object as argument
 
You could build your own frame and bypass all that 
this library provides, if you wish
 
>>> from stomp import Stomp, Frame
>>> stomp = Stomp('localhost',61613)
>>> frameobj = Frame()
>>> frame = frameobj.build_frame({'command':'DISCONNECT','headers':{}})
>>> stomp.send_frame(frame)
subscribe(self, 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'})
unsubscribe(self, 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'})