The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

XAS::Lib::Stomp::POE::Client - A STOMP client for the POE Environment

SYNOPSIS

This module is a class used to create clients that need to access a message server that communicates with the STOMP protocol. Your program could look as follows:

 package Client;

 use POE;
 use XAS::Class
   version => '1.0',
   base    => 'XAS::Lib::Stomp::POE::Client',
 ;

 package main;

 use POE;
 use strict;

 Client->new(
    -alias => 'testing',
    -queue => '/queue/testing',
 );

 $poe_kernel->run();

 exit 0;

DESCRIPTION

This module handles the nitty-gritty details of setting up the communications channel to a message queue server. You will need to sub-class this module with your own for it to be useful.

When messages are received, specific events are generated. Those events are based on the message type. If you are interested in those events you should override the default behavior for those events. The default behavior is to do nothing. This module inherits from XAS::Lib::Net::POE::Client.

METHODS

new

This method initializes the class and starts a session to handle the communications channel. It takes the following additional parameters:

-alias

Sets the alias for this client, defaults to 'stomp-client'.

-host

Sets the host to attach too. defaults to 'localhost'.

-port

Sets the port to use, defaults to 61613.

-login

Sets the login name for this server, defaults to 'guest'.

-passcode

Sets the passcode for this server, defaults to 'guest'.

handle_connection(OBJECT)

This event is signaled and the corresponding method is called upon initial connection to the message server. I accepts these parameters:

OBJECT

The current class object.

handle_connected(OBJECT, ARG0)

This event and corresponding method is called when a "CONNECT" frame is received from the server. It posts the frame to the 'connection_up' event. It accepts these parameters:

OBJECT

The current class object.

ARG0

The current STOMP frame.

handle_message(OBJECT, ARG0)

This event and corresponding method is used to process "MESSAGE" frames.

It accepts these parameters:

OBJECT

The current class object.

ARG0

The current STOMP frame.

 Example

    sub handle_message {
        my ($self, $frame) = @_[OBJECT,ARG0];
 
        my $nframe = $self->stomp->ack(
            -message_id => $frame->header->message_id
        );

        $poe_kernel->yield('write_data', $nframe);

    }

This example really doesn't do much other then "ack" the messages that are received.

handle_receipt(OBJECT, ARG0)

This event and corresponding method is used to process "RECEIPT" frames. It accepts these parameters:

OBJECT

The current class object.

ARG0

The current STOMP frame.

 Example

    sub handle_receipt {
        my ($self, $frame) = @_[OBJECT,ARG0];

        my $receipt = $frame->header->receipt;

    }

This example really doesn't do much, and you really don't need to worry about receipts unless you ask for one when you send a frame to the server. So this method could be safely left with the default.

handle_error(OBJECT, ARG0)

This event and corresponding method is used to process "ERROR" frames. It accepts these parameters:

OBJECT

The current class object.

ARG0

The current STOMP frame.

handle_noop(OBJECT, ARG0)

This event and corresponding method is used to process "NOOP" frames. It accepts these parameters:

OBJECT

The current class object.

ARG0

The current STOMP frame.

ACCESSORS

stomp

This returns an object to the internal XAS::Lib::Stomp::Utils object. This is very useful for creating STOMP frames.

 Example

    $frame = $self->stomp->connect(
         -login    => 'testing',
         -passcode => 'testing'
    );

    $poe_kernel->yield('write_data', $frame);

SEE ALSO

XAS

For details on the protocol see http://stomp.github.io/.

AUTHOR

Kevin L. Esteb, <=[@kesteb.us>

COPYRIGHT AND LICENSE

Copyright (C) 2014 Kevin L. Esteb

This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.