NAME

Catalyst::Controller::JMS - controller base class to simplify usage of Catalyst::ActionRole::JMS

VERSION

version 1.3

SYNOPSIS

package MyApp::Controller::Something;
use Moose;

BEGIN { extends 'Catalyst::Controller::JMS' }

__PACKAGE__->config(
  namespace => 'queue/my_queue',
);

sub my_message_type :MessageTarget {
  my ($self,$c) = @_;

  my $body = $c->req->data;
  my $headers = $c->req->headers;

  # do something

  $c->res->header('X-Reply-Address' => 'temporary-queue-name');
  $c->stash->{message} = { some => [ 'reply', 'message' ] };

  return;
}

DESCRIPTION

This controller base class makes it easy to handle JMS-style messages in your Catalyst application. It handles deserialisation and serialisation transparently (thanks to Catalyst::Action::Deserialize and Catalyst::Action::Serialize) and sets up the attributes needed by Catalyst::ActionRole::JMS. It also sets up some sensible default configuration.

CONFIGURATION

__PACKAGE__->config(
  stash_key => 'message',
  default => 'application/json',
  map => {
    'application/json'   => 'JSON',
    'text/x-json'        => 'JSON',
  },
);

See Catalyst::Action::Deserialize and Catalyst::Action::Serialize for what this means.

ACTIONS

Your actions

If you set the MessageTarget attribute on an action, it will be marked for dispatch based on the JMSType of incoming messages. More precisely:

sub my_message_type :MessageTarget { }

is equivalent to:

sub my_message_type : Does('Catalyst::ActionRole::JMS')
                      JMSType('my_message_type')
 { }

And:

sub my_action :MessageTarget('my_type') { }

is equivalent to:

sub my_action : Does('Catalyst::ActionRole::JMS')
                JMSType('my_type')
 { }

If you want to have a default action to catch requests not matching any other action, you have to declare it as:

sub default :Default { }

otherwise dispatch may not work properly, see http://lists.scsys.co.uk/pipermail/catalyst/2012-March/028261.html for some attempts at an explanation

begin

De-serialises the body of the request into $ctx->req->data. See Catalyst::Action::Deserialize for details.

end

Serialises $ctx->stash->{message} into the response body. See Catalyst::Action::Serialize for details.

NOTE: if $ctx->stash->{message} is not a reference, it will be wrapped in an arrayref. Some Catalyst::Action::Serialize plugins don't like serialising plain scalars.

EXAMPLES

You can find examples of use in the tests, or at https://github.com/dakkar/CatalystX-StompSampleApps

AUTHOR

Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Net-a-porter.com.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.