activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roger Hoover <roger.hoo...@gmail.com>
Subject Queue message order
Date Tue, 28 Apr 2009 22:15:25 GMT
Hi,

Are queued messages supposed to be delivered in order?  I have a simple
STOMP Perl script below that shows messages delivered out of order.  I've
run it against AMQ 4.1.1 and 5.2.0 in with both persistent and
non-persistent messages.  Note from the message ids and timestamps that the
newer message is delivered first.

Is there a way to force message delivery order? I don't think selectors
allow for ordering, right? Our application doesn't particularly depend on
message order but this behavior is causing my unit tests to fail every third
time they are run.  :(

This also seems problematic for STOMP clients using "client" ack mode.
Since newer messages are delivered first, ack'ing the newer message will
implicitly ack the older message which has not even been delivered yet.

Any help is appreciated.  Thanks,

Roger

$ perl out-of-order.pl
OUT OF ORDER!!!
Frame 1: $VAR1 = bless( {
                 'body' => 'test2',
                 'headers' => {
                                'priority' => '0',
                                'timestamp' => '1240956094252',
                                'destination' => '/queue/testOutOfOrder',
                                'message-id' =>
'ID:thedude.local-58168-1240956067250-3:3897:-1:1:2',
                                'expires' => '0'
                              },
                 'command' => 'MESSAGE'
               }, 'Net::Stomp::Frame' );
Frame 2: $VAR1 = bless( {
                 'body' => 'test1',
                 'headers' => {
                                'priority' => '0',
                                'timestamp' => '1240956094247',
                                'destination' => '/queue/testOutOfOrder',
                                'message-id' =>
'ID:thedude.local-58168-1240956067250-3:3897:-1:1:1',
                                'expires' => '0'
                              },
                 'command' => 'MESSAGE'
               }, 'Net::Stomp::Frame' );

#!/usr/bin/env perl

use strict;
use Net::Stomp;
use Data::Dumper;

my $stomp = Net::Stomp->new( { 'hostname' => 'localhost', 'port' => '61613'
} );
$stomp->connect( { 'login' => 'hello', 'passcode' => 'there' } );
$stomp->subscribe(
  {   'destination'             => '/queue/testOutOfOrder',
      'ack'                   => 'client',
      'activemq.prefetchSize' => 1
  }
);
while ($stomp->can_read({'timeout' => 1})) {
    my $frame = $stomp->receive_frame();
    $stomp->ack({'frame' => $frame});
}
$stomp->disconnect();

while (1) {
    doit();
}

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

    $stomp->send({ 'destination' => '/queue/testOutOfOrder', 'body' =>
'test1', 'persistent' => 'true'} );
    $stomp->send({ 'destination' => '/queue/testOutOfOrder', 'body' =>
'test2', 'persistent' => 'true'} );
    $stomp->disconnect();

    my $stomp = Net::Stomp->new( { 'hostname' => 'localhost', 'port' =>
'61613' } );
    $stomp->connect( { 'login' => 'hello', 'passcode' => 'there' } );
    $stomp->subscribe(
      {   'destination'             => '/queue/testOutOfOrder',
          'ack'                   => 'client',
          'activemq.prefetchSize' => 1
      }
    );
    my $frame1 = $stomp->receive_frame();
    $stomp->ack({'frame' => $frame1});
    my $frame2 = $stomp->receive_frame();
    $stomp->ack({'frame' => $frame2});
    $stomp->disconnect();

    if ($frame1->{'body'} ne 'test1') {
        print "OUT OF ORDER!!!\n";
        print "Frame 1: " . Dumper($frame1);
        print "Frame 2: " . Dumper($frame2);
    }
}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message