forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemit_log_topic.php
More file actions
33 lines (24 loc) · 792 Bytes
/
emit_log_topic.php
File metadata and controls
33 lines (24 loc) · 792 Bytes
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
<?php
//Establish connection to AMQP
$connection = new AMQPConnection();
$connection->setHost('127.0.0.1');
$connection->setLogin('guest');
$connection->setPassword('guest');
$connection->connect();
//Declare Channel
$channel = new AMQPChannel($connection);
$routing_key = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'anonymous.info';
$message = implode(' ',array_slice($argv, 2));
if(empty($message)) $message = "Hello World!";
try {
//Declare Exchange
$exchange_name = 'topic_logs';
$exchange = new AMQPExchange($channel);
$exchange->setType(AMQP_EX_TYPE_TOPIC);
$exchange->setName($exchange_name);
$exchange->declareExchange();
$exchange->publish($message, $routing_key);
echo " [x] Sent {$routing_key}:{$message}", PHP_EOL;
} catch(Exception $ex) {
print_r($ex);
}