You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Kevin Goess <kn...@goess.org> on 2011/09/26 14:42:21 UTC

Net::Stomp and transactions and receive_frame()

I'm in the process of adapting some existing code using Net::Stomp from being
able to handle a single topic to being able to work on multiple topics.  Can
anyone tell me if this approach is even possible?  It's not working now
because where it expects a transaction receipt, it's getting the first
message on another topic.  I'd like to know if I'm just barking up the wrong
tree before I go about trying to fix it.

Here's what the workflow looks like:

# first subscribe to three different queues
for $job (qw/ JOB1 JOB2 JOB3 /){
$stomp->subscribe({
   "ack" => "client",
   "destination" => "/queue/$job"
});

while($stomp->can_read){

   $frame = $stomp->receive_frame();

   # ... receives a message for JOB1
   # and to start a transaction sends a BEGIN frame that looks like this:

    bless({
    command => "BEGIN",
    headers => {
             receipt => "0002",
            transaction => "0001",
       },
    }, "Net::Stomp::Frame")
   
   # Then looks for a receipt on that frame by calling
   $receipt = $stomp->receive_frame()

Unfortunately, where it's expecting a RECEIPT frame, it actually gets a
MESSAGE frame from the JOB2 queue.

My question is, is there any way for that to work, to be both subscribed to
multiple topics and to be able to receive receipts on transactions?  Or is
there a better/more standard way to handle it?

Any tips or suggestions would be most welcome, thanks!



--
View this message in context: http://activemq.2283324.n4.nabble.com/Net-Stomp-and-transactions-and-receive-frame-tp3843640p3843640.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Net::Stomp and transactions and receive_frame()

Posted by Gary Tully <ga...@gmail.com>.
you need to correlate the receipt ids as there is nothing to sync
replys and message dispatch.

Have a peek at http://search.cpan.org/~lcons/Net-STOMP-Client-1.2/lib/Net/STOMP/Client.pm#RECEIPTS

that has some built in receipt management

On 28 September 2011 10:37, Kevin Goess <kn...@goess.org> wrote:
> Here's a complete repro case.  Either it's not supposed to work this way or
> I'm doing something wrong:
>
> use Net::Stomp;
>
> use strict;
>
> my $stomp = Net::Stomp->new( { hostname => 'bpdeb', port => '61612' } );
> $stomp->connect( { login => 'hello', passcode => 'there' } );
>
> # pre-populate the two queues
> $stomp->send( { destination => '/queue/FOO.BAR', body => 'test message' } );
> $stomp->send( { destination => '/queue/FOO.BAR2', body => 'test message' }
> );
>
>
> # now subscribe to them
> $stomp->subscribe({ destination => '/queue/FOO.BAR',
>                   'ack'        => 'client',
>                   'activemq.prefetchSize' => 1
> });
> $stomp->subscribe({ destination => '/queue/FOO.BAR2',
>                   'ack'        => 'client',
>                   'activemq.prefetchSize' => 1
> });
>
> # read one frame, then start a transaction asking for a receipt of the
> # BEGIN message
> while ($stomp->can_read()){
>
>    my $frame = $stomp->receive_frame;
>    print STDERR "got frame ".$frame->as_string()."\n";
>
>
>    print STDERR "sending a BEGIN\n";
>    my($frame) = Net::Stomp::Frame->new({
>        command => 'BEGIN',
>            headers => {
>            transaction => 123,
>            receipt     => 456,
>        },
>    });
>
>    $stomp->send_frame($frame);
>
>    my $expected_receipt = $stomp->receive_frame;
>    print STDERR "expected RECEIPT but got
> ".$expected_receipt->as_string()."\n";
>
>    exit;
> }
>
> This outputs (with the details elided)
>
> got frame MESSAGE
> destination:/queue/FOO.BAR
> ....
>
> sending a BEGIN
>
> expected RECEIPT but got MESSAGE
> destination:/queue/FOO.BAR2
> ....
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Net-Stomp-and-transactions-and-receive-frame-tp3843640p3850526.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
http://fusesource.com
http://blog.garytully.com

Re: Net::Stomp and transactions and receive_frame()

Posted by Kevin Goess <kn...@goess.org>.
Here's a complete repro case.  Either it's not supposed to work this way or
I'm doing something wrong:

use Net::Stomp;

use strict;

my $stomp = Net::Stomp->new( { hostname => 'bpdeb', port => '61612' } );
$stomp->connect( { login => 'hello', passcode => 'there' } );

# pre-populate the two queues
$stomp->send( { destination => '/queue/FOO.BAR', body => 'test message' } );
$stomp->send( { destination => '/queue/FOO.BAR2', body => 'test message' }
);


# now subscribe to them
$stomp->subscribe({ destination => '/queue/FOO.BAR',
                   'ack'        => 'client',
                   'activemq.prefetchSize' => 1
});
$stomp->subscribe({ destination => '/queue/FOO.BAR2',
                   'ack'        => 'client',
                   'activemq.prefetchSize' => 1
});

# read one frame, then start a transaction asking for a receipt of the 
# BEGIN message
while ($stomp->can_read()){

    my $frame = $stomp->receive_frame; 
    print STDERR "got frame ".$frame->as_string()."\n";


    print STDERR "sending a BEGIN\n";
    my($frame) = Net::Stomp::Frame->new({
        command => 'BEGIN',
            headers => {
            transaction => 123,
            receipt     => 456,
        },
    });

    $stomp->send_frame($frame);

    my $expected_receipt = $stomp->receive_frame;
    print STDERR "expected RECEIPT but got
".$expected_receipt->as_string()."\n";

    exit;
}

This outputs (with the details elided)

got frame MESSAGE
destination:/queue/FOO.BAR
....

sending a BEGIN

expected RECEIPT but got MESSAGE
destination:/queue/FOO.BAR2
....


--
View this message in context: http://activemq.2283324.n4.nabble.com/Net-Stomp-and-transactions-and-receive-frame-tp3843640p3850526.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.