+ added bit more code so when you add additional header key/value pairs for
Jason Tang [Thu, 23 Jul 2009 16:36:02 +0000 (17:36 +0100)]
  subscribing

ie
<Engine::Stomp>
    <subscribe_header>
        transformation  jms-object-json
    </subscribe_header>
</Engine::Stomp>

lib/Catalyst/Engine/Stomp.pm

index 218702e..f2b588f 100644 (file)
@@ -77,6 +77,10 @@ sub run {
 
         # connect up
         my %template = %{$app->config->{'Engine::Stomp'}};
+        my $add_header = delete $template{subscribe_header};
+        if (ref($add_header) ne 'HASH') {
+            $add_header = undef;
+        }
         $self->connection(Net::Stomp->new(\%template));
         $self->connection->connect();
         $self->conn_desc($template{hostname}.':'.$template{port});
@@ -84,10 +88,20 @@ sub run {
         # subscribe, with client ack.
         foreach my $queue (@queues) {
                 my $queue_name = "/queue/$queue";
-                $self->connection->subscribe({
-                                              destination => $queue_name,
-                                              ack         => 'client'
-                                             });
+                my $header_hash = {
+                    destination => $queue_name,
+                    ack         => 'client',
+                };
+
+                # add the additional headers - yes I know it overwrites but
+                # thats the dev's problem?
+                if (keys %{$add_header}) {
+                    foreach my $key (keys %{$add_header}) {
+                        $header_hash->{$key} = $add_header->{$key};
+                    }
+                }
+
+                $self->connection->subscribe($header_hash);
         }
 
         # enter loop...