| 1 | package Catalyst::Engine::Stomp; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use List::MoreUtils qw/ uniq /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Net::Stomp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use MooseX::Types::Moose qw/Str Int HashRef/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | extends 'Catalyst::Engine::Embeddable'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = '0.17'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | has connection => (is => 'rw', isa => 'Net::Stomp'); | |||||||||||||||||||||||||||
| 15 | 1 | has conn_desc => (is => 'rw', isa => Str); | |||||||||||||||||||||||||||
| 16 | 0 | ▶ | has destination_namespace_map => (is => 'rw', isa => HashRef, default => sub { { } } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | Catalyst::Engine::Stomp - write message handling apps with Catalyst. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # In a server script: | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | BEGIN { | ||||||||||||||||||||||||||||
| 27 | $ENV{CATALYST_ENGINE} = 'Stomp'; | ||||||||||||||||||||||||||||
| 28 | require Catalyst::Engine::Stomp; | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | MyApp->config( | ||||||||||||||||||||||||||||
| 32 | Engine::Stomp' = { | ||||||||||||||||||||||||||||
| 33 | tries_per_server => 3, | ||||||||||||||||||||||||||||
| 34 | 'servers' => [ | ||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 'hostname' => 'localhost', | ||||||||||||||||||||||||||||
| 37 | 'port' => '61613' | ||||||||||||||||||||||||||||
| 38 | connect_headers => { | ||||||||||||||||||||||||||||
| 39 | login => 'myuser', | ||||||||||||||||||||||||||||
| 40 | passcode => 'mypassword', | ||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||
| 44 | 'hostname' => 'stomp.yourmachine.com', | ||||||||||||||||||||||||||||
| 45 | 'port' => '61613' | ||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||
| 47 | ], | ||||||||||||||||||||||||||||
| 48 | utf8 => 1, | ||||||||||||||||||||||||||||
| 49 | subscribe_headers => { | ||||||||||||||||||||||||||||
| 50 | transformation => 'jms-to-json', | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | }, | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | MyApp->run(); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # In a controller, or controller base class: | ||||||||||||||||||||||||||||
| 57 | use base qw/ Catalyst::Controller::MessageDriven /; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # then create actions, which map as message types | ||||||||||||||||||||||||||||
| 60 | sub testaction : Local { | ||||||||||||||||||||||||||||
| 61 | my ($self, $c) = @_; | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # Reply with a minimal response message | ||||||||||||||||||||||||||||
| 64 | my $response = { type => 'testaction_response' }; | ||||||||||||||||||||||||||||
| 65 | $c->stash->{response} = $response; | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Write a Catalyst app connected to a Stomp messagebroker, not HTTP. You | ||||||||||||||||||||||||||||
| 71 | need a controller that understands messaging, as well as this engine. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | This is single-threaded and single process - you need to run multiple | ||||||||||||||||||||||||||||
| 74 | instances of this engine to get concurrency, and configure your broker | ||||||||||||||||||||||||||||
| 75 | to load-balance across multiple consumers of the same queue. | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Controllers are mapped to Stomp queues or topics, and a controller | ||||||||||||||||||||||||||||
| 78 | base class is provided, Catalyst::Controller::MessageDriven, which | ||||||||||||||||||||||||||||
| 79 | implements YAML-serialized messages, mapping a top-level YAML "type" | ||||||||||||||||||||||||||||
| 80 | key to the action. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 QUEUES and TOPICS | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | The controller namespace (either derived from its name, or defined by | ||||||||||||||||||||||||||||
| 85 | its C<action_namespace> attribute) defines what the controller is | ||||||||||||||||||||||||||||
| 86 | subscribed to: | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =over 4 | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =item C<queue/foo> | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | subscribes to the queue called C<foo> | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =item C<topic/foo> | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | subscribes to the topic called C<foo> | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =item C<foo> | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | subscribes to the queue called C<foo> (for simplicity and backward | ||||||||||||||||||||||||||||
| 101 | compatibility) | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =back | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head2 Connction and Subscription Headers | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | You can specify custom headers to send with the C<CONNECT> and | ||||||||||||||||||||||||||||
| 108 | C<SUBSCRIBE> STOMP messages. You can specify them globally: | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | MyApp->config( | ||||||||||||||||||||||||||||
| 111 | Engine::Stomp' = { | ||||||||||||||||||||||||||||
| 112 | 'servers' => [ | ||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||
| 114 | 'hostname' => 'localhost', | ||||||||||||||||||||||||||||
| 115 | 'port' => '61613' | ||||||||||||||||||||||||||||
| 116 | }, | ||||||||||||||||||||||||||||
| 117 | ], | ||||||||||||||||||||||||||||
| 118 | subscribe_headers => { | ||||||||||||||||||||||||||||
| 119 | transformation => 'jms-to-json', | ||||||||||||||||||||||||||||
| 120 | }, | ||||||||||||||||||||||||||||
| 121 | connect_headers => { | ||||||||||||||||||||||||||||
| 122 | login => 'myuser', | ||||||||||||||||||||||||||||
| 123 | passcode => 'mypassword', | ||||||||||||||||||||||||||||
| 124 | }, | ||||||||||||||||||||||||||||
| 125 | }, | ||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | per server: | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | MyApp->config( | ||||||||||||||||||||||||||||
| 131 | Engine::Stomp' = { | ||||||||||||||||||||||||||||
| 132 | 'servers' => [ | ||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||
| 134 | 'hostname' => 'localhost', | ||||||||||||||||||||||||||||
| 135 | 'port' => '61613' | ||||||||||||||||||||||||||||
| 136 | subscribe_headers => { | ||||||||||||||||||||||||||||
| 137 | strange_stuff => 'something', | ||||||||||||||||||||||||||||
| 138 | }, | ||||||||||||||||||||||||||||
| 139 | connect_headers => { | ||||||||||||||||||||||||||||
| 140 | login => 'myuser', | ||||||||||||||||||||||||||||
| 141 | passcode => 'mypassword', | ||||||||||||||||||||||||||||
| 142 | }, | ||||||||||||||||||||||||||||
| 143 | }, | ||||||||||||||||||||||||||||
| 144 | ], | ||||||||||||||||||||||||||||
| 145 | }, | ||||||||||||||||||||||||||||
| 146 | ); | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | or per-controller (subscribe headers only): | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | package MyApp::Controller::Special; | ||||||||||||||||||||||||||||
| 151 | use Moose; | ||||||||||||||||||||||||||||
| 152 | BEGIN { extends 'Catalyst::Controller::MessageDriven' }; | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | has stomp_destination => ( | ||||||||||||||||||||||||||||
| 155 | is => 'ro', | ||||||||||||||||||||||||||||
| 156 | isa => 'Str', | ||||||||||||||||||||||||||||
| 157 | default => '/topic/crowded', | ||||||||||||||||||||||||||||
| 158 | ); | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | has stomp_subscribe_headers => ( | ||||||||||||||||||||||||||||
| 161 | is => 'ro', | ||||||||||||||||||||||||||||
| 162 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 163 | default => sub { +{ | ||||||||||||||||||||||||||||
| 164 | selector => q{custom_header = '1' or JMSType = 'test_foo'}, | ||||||||||||||||||||||||||||
| 165 | } }, | ||||||||||||||||||||||||||||
| 166 | ); | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | This is very useful to set filters / selectors on the subscription. | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | There are a few caveats, mostly summarized by "if you do confusing | ||||||||||||||||||||||||||||
| 171 | things, the program may not work". | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =over 4 | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =item * | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | you can have the C<stomp_destination> and the C<action_namespace> | ||||||||||||||||||||||||||||
| 178 | different in a single controller, but this may become confusing if you | ||||||||||||||||||||||||||||
| 179 | have more than one controller subscribed to the same destination; you | ||||||||||||||||||||||||||||
| 180 | can remove some of the confusion by restricting the kind of messages | ||||||||||||||||||||||||||||
| 181 | that each subscription receives | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =item * | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | if you filter out some messages, don't be surprised if they are never | ||||||||||||||||||||||||||||
| 186 | received by your application | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =item * | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | you can set persistent topic subscriptions, to prevent message loss | ||||||||||||||||||||||||||||
| 191 | during reconnects (the broker will remember your subscription and keep | ||||||||||||||||||||||||||||
| 192 | the messages while you are not connected): | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | MyApp->config( | ||||||||||||||||||||||||||||
| 195 | Engine::Stomp' = { | ||||||||||||||||||||||||||||
| 196 | 'servers' => [ | ||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||
| 198 | 'hostname' => 'localhost', | ||||||||||||||||||||||||||||
| 199 | 'port' => '61613' | ||||||||||||||||||||||||||||
| 200 | }, | ||||||||||||||||||||||||||||
| 201 | ], | ||||||||||||||||||||||||||||
| 202 | connect_headers => { | ||||||||||||||||||||||||||||
| 203 | 'client-id' => 'myapp', | ||||||||||||||||||||||||||||
| 204 | }, | ||||||||||||||||||||||||||||
| 205 | }, | ||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | package MyApp::Controller::Persistent; | ||||||||||||||||||||||||||||
| 209 | use Moose; | ||||||||||||||||||||||||||||
| 210 | BEGIN { extends 'Catalyst::Controller::MessageDriven' }; | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | has stomp_destination => ( | ||||||||||||||||||||||||||||
| 213 | is => 'ro', | ||||||||||||||||||||||||||||
| 214 | isa => 'Str', | ||||||||||||||||||||||||||||
| 215 | default => '/topic/important', | ||||||||||||||||||||||||||||
| 216 | ); | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | has stomp_subscribe_headers => ( | ||||||||||||||||||||||||||||
| 219 | is => 'ro', | ||||||||||||||||||||||||||||
| 220 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 221 | default => sub { +{ | ||||||||||||||||||||||||||||
| 222 | 'activemq.subscriptionName' => 'important-subscription', | ||||||||||||||||||||||||||||
| 223 | } }, | ||||||||||||||||||||||||||||
| 224 | ); | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | According to the ActiveMQ docs, the C<client-id> must be globally | ||||||||||||||||||||||||||||
| 227 | unique, and C<activemq.subscriptionName> must be unique within the | ||||||||||||||||||||||||||||
| 228 | client. Non-ActiveMQ brokers may use different headers to specify the | ||||||||||||||||||||||||||||
| 229 | subscription name. | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | =back | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =head1 FAILOVER | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | You can specify one or more servers in a list for the apps config. | ||||||||||||||||||||||||||||
| 236 | This enables fail over if an error occurs, like the broker or network | ||||||||||||||||||||||||||||
| 237 | connection disappears. | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | It will try to use a server a set number of times, as determined by | ||||||||||||||||||||||||||||
| 240 | tries_per_server in the config before failing on to the next server | ||||||||||||||||||||||||||||
| 241 | in the list. It cycle through each server in turn, going back to the | ||||||||||||||||||||||||||||
| 242 | start of the list if need be. | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =head1 UTF-8 | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | By default STOMP messages are assumed to be in UTF-8. This module can | ||||||||||||||||||||||||||||
| 247 | automatically convert a Perl string into a UTF-8 set of octets to be | ||||||||||||||||||||||||||||
| 248 | sent over the wire instead. This is a Good Thing, especially if you | ||||||||||||||||||||||||||||
| 249 | use the function Load() from the package YAML::XS to un-serialize | ||||||||||||||||||||||||||||
| 250 | it in your client - it assumes it is in UTF-8. | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | If you do want this behaviour, set 'utf8' to '1' in your config. | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | =head1 Simplified configuration | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | Instead of using the complete config layout as shown in the synopsis, | ||||||||||||||||||||||||||||
| 257 | you can | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | =over 4 | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =item * | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | not specify a C<tries_per_server> (defaults to 1) | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =item * | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | specify a single server: | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | server => { hostname => $host, port => $port } | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | =item * | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | use the old-style (pre 0.14) config having C<hostname> and C<port> | ||||||||||||||||||||||||||||
| 274 | directly in the C<Engine::Stomp> block, without a C<server> key in | ||||||||||||||||||||||||||||
| 275 | between. | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | =back | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | =cut | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | =head1 METHODS | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | =head2 _see_ya | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | Set to run when signal USR1 is received. Simply sets the stop flag. | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | =cut | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 1 | my $stop = 0; | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 0 | ▶ | sub _see_ya { | ||||||||||||||||||||||||||
|
Subroutine
_see_ya: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 292 | 0 | $stop = 1; | |||||||||||||||||||||||||||
| 293 | 0 | delete $SIG{'USR1'}; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | =head2 run | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | App entry point. Starts a loop listening for messages. | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | If the stop flag is set (see _see_ya above) then no more requests are processed. | ||||||||||||||||||||||||||||
| 302 | Keep in mind this is a blocking server and it will wait for a STOMP message forever. | ||||||||||||||||||||||||||||
| 303 | Only after handling a request does it check the flag. | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | =cut | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 0 | ▶ | sub _qualify_destination { | ||||||||||||||||||||||||||
|
Subroutine
_qualify_destination: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 308 | 0 | my ($self,$unq_dest) = @_; | |||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 0 | my $q_dest = $unq_dest; | |||||||||||||||||||||||||||
| 311 | 0 | ▶ | if ($unq_dest !~ m{^ /? (?: queue | topic ) / }x) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 0 | $q_dest = "/queue/$unq_dest"; | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | # normalize slashes | ||||||||||||||||||||||||||||
| 316 | 0 | $unq_dest =~ s{^/}{}; | |||||||||||||||||||||||||||
| 317 | 0 | $q_dest =~ s{/+}{/}; | |||||||||||||||||||||||||||
| 318 | 0 | ▶ | $q_dest = "/$q_dest" unless $q_dest =~ m{^/}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 0 | return ($unq_dest,$q_dest); | |||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 0 | ▶ | sub _collect_destinations { | ||||||||||||||||||||||||||
|
Subroutine
_collect_destinations: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 324 | 0 | my ($self,$app) = @_; | |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 0 | my $sub_id=1; | |||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 0 | my @dests; | |||||||||||||||||||||||||||
| 329 | 0 | for my $ctrl_name ($app->controllers) { | |||||||||||||||||||||||||||
| 330 | 0 | my $ctrl = $app->controller($ctrl_name); | |||||||||||||||||||||||||||
| 331 | 0 | my $dest_call = $ctrl->can('stomp_destination'); | |||||||||||||||||||||||||||
| 332 | 0 | my $subh_call = $ctrl->can('stomp_subscribe_headers'); | |||||||||||||||||||||||||||
| 333 | 0 | my ($unq_dest,$q_dest,$subh); | |||||||||||||||||||||||||||
| 334 | 0 | ▶ | $unq_dest = $dest_call ? $ctrl->$dest_call() : $ctrl->action_namespace(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | 0 | ($unq_dest,$q_dest) = $self->_qualify_destination($unq_dest); | |||||||||||||||||||||||||||
| 336 | 0 | ▶ | $subh = $subh_call ? $ctrl->$subh_call() : { }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 0 | push @dests,{ | |||||||||||||||||||||||||||
| 339 | destination => $q_dest, | ||||||||||||||||||||||||||||
| 340 | subscribe_headers => { | ||||||||||||||||||||||||||||
| 341 | %$subh, | ||||||||||||||||||||||||||||
| 342 | id => $sub_id, | ||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | }; | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | $self->destination_namespace_map->{$q_dest} = | ||||||||||||||||||||||||||||
| 347 | 0 | $self->destination_namespace_map->{"/subscription/$sub_id"} = | |||||||||||||||||||||||||||
| 348 | $ctrl->action_namespace(); | ||||||||||||||||||||||||||||
| 349 | 0 | ++$sub_id; | |||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | return @dests; | |||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=25 SCAR=64.8
Pod
documented
| |||||||||||||||||||||||||||||
| 356 | 0 | my ($self, $app, $oneshot) = @_; | |||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 0 | $SIG{'USR1'} = \&_see_ya; | |||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | die 'No Engine::Stomp configuration found' | ||||||||||||||||||||||||||||
| 361 | 0 | ▶ | unless ref $app->config->{'Engine::Stomp'} eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | my @destinations = $self->_collect_destinations($app); | |||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | # connect up | ||||||||||||||||||||||||||||
| 366 | 0 | my $config = $app->config->{'Engine::Stomp'}; | |||||||||||||||||||||||||||
| 367 | 0 | my $index = 0; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | # munge the configuration to make it easier to write | ||||||||||||||||||||||||||||
| 370 | 0 | ▶ | $config->{tries_per_server} ||= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"tries_per_server"} ||= 1
MC/DC0%0/1
$config->{"tries_per_server"} ||= 1
$config->{"tries_per_server"}
Truth table0%0/2
A
A= $config->{"tries_per_server"}
| |||||||||||||||||||||||||||||
| 371 | 0 | ▶ | $config->{connect_retry_delay} ||= 15; | ||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"connect_retry_delay"} ||= 15
MC/DC0%0/1
$config->{"connect_retry_delay"} ||= 15
$config->{"connect_retry_delay"}
Truth table0%0/2
A
A= $config->{"connect_retry_delay"}
| |||||||||||||||||||||||||||||
| 372 | 0 | for my $h (qw(connect subscribe)) { | |||||||||||||||||||||||||||
| 373 | 0 | ▶ | $config->{"${h}_headers"} ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$$config{"${h}_headers"} ||= {}
MC/DC0%0/1
$$config{"${h}_headers"} ||= {}
$$config{"${h}_headers"}
Truth table0%0/2
A
A= $$config{"${h}_headers"}
| |||||||||||||||||||||||||||||
| 374 | die("${h}_headers config for Engine::Stomp must be a hashref!\n") | ||||||||||||||||||||||||||||
| 375 | 0 | ▶ | if (ref($config->{"${h}_headers"}) ne 'HASH'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 0 | ▶ | if (! $config->{servers} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 379 | $config->{servers} = [ { | ||||||||||||||||||||||||||||
| 380 | hostname => (delete $config->{hostname}), | ||||||||||||||||||||||||||||
| 381 | 0 | port => (delete $config->{port}), | |||||||||||||||||||||||||||
| 382 | } ]; | ||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | elsif (ref $config->{servers} eq 'HASH') { | ||||||||||||||||||||||||||||
| 385 | 0 | $config->{servers} = [ $config->{servers} ]; | |||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | QUITLOOP: | ||||||||||||||||||||||||||||
| 389 | 0 | while (1) { | |||||||||||||||||||||||||||
| 390 | # Go to next server in list | ||||||||||||||||||||||||||||
| 391 | 0 | my %template = %{ $config->{servers}->[$index] }; | |||||||||||||||||||||||||||
| 392 | 0 | $config->{hostname} = $template{hostname}; | |||||||||||||||||||||||||||
| 393 | 0 | $config->{port} = $template{port}; | |||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 0 | ++$index; | |||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ($index >= (scalar( @{$config->{servers}} ))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 398 | 0 | $index = 0; # go back to first server in list | |||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 0 | my $tries = 0; | |||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 0 | ▶ | while ($tries < $config->{tries_per_server}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | 0 | ++$tries; | |||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 0 | eval { | |||||||||||||||||||||||||||
| 407 | 0 | for my $h (qw(connect subscribe)) { | |||||||||||||||||||||||||||
| 408 | 0 | ▶ | $template{"${h}_headers"} ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$template{"${h}_headers"} ||= {}
MC/DC0%0/1
$template{"${h}_headers"} ||= {}
$template{"${h}_headers"}
Truth table0%0/2
A
A= $template{"${h}_headers"}
| |||||||||||||||||||||||||||||
| 409 | die("${h}_headers config for for server $config->{hostname}:$config->{port} in Engine::Stomp must be a hashref!\n") | ||||||||||||||||||||||||||||
| 410 | 0 | ▶ | if (ref($template{"${h}_headers"}) ne 'HASH'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | my $per_server_connect_headers = { | ||||||||||||||||||||||||||||
| 414 | 0 | %{$config->{connect_headers}}, | |||||||||||||||||||||||||||
| 415 | 0 | %{$template{connect_headers}}, | |||||||||||||||||||||||||||
| 416 | }; | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | my $per_server_subscribe_headers = { | ||||||||||||||||||||||||||||
| 419 | 0 | %{$config->{subscribe_headers}}, | |||||||||||||||||||||||||||
| 420 | 0 | %{$template{subscribe_headers}}, | |||||||||||||||||||||||||||
| 421 | }; | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | $app->log->debug("Connecting to STOMP Q at " . $template{hostname}.':'.$template{port}) | ||||||||||||||||||||||||||||
| 424 | 0 | ▶ | if $app->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 0 | $self->connection(Net::Stomp->new(\%template)); | |||||||||||||||||||||||||||
| 427 | 0 | $self->connection->connect($per_server_connect_headers); | |||||||||||||||||||||||||||
| 428 | 0 | $self->conn_desc($template{hostname}.':'.$template{port}); | |||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | # subscribe, with client ack. | ||||||||||||||||||||||||||||
| 431 | 0 | foreach my $destination (@destinations) { | |||||||||||||||||||||||||||
| 432 | 0 | my $dest_name = $destination->{destination}; | |||||||||||||||||||||||||||
| 433 | my $local_subscribe_headers = | ||||||||||||||||||||||||||||
| 434 | 0 | $destination->{subscribe_headers}; | |||||||||||||||||||||||||||
| 435 | 0 | my $id = $local_subscribe_headers->{id}; | |||||||||||||||||||||||||||
| 436 | $app->log->debug( | ||||||||||||||||||||||||||||
| 437 | "subscribing to $dest_name ($id) ". | ||||||||||||||||||||||||||||
| 438 | 'which is mapped to '. | ||||||||||||||||||||||||||||
| 439 | 0 | ▶ | $self->destination_namespace_map->{"/subscription/$id"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | ) | ||||||||||||||||||||||||||||
| 441 | if $app->debug; | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 0 | $self->connection->subscribe({ | |||||||||||||||||||||||||||
| 444 | %$per_server_subscribe_headers, | ||||||||||||||||||||||||||||
| 445 | %$local_subscribe_headers, | ||||||||||||||||||||||||||||
| 446 | destination => $dest_name, | ||||||||||||||||||||||||||||
| 447 | ack => 'client', | ||||||||||||||||||||||||||||
| 448 | }); | ||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | # Since we might block for some time, lets flush the log messages | ||||||||||||||||||||||||||||
| 452 | 0 | ▶ | $app->log->_flush() if $app->log->can('_flush'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | # enter loop... | ||||||||||||||||||||||||||||
| 455 | 0 | while (1) { | |||||||||||||||||||||||||||
| 456 | 0 | my $frame = $self->connection->receive_frame(); # block | |||||||||||||||||||||||||||
| 457 | 0 | $self->handle_stomp_frame($app, $frame); | |||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | 0 | ▶ | if ( $ENV{ENGINE_ONESHOT} || $stop ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ENV{"ENGINE_ONESHOT"} or $stop
MC/DC0%0/2
$ENV{"ENGINE_ONESHOT"} or $stop
$ENV{"ENGINE_ONESHOT"}
$stop
Truth table0%0/3
A or B
A= $ENV{"ENGINE_ONESHOT"}B= $stop
| |||||||||||||||||||||||||||||
| 460 | # Perl does not like 'last QUITLOOP' inside an eval, hence we die and do it | ||||||||||||||||||||||||||||
| 461 | 0 | die "QUITLOOP\n"; | |||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||
| 464 | }; | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 0 | ▶ | if (my $err=$@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | # although it looks like a lot of pointless flush()ing we need | ||||||||||||||||||||||||||||
| 468 | # to make sure the user(s) can see any new messages; we | ||||||||||||||||||||||||||||
| 469 | # sometimes die before we flush() in the loop above | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 0 | ▶ | if ($err eq "QUITLOOP\n") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 472 | 0 | last QUITLOOP; | |||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||
| 474 | else { | ||||||||||||||||||||||||||||
| 475 | 0 | $app->log->error(" Problem dealing with STOMP : $err"); | |||||||||||||||||||||||||||
| 476 | 0 | ▶ | $app->log->_flush() if $app->log->can('_flush'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | # don't loop continuously if we can't connect; take a break; | ||||||||||||||||||||||||||||
| 480 | # give the service a chance to come back | ||||||||||||||||||||||||||||
| 481 | 0 | ▶ | if ($err =~ m{Connection refused}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 482 | $app->log->info( | ||||||||||||||||||||||||||||
| 483 | 'Unable to connect to ' | ||||||||||||||||||||||||||||
| 484 | . $template{hostname}.':'.$template{port} | ||||||||||||||||||||||||||||
| 485 | 0 | . '; sleeping before next retry' | |||||||||||||||||||||||||||
| 486 | ); | ||||||||||||||||||||||||||||
| 487 | 0 | ▶ | $app->log->_flush() if $app->log->can('_flush'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 488 | 0 | sleep $config->{connect_retry_delay}; | |||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | =head2 prepare_request | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | Overridden to add the source broker to the request, in place of the | ||||||||||||||||||||||||||||
| 498 | client IP address. | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | =cut | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | 0 | ▶ | sub prepare_request { | ||||||||||||||||||||||||||
|
Subroutine
prepare_request: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 503 | 0 | my ($self, $c, $req, $res_ref) = @_; | |||||||||||||||||||||||||||
| 504 | 0 | shift @_; | |||||||||||||||||||||||||||
| 505 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||
| 506 | 0 | $c->req->address($self->conn_desc); | |||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | =head2 finalize_headers | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | Overridden to dump out any errors encountered, since you won't get a #' | ||||||||||||||||||||||||||||
| 512 | "debugging" message as for HTTP. | ||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | =cut | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | 0 | ▶ | sub finalize_headers { | ||||||||||||||||||||||||||
|
Subroutine
finalize_headers: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 517 | 0 | my ($self, $c) = @_; | |||||||||||||||||||||||||||
| 518 | 0 | my $error = join "\n", @{$c->error}; | |||||||||||||||||||||||||||
| 519 | 0 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 520 | 0 | $c->log->debug($error); | |||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||
| 522 | 0 | return $self->next::method($c); | |||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | =head2 handle_stomp_frame | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | Dispatch according to Stomp frame type. | ||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | =cut | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | 0 | ▶ | sub handle_stomp_frame { | ||||||||||||||||||||||||||
|
Subroutine
handle_stomp_frame: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 532 | 0 | my ($self, $app, $frame) = @_; | |||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | 0 | my $command = $frame->command(); | |||||||||||||||||||||||||||
| 535 | 0 | ▶ | if ($command eq 'MESSAGE') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 536 | 0 | $self->handle_stomp_message($app, $frame); | |||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||
| 538 | elsif ($command eq 'ERROR') { | ||||||||||||||||||||||||||||
| 539 | 0 | $self->handle_stomp_error($app, $frame); | |||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||
| 541 | else { | ||||||||||||||||||||||||||||
| 542 | 0 | $app->log->debug("Got unknown Stomp command: $command"); | |||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | =head2 handle_stomp_message | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | Dispatch a Stomp message into the Catalyst app. | ||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | =cut | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | 0 | ▶ | sub handle_stomp_message { | ||||||||||||||||||||||||||
|
Subroutine
handle_stomp_message: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 553 | 0 | my ($self, $app, $frame) = @_; | |||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | # destination -> controller | ||||||||||||||||||||||||||||
| 556 | 0 | my $destination = $frame->headers->{destination}; | |||||||||||||||||||||||||||
| 557 | 0 | my $subscription = $frame->headers->{subscription}; | |||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | 0 | ▶ | $app->log->debug("message from $destination ($subscription)") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 560 | if $app->debug; | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | my $controller = $self->destination_namespace_map->{"/subscription/$subscription"} | ||||||||||||||||||||||||||||
| 563 | 0 | ▶ | || $self->destination_namespace_map->{$destination}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->destination_namespace_map->{"/subscription/$subscription"} || $self->destination_namespace_map->{$destination}
MC/DC0%0/2
$self->destination_namespace_map->{"/subscription/$subscription"} || $self->destination_namespace_map->{$destination}
$self->destination_namespace_map->{"/subscription/$subscription"}
$self->destination_namespace_map->{$destination}
Truth table0%0/3
A || B
A= $self->destination_namespace_map->{"/subscription/$subscription"}B= $self->destination_namespace_map->{$destination}
| |||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | # set up request | ||||||||||||||||||||||||||||
| 566 | 0 | my $config = $app->config->{'Engine::Stomp'}; | |||||||||||||||||||||||||||
| 567 | 0 | my $url = 'stomp://'.$config->{hostname}.':'.$config->{port}.'/'.$controller; | |||||||||||||||||||||||||||
| 568 | 0 | my $request_headers = HTTP::Headers->new(%{$frame->headers}); | |||||||||||||||||||||||||||
| 569 | 0 | my $req = HTTP::Request->new(POST => $url, $request_headers); | |||||||||||||||||||||||||||
| 570 | 0 | $req->content($frame->body); | |||||||||||||||||||||||||||
| 571 | 0 | $req->content_length(length $frame->body); | |||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | # dispatch | ||||||||||||||||||||||||||||
| 574 | 0 | my $response; | |||||||||||||||||||||||||||
| 575 | 0 | $app->handle_request($req, \$response); | |||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | # reply, if header set | ||||||||||||||||||||||||||||
| 578 | 0 | ▶ | if (my $reply_to = $response->headers->header('X-Reply-Address')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 579 | 0 | my $reply_queue = '/remote-temp-queue/' . $reply_to; | |||||||||||||||||||||||||||
| 580 | 0 | my $content = $response->content; | |||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | 0 | ▶ | if ($config->{utf8}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 583 | 0 | $content = encode("utf8", $response->content); # create octets | |||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | 0 | my $reply_headers = $response->headers->clone; | |||||||||||||||||||||||||||
| 587 | 0 | $reply_headers->remove_content_headers; | |||||||||||||||||||||||||||
| 588 | my %reply_hh = | ||||||||||||||||||||||||||||
| 589 | map { | ||||||||||||||||||||||||||||
| 590 | 0 | lc($_), scalar($reply_headers->header($_)), | |||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||
| 592 | 0 | grep { !/^X-/i } | |||||||||||||||||||||||||||
| 593 | $reply_headers->header_field_names(); | ||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | 0 | $self->connection->send({ | |||||||||||||||||||||||||||
| 596 | %reply_hh, | ||||||||||||||||||||||||||||
| 597 | destination => $reply_queue, | ||||||||||||||||||||||||||||
| 598 | body => $content | ||||||||||||||||||||||||||||
| 599 | }); | ||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | # ack the message off the destination now we've replied / processed | ||||||||||||||||||||||||||||
| 603 | 0 | $self->connection->ack( { frame => $frame } ); | |||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | =head2 handle_stomp_error | ||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | Log any Stomp error frames we receive. | ||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||
| 610 | =cut | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | 0 | ▶ | sub handle_stomp_error { | ||||||||||||||||||||||||||
|
Subroutine
handle_stomp_error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 613 | 0 | my ($self, $app, $frame) = @_; | |||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | 0 | my $error = $frame->headers->{message}; | |||||||||||||||||||||||||||
| 616 | 0 | $app->log->debug("Got Stomp error: $error"); | |||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | =head2 subscribe_header | ||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | Add additional header key/value pairs to the subscribe message sent to the | ||||||||||||||||||||||||||||
| 626 | message broker. | ||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | =cut | ||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | =head1 DEVELOPMENT | ||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | The source to Catalyst::Engine::Stomp is in github: | ||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||
| 634 | http://github.com/pmooney/catalyst-engine-stomp | ||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | Chris Andrews C<< <chris@nodnol.org> >> | ||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||
| 640 | =head1 CONTRIBUTORS | ||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||
| 642 | Tomas Doran (t0m) C<< <bobtfish@bobtfish.net> >> | ||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||
| 644 | Jason Tang | ||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||
| 646 | Paul Mooney | ||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | =head1 LICENCE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | Copyright (C) 2009 Venda Ltd | ||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||
| 652 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 653 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||||||||||||||||||||||||||||
| 654 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | =cut | ||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||