#!/usr/bin/perl use strict; use warnings; use Net::STOMP::Client qw(); use constant HOST => "localhost"; use constant PORT => 6163; use constant DESTINATION => "/queue/test"; use constant USER => "guest"; use constant PASSWORD => "guest"; # uncomment the next line to see more... #$Net::STOMP::Client::Debug::Flags = -1; sub stomp () { my($stomp); $stomp = Net::STOMP::Client->new(host => HOST, port => PORT); $stomp->connect(login => USER, passcode => PASSWORD, host => "/"); return($stomp); } sub test () { my($prod, $cons, $frame, $count); # connect $prod = stomp(); # send test messages $prod->send( destination => DESTINATION, body => "Hello ancient world (30s)", expiration => 30000, ); $prod->send( destination => DESTINATION, body => "Hello ancient world (3s)", expiration => 3000, ); # disconnect $prod->disconnect(receipt => $prod->uuid()); # sleep a bit sleep(5); # connect $cons = stomp(); # subscribe $cons->message_callback(sub { return(1) }); $cons->subscribe( destination => DESTINATION, id => $cons->uuid(), receipt => $cons->uuid(), ); $cons->wait_for_receipts(timeout => 3); die("no receipts received!") if $cons->receipts(); # wait for messages $count = 0; while (1) { $frame = $cons->wait_for_frames(timeout => 3); last unless $frame; $count++; } printf("received %d: %s\n", $count, $count == 1 ? "OK" : "BAD"); # disconnect $cons->disconnect(); } test();