forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
receive_logs.php
42 lines (30 loc) · 964 Bytes
/
receive_logs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
// composer require enqueue/amqp-bunny
require_once __DIR__.'/vendor/autoload.php';
use Enqueue\AmqpBunny\AmqpConnectionFactory;
use Interop\Amqp\AmqpConsumer;
use Interop\Amqp\AmqpTopic;
use Interop\Amqp\Impl\AmqpBind;
$config = [
'host' => 'localhost',
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
'receive_method' => 'basic_consume',
];
$connection = new AmqpConnectionFactory($config);
$context = $connection->createContext();
$topic = $context->createTopic('logs');
$topic->setType(AmqpTopic::TYPE_FANOUT);
$context->declareTopic($topic);
$queue = $context->createTemporaryQueue();
$context->bind(new AmqpBind($topic, $queue));
$consumer = $context->createConsumer($queue);
$consumer->addFlag(AmqpConsumer::FLAG_NOACK);
echo ' [*] Waiting for logs. To exit press CTRL+C', "\n";
while (true) {
if ($message = $consumer->receive()) {
echo ' [x] ', $message->getBody(), "\n";
}
}
$context->close();