View on
Michael S. Fischer > AnyEvent-STOMP-0.6 > AnyEvent::STOMP



Annotate this POD


New  1
Open  2
View/Report Bugs
Module Version: 0.6   Source   Latest Release: AnyEvent-STOMP-0.7


AnyEvent::STOMP - A lightweight event-driven STOMP client


 use AnyEvent;
 use AnyEvent::STOMP;

 my $client = AnyEvent::STOMP->connect($host, $port, $ssl, $destination, $ack,
                                       { connect_headers }, 
                                       { subscribe_headers });
 $client->send($command, $headers, $body);

 # Register interest in new messages
 $client->reg_cb(MESSAGE => sub {
     my (undef, $body, $headers) = @_;
     # Do something with the frame

 # Register interest in any frame received.  Use with caution.
 $client->reg_cb(frame => sub {
     my (undef, $type, $body, $headers) = @_;
     # Do something with the frame

 # Start the event loop


AnyEvent::STOMP is a lightweight event-driven STOMP client. It's intended to be run in the context of an event loop driven by AnyEvent.

Making a connection

 my $client = AnyEvent::STOMP->connect($host, $port, $ssl, $destination, $ack,
                                       { connect_headers }, 
                                       { subscribe_headers });

Only the first parameter (the hostname) is required. The remaining optional arguments are:


The port number to connect to. If not specified, defaults to 61612 (if SSL/TLS is used) or 61613 (if not).


If set to a true value, use SSL/TLS to connect.


If defined, subscribe to the specified destination (queue) upon connection.


Sets the behavior with respect to STOMP frame acknowledgments.

If this value is 0 or undef, no acknowledgment is required: the server will consider all sent frames to be delivered, regardless of whether the client has actually received them. (This is the default behavior according to the STOMP protocol.)

If set to auto, the client will automatically acknowledge a frame upon receipt.

If set to manual, the caller must acknowledge frames manually via the ack() method.


An anonymous hash of headers (key/value pairs) to send in the STOMP CONNECT frame.


An anonymous hash of headers (key/value pairs) to send in the STOMP SUBSCRIBE frame.

Sending a message

To send a message, just call send() with the body, the destination (queue) name, and (optionally) any additional headers:

 $client->send($body, $destination, $headers); # headers may be undef

Sending STOMP frames

You can also send arbitrary STOMP frames:

 $client->send_frame($command, $body, $headers); # headers may be undef

See the STOMP protocol documentation for more details on valid commands and headers.


Once you've connected, you can register interest in events, most commonly the receipt of new messages (assuming you've connected as a subscriber).

The typical use is:

 $client->reg_cb($type => $cb->($client, $body, $headers));

In most cases, $type is MESSAGE, but you can also register interest in any other type of frame (RECEIPT, ERROR, etc.). (If you register interest in CONNECTED frames, please do so with a priority of after; see Object::Event for more details.)

The client object (which can usually be ignored), body and headers (as an anonymous hash of key-value pairs) will be passed to your callback.

Other events you can register interest in are:

prepare => $cb->($client, $handle)

Will be fired after a client socket has been allocated. See on_prepare in AnyEvent::Handle for more details.

connect => $cb->($client, $handle, $host, $port, $retry->())

Will be fired when the client has successfully connected to the STOMP server. See on_connect in AnyEvent::Handle for more details.

frame => $cb->($client, $type, $body, $headers)

Will be fired whenever any frame is received.

connect_error => $cb->($client, $errmsg)

Will be fired if the attempt to connect to the STOMP server fails. See on_connect_error in AnyEvent::Handle for more details.

io_error => $cb->($client, $errmsg)

Will be fired if an I/O error occurs. See on_error in AnyEvent::Handle for more details.

Acknowledging frames

You can acknowledge a frame received via the ack() method:

  $client->ack($id, $transaction);

The transaction is optional.


AnyEvent, AnyEvent::Handle, Object::Event, STOMP Protocol


Michael S. Fischer ( wrote the original version and is the current maintainer.


(C) 2010 Yahoo! Inc.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.

syntax highlighting: