AnyEvent-Stomper
view release on metacpan or search on metacpan
- command\_headers
Specifies default headers for particular commands.
command_headers => {
SEND => {
receipt => 'auto',
},
SUBSCRIBE => {
durable => 'true',
ack => 'client',
},
}
- on\_connect => $cb->()
The `on_connect` callback is called when the connection is successfully
established.
Not set by default.
- on\_disconnect => $cb->()
The `on_disconnect` callback is called when the connection is closed by any
reason.
Not set by default.
- on\_error => $cb->( $err )
The `on_error` callback is called when occurred an error, which was affected
on entire client (e. g. connection error or authentication error). Also the
`on_error` callback is called on command errors if the command callback is not
specified. If the `on_error` callback is not specified, the client just print
an error messages to `STDERR`.
# COMMAND METHODS
To execute the STOMP command you must call appropriate method. STOMP headers
can be specified as command parameters. The client automatically adds
`content-length` header to all outgoing frames. Every command method can also
accept two additional parameters: the `body` parameter where you can specify
the body of the frame, and the `on_receipt` parameter that is the alternative
way to specify the command callback.
If you want to receive `RECEIPT` frame, you must specify `receipt` header.
The `receipt` header can take the special value `auto`. If it set, the
receipt identifier will be generated automatically by the client. The
`RECEIPT` frame is passed to the command callback in first argument as the
object of the class [AnyEvent::Stomper::Frame](https://metacpan.org/pod/AnyEvent::Stomper::Frame). If the `receipt` header is
not specified the first argument of the command callback will be `undef`.
For commands `SUBSCRIBE`, `UNSUBSCRIBE`, `DISCONNECT` the client
automatically adds `receipt` header for internal usage.
The command callback is called in one of two cases depending on the presence of
the `receipt` header. First case, when the command was successfully written to
the socket. Second case, when the `RECEIPT` frame will be received. In first
case `on_receipt` callback can be called synchronously. If any error occurred
during the command execution, the error object is passed to the callback in
second argument. Error object is the instance of the class
[AnyEvent::Stomper::Error](https://metacpan.org/pod/AnyEvent::Stomper::Error).
The command callback is optional. If it is not specified and any error
occurred, the `on_error` callback of the client is called.
The full list of all available headers for every command you can find in STOMP
protocol specification and in documentation on your STOMP server. For various
versions of STOMP protocol and various STOMP servers they can be differ.
## send( \[ %params \] \[, $cb->( $receipt, $err ) \] )
Sends a message to a destination in the messaging system.
$stomper->send(
destination => '/queue/foo',
body => 'Hello, world!',
);
$stomper->send(
destination => '/queue/foo',
body => 'Hello, world!',
sub {
my $err = $_[1];
if ( defined $err ) {
my $err_msg = $err->message;
my $err_code = $err->code;
my $err_frame = $err->frame;
# error handling...
return;
}
}
);
$stomper->send(
destination => '/queue/foo',
receipt => 'auto',
body => 'Hello, world!',
on_receipt => sub {
my $receipt = shift;
my $err = shift;
if ( defined $err ) {
my $err_msg = $err->message;
my $err_code = $err->code;
my $err_frame = $err->frame;
# error handling...
return;
}
# receipt handling...
}
( run in 1.478 second using v1.01-cache-2.11-cpan-97f6503c9c8 )