AnyEvent-STOMP
view release on metacpan or search on metacpan
lib/AnyEvent/STOMP.pm view on Meta::CPAN
=head1 NAME
AnyEvent::STOMP - A lightweight event-driven STOMP client
=head1 SYNOPSIS
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
});
lib/AnyEvent/STOMP.pm view on Meta::CPAN
=cut
=head1 DESCRIPTION
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.
=head2 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:
=over
=item port
The port number to connect to. If not specified, defaults to 61612 (if SSL/TLS
is used) or 61613 (if not).
=item ssl
If set to a true value, use SSL/TLS to connect.
=item destination
If defined, subscribe to the specified destination (queue) upon connection.
=item ack
Sets the behavior with respect to STOMP frame acknowledgments.
lib/AnyEvent/STOMP.pm view on Meta::CPAN
An anonymous hash of headers (key/value pairs) to send in the STOMP SUBSCRIBE
frame.
=back
=cut
sub connect {
my $class = shift;
my ($host, $port, $ssl, $destination, $ack,
$connect_headers, $subscribe_headers) = @_;
croak 'No host provided' unless $host;
croak "ack value must be 0, undef, 'auto' or 'manual'"
if $ack && $ack ne 'auto' && $ack ne 'manual';
my $self = $class->SUPER::new;
$self->{ack} = $ack;
$port ||= ($ssl ? 61612 : 61613);
my $connect_cb;
$self->{handle} = AnyEvent::Handle->new(
connect => [ $host, $port ],
tls => $ssl ? 'connect' : undef,
keepalive => 1,
on_prepare => sub { $self->event('prepare', @_); },
on_connect => sub {
$self->event('connect', @_);
$self->send_frame('CONNECT', undef, $connect_headers);
if ($destination) {
$subscribe_headers->{destination} = $destination;
$subscribe_headers->{ack} = 'client' if $ack;
$connect_cb = $self->reg_cb(CONNECTED => sub {
$self->{session_id} = $_[2]->{session};
( run in 0.933 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )