Created
July 3, 2017 18:42
-
-
Save horgh/110b57e63d6ce55c11392b91697eceec to your computer and use it in GitHub Desktop.
Net::AMQP::RabbitMQ test script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Net::AMQP::RabbitMQ (); | |
my $channel = 1; | |
my $exchange_name = 'exchange_name3'; | |
my $routing_key = 'routing_key3'; | |
my $queue_name = 'test_queue3'; | |
my $mq = Net::AMQP::RabbitMQ->new; | |
$mq->connect('localhost', {}); | |
$mq->channel_open($channel); | |
$mq->exchange_declare($channel, $exchange_name, { | |
exchange_type => 'direct', | |
passive => 0, | |
durable => 0, | |
auto_delete => 1, | |
}); | |
$mq->queue_declare($channel, $queue_name, { | |
passive => 0, | |
durable => 0, | |
exclusive => 0, | |
auto_delete => 1, | |
}); | |
$mq->queue_bind($channel, $queue_name, $exchange_name, $routing_key); | |
$mq->publish($channel, $routing_key, 'Hello World', { | |
exchange => $exchange_name, | |
}); | |
$mq->consume($channel, $queue_name, { | |
no_ack => 1, | |
}); | |
my $message = $mq->recv(1000); | |
if ($message) { | |
$mq->ack($channel, $message->{delivery_tag}); | |
} else { | |
print "no message received\n"; | |
} | |
$mq->queue_unbind($channel, $queue_name, $exchange_name, $routing_key); | |
$mq->disconnect; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment