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;