Net::Stomp::Frame - A STOMP Frame


Net-Stomp documentation Contained in the Net-Stomp distribution.

Index


Code Index:

NAME

Top

Net::Stomp::Frame - A STOMP Frame

SYNOPSIS

Top

  use Net::Stomp::Frame;
  my $frame = Net::Stomp::Frame->new( {
    command => $command,
    headers => $headers,
    body    => $body,
  } );
  my $frame  = Net::Stomp::Frame->parse($string);
  my $string = $frame->as_string;

DESCRIPTION

Top

This module encapulates a Stomp frame. Stomp is the Streaming Text Orientated Messaging Protocol (or the Protocol Briefly Known as TTMP and Represented by the symbol :ttmp). It's a simple and easy to implement protocol for working with Message Orientated Middleware from any language. Net::Stomp is useful for talking to Apache ActiveMQ, an open source (Apache 2.0 licensed) Java Message Service 1.1 (JMS) message broker packed with many enterprise features.

A Stomp frame consists of a command, a series of headers and a body.

For details on the protocol see http://stomp.codehaus.org/Protocol.

METHODS

Top

new

Create a new Net::Stomp::Frame object:

  my $frame = Net::Stomp::Frame->new( {
    command => $command,
    headers => $headers,
    body    => $body,
  } );

parse

Create a new Net::Somp::Frame given a string containing the serialised frame:

  my $frame  = Net::Stomp::Frame->parse($string);

as_string

Create a string containing the serialised frame representing the frame:

  my $string = $frame->as_string;

destination

Get or set the destination header.

content_type

Get or set the content-type header.

content_length

Get or set the content-length header.

exchange

Get or set the exchange header.

message_id

Get or set the message-id header.

SEE ALSO

Top

Net::Stomp.

AUTHOR

Top

Leon Brocard <acme@astray.com>.

COPYRIGHT

Top


Net-Stomp documentation Contained in the Net-Stomp distribution.

package Net::Stomp::Frame;
use strict;
use warnings;
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors(qw(command headers body));

BEGIN {
    for my $header (
        qw(destination exchange content-type content-length message-id))
    {
        my $method = $header;
        $method =~ s/-/_/g;
        no strict 'refs';
        *$method = sub {
            my $self = shift;
            $self->headers->{$header} = shift if @_;
            $self->headers->{$header};
        };
    }
}

sub as_string {
    my $self    = shift;
    my $command = $self->command;
    my $headers = $self->headers;
    my $body    = $self->body;
    my $frame   = $command . "\n";

    # insert a content-length header
    my $bytes_message = 0;
    if ( $headers->{bytes_message} ) {
        $bytes_message = 1;
        delete $headers->{bytes_message};
        $headers->{"content-length"} = length( $self->body );
    }

    while ( my ( $key, $value ) = each %{ $headers || {} } ) {
        $frame .= $key . ':' . $value . "\n";
    }
    $frame .= "\n";
    $frame .= $body || '';
    $frame .= "\000";
}

1;

__END__