1 package Catalyst::Controller::MessageDriven;
4 BEGIN { extends 'Catalyst::Controller' }
8 Catalyst::Controller::MessageDriven
12 package MyApp::Controller::Queue;
14 BEGIN { extends 'Catalyst::Controller::MessageDriven' }
16 sub some_action : Local {
18 # Reply with a minimal response message
19 my $response = { type => 'testaction_response' };
20 $c->stash->{response} = $response;
25 A Catalyst controller base class for use with Catalyst::Engine::Stomp,
26 which handles YAML-serialized messages. A top-level "type" key in the
27 YAML determines the action dispatched to.
32 'default' => 'text/x-yaml',
33 'stash_key' => 'response',
34 'map' => { 'text/x-yaml' => 'YAML' },
37 sub begin :ActionClass('Deserialize') { }
39 sub end :ActionClass('Serialize') {
42 # Engine will send our reply based on the value of this header.
43 $c->response->headers->header( 'X-Reply-Address' => $c->req->data->{reply_to} );
45 # Custom error handler - steal errors from catalyst and dump them into
46 # the stash, to get them serialized out as the reply.
47 if (scalar @{$c->error}) {
48 my $error = join "\n", @{$c->error};
49 $c->stash->{response} = { status => 'ERROR', error => $error };
50 $c->error(0); # clear errors, so our response isn't clobbered
54 sub default : Private {
57 # Forward the request to the appropriate action, based on the
59 my $action = $c->req->data->{type};
60 $c->forward($action, [$c->req->data]);
63 __PACKAGE__->meta->make_immutable;
69 Forwards the request to the appropriate action based on the 'type' field
70 within the message data.
74 Uses L<Catalyst::Action::Deserialize> to unserialize the message.
78 Serializes the data stashed by the dispatched action, and
79 arranges for the reply to be sent to the endpoint nominated in
80 the request's 'reply_to' field.
82 Supplies custom exception handling which returns
83 throw exceptions as a serialized return message.