Changes
+inc/Module/AutoInstall.pm
+inc/Module/Install.pm
+inc/Module/Install/AutoInstall.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Include.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
+lib/Catalyst/Controller/MessageDriven.pm
+lib/Catalyst/Engine/Stomp.pm
Makefile.PL
-MANIFEST
+MANIFEST This list of files
+META.yml
README
+t/00_use.t
t/Catalyst-Engine-Stomp.t
-lib/Catalyst/Engine/Stomp.pm
-lib/Catalyst/Controller/MessageDriven.pm
+testapp/lib/TestApp.pm
testapp/lib/TestApp/Controller/TestController.pm
testapp/lib/TestApp/testapp.yml
-testapp/lib/TestApp.pm
testapp/script/testapp_stomp.pl
-
+testapp/script/testapp_stomp_workers.pl
BEGIN { extends 'Catalyst::Controller' }
+=head1 NAME
+
+Catalyst::Controller::MessageDriven
+
+=head1 SYNOPSIS
+
+ package MyApp::Controller::Queue;
+ use Moose;
+ BEGIN { extends 'Catalyst::Controller::MessageDriven' }
+
+ sub some_action : Local {
+ my ($self, $c) = @_;
+ # Reply with a minimal response message
+ my $response = { type => 'testaction_response' };
+ $c->stash->{response} = $response;
+ }
+
+=head1 DESCRIPTION
+
+A Catalyst controller base class for use with Catalyst::Engine::Stomp,
+which handles YAML-serialized messages. A top-level "type" key in the
+YAML determines the action dispatched to.
+
+=cut
+
__PACKAGE__->config(
'default' => 'text/x-yaml',
'stash_key' => 'response',
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
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
=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
=head2 handle_stomp_frame
-Dispatch according to STOMP frame type.
+Dispatch according to Stomp frame type.
=cut
$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
=head2 handle_stomp_error
-Log any STOMP error frames we receive.
+Log any Stomp error frames we receive.
=cut
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;