use Net::Stomp;
use Net::Stomp::Frame;

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

my $frame;
my $id = 0;
for (1..20){
    print "subscribe sent\n";
    $stomp->subscribe(
            {   destination             => '/queue/test.queue',
                'receipt'               => $id,
            }
    );
	#we are looking for the receipt
    $frame = $stomp->receive_frame();
    $id++;
    print $frame->as_string();
    $stomp->unsubscribe({   destination => '/queue/test.queue',
                            'receipt'   => $id,
    });
    print "unsubscribe sent\n";
    $frame = $stomp->receive_frame();
    print $frame->as_string();
    $id++;
}

my $count = 300;
for (1..$count){
    $stomp->send(
        {   destination => '/queue/test.queue',
            body => 'test message',
            receipt => $id,
        }
    );
    $id++;
}

$stomp->subscribe( { destination => '/queue/test.queue', });

for my $i (1..$count){
    $frame = $stomp->receive_frame();
    print "Ricevuto messaggio [".$i."]: ".$frame->command."\n";
}
$stomp->disconnect();
