X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FStomp.pm;h=4391d9a4e6a7975656b27e72b3c1633d601db3e8;hb=d78bb7396376e6aa61c92a51420554476122d1f3;hp=e6580f6a4dd6e57bc3b27d4ad05638181d1d12a5;hpb=a6b86b3548d5760e16a5d5131024ca093cda1a62;p=catagits%2FCatalyst-Engine-STOMP.git diff --git a/lib/Catalyst/Engine/Stomp.pm b/lib/Catalyst/Engine/Stomp.pm index e6580f6..4391d9a 100644 --- a/lib/Catalyst/Engine/Stomp.pm +++ b/lib/Catalyst/Engine/Stomp.pm @@ -32,30 +32,25 @@ Catalyst::Engine::Stomp - write message handling apps with Catalyst. MyApp->run(); # In a controller, or controller base class: + use base qw/ Catalyst::Controller::MessageDriven /; - use YAML; + # then create actions, which map as message types + sub testaction : Local { + my ($self, $c) = @_; - # configure YAML deserialization; requires Catalyst::Action::REST + # Reply with a minimal response message + my $response = { type => 'testaction_response' }; + $c->stash->{response} = $response; + } + + # The default serialization is YAML, but this configuration + # may be overridden in your controller: __PACKAGE__->config( 'default' => 'text/x-yaml', 'stash_key' => 'rest', 'map' => { 'text/x-yaml' => 'YAML' }, ); - sub begin :ActionClass('Deserialize') { } - - # have a default action, which forwards to the correct action - # based on the message contents (the type). - sub default : Private { - my ($self, $c) = @_; - - my $action = $c->req->data->{type}; - $c->forward($action); - } - - # Send messages back: - $c->engine->send_message($queue, Dump($msg)); - =head1 DESCRIPTION Write a Catalyst app connected to a Stomp messagebroker, not HTTP. You @@ -65,6 +60,11 @@ This is single-threaded and single process - you need to run multiple instances of this engine to get concurrency, and configure your broker to load-balance across multiple consumers of the same queue. +Controllers are mapped to Stomp queues, and a controller base class is +provided, Catalyst::Controller::MessageDriven, which implements +YAML-serialized messages, mapping a top-level YAML "type" key to +the action. + =head1 METHODS =head2 run @@ -133,7 +133,8 @@ sub prepare_request { =head2 finalize_headers -Overridden to dump out any errors encountered. +Overridden to dump out any errors encountered, since you won't get a +"debugging" message as for HTTP. =cut @@ -148,7 +149,7 @@ sub finalize_headers { =head2 handle_stomp_frame -Dispatch according to STOMP frame type. +Dispatch according to Stomp frame type. =cut @@ -163,13 +164,13 @@ sub handle_stomp_frame { $self->handle_stomp_error($app, $frame); } else { - $app->log->debug("Got unknown STOMP command: $command"); + $app->log->debug("Got unknown Stomp command: $command"); } } =head2 handle_stomp_message -Dispatch a STOMP message into the Catalyst app. +Dispatch a Stomp message into the Catalyst app. =cut @@ -201,7 +202,7 @@ sub handle_stomp_message { =head2 handle_stomp_error -Log any STOMP error frames we receive. +Log any Stomp error frames we receive. =cut @@ -209,8 +210,10 @@ sub handle_stomp_error { my ($self, $app, $frame) = @_; my $error = $frame->headers->{message}; - $app->log->debug("Got STOMP error: $error"); + $app->log->debug("Got Stomp error: $error"); } +__PACKAGE__->meta->make_immutable; + 1;