forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emit_log_topic.php
38 lines (26 loc) · 870 Bytes
/
emit_log_topic.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
<?php
// composer require enqueue/amqp-bunny
require_once __DIR__.'/vendor/autoload.php';
use Enqueue\AmqpBunny\AmqpConnectionFactory;
use Interop\Amqp\AmqpTopic;
$config = [
'host' => 'localhost',
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
];
$connection = new AmqpConnectionFactory($config);
$context = $connection->createContext();
$topic = $context->createTopic('topic_logs');
$topic->setType(AmqpTopic::TYPE_TOPIC);
$context->declareTopic($topic);
$routing_key = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'anonymous.info';
$data = implode(' ', array_slice($argv, 2));
if (empty($data)) {
$data = 'Hello World!';
}
$message = $context->createMessage($data);
$message->setRoutingKey($routing_key);
$context->createProducer()->send($topic, $message);
echo ' [x] Sent ',$routing_key,':',$data," \n";
$context->close();