Skip to content

Commit d4c9576

Browse files
author
oylenshpeegul
committed
add worker
1 parent 339f1b4 commit d4c9576

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

new_task.pl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use warnings;
55
use Net::AMQP::RabbitMQ;
66

7+
my $message = shift // 'Hello, World!';
8+
79
my $mq = Net::AMQP::RabbitMQ->new;
810

911
$mq->connect('localhost', { user => 'guest', password => 'guest' });
@@ -12,8 +14,8 @@
1214

1315
$mq->queue_declare(1, 'hello');
1416

15-
$mq->publish(1, 'hello', 'Hello, World!');
17+
$mq->publish(1, 'hello', $message);
1618

17-
say " [x] Sent 'Hello World!' ";
19+
say " [x] Sent '$message' ";
1820

1921
$mq->disconnect;

worker.pl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env perl
2+
3+
use v5.24;
4+
use warnings;
5+
use Net::AMQP::RabbitMQ;
6+
7+
my $mq = Net::AMQP::RabbitMQ->new();
8+
9+
$mq->connect('localhost', { user => 'guest', password => 'guest' });
10+
11+
$mq->channel_open(1);
12+
13+
$mq->queue_declare(1, 'hello');
14+
15+
$mq->consume(1, 'hello');
16+
17+
say ' [*] Waiting for messages. To exit press CTRL-C';
18+
while (1) {
19+
my $received = $mq->recv(0);
20+
say " [x] Received '$received->{body}'";
21+
}

0 commit comments

Comments
 (0)