今度提案をする某プロジェクトのためにGearmanやTheSchwartzをみていたら、最終的にはActiveMQを発見。知らんかったわぁ、不勉強。
ちなみに渡したいのバイナリデータなので、こんな感じで
./bin/activemq
# Publisher
use strict;
use Net::Stomp;
use MIME::Base64;
use Storable qw(freeze);
my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '61613' } );
$stomp->connect( { login => 'hello', passcode => 'there' } );
for (1..100_000) {
my $h = encode_base64(freeze({ hoge => $_ }));
$stomp->send( {
destination => '/queue/foo',
body => $h
} );
}
$stomp->disconnect;
# Consumer
use strict;
use Net::Stomp;
use Data::Dump ();
use MIME::Base64;
use Storable qw(thaw);
my $stomp = Net::Stomp->new( {
hostname => 'localhost',
port => '61613'
} );
$stomp->connect( { login => 'hello', passcode => 'there' } );
$stomp->subscribe({
destination => '/queue/foo',
ack => 'client',
'activemq.prefetchSize' => 1
});
while (1) {
my $frame = $stomp->receive_frame;
my $h = thaw(decode_base64( $frame->body ) );
$stomp->ack( { frame => $frame } );
print STDERR Data::Dump::dump($h), "\n";
}
$stomp->disconnect;
メッセージキューみたいなものって今まで何回も書いてきたけど、これは便利でいいな。
ちなみにこれを勉強していたらちょうどCatalystのMLで同じようなトピックやってた。このごろシンクロ率が高い。
コメント