-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_topic.php
More file actions
36 lines (32 loc) · 851 Bytes
/
send_topic.php
File metadata and controls
36 lines (32 loc) · 851 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
34
35
36
<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
// 连接服务
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
// 交换机的名字
$exchange = 'topic_logs';
// 交换机类型
$type = 'topic';
$auto_delete = false;
// 定义交换机
$channel->exchange_declare($exchange, $type, false, false, $auto_delete);
$data = getmypid();
$msg = new AMQPMessage($data);
$source = [
'and',
'ios',
'other'
];
$severities = [
'info',
'warning',
'error',
'other'
];
$routing_key = $source[mt_rand(0,2)].'.'.$severities[mt_rand(0,3)];
$channel->basic_publish($msg, $exchange, $routing_key);
echo " [x] Sent {$data} key {$routing_key}\n";
$channel->close();
$connection->close();