forked from Qihoo360/qbusbridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
consumer.php
63 lines (49 loc) · 1 KB
/
consumer.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
require("./qbus.php");
ini_set('error_reporting', E_ALL);
if (count($argv) < 5)
{
print "Usage: php consumer.php config_path topic_name group_name cluster_name\n";
exit(1);
}
$config = $argv[1];
$topic = $argv[2];
$group = $argv[3];
$cluster = $argv[4];
echo "topic: ". $topic . " | group: " . $group . " | cluster: " . $cluster;
$consumer = new QbusConsumer;
if (false == $consumer->init($cluster, "./consumer.log", $config))
{
echo "Init failed\n";
exit(2);
}
if (false == $consumer->subscribeOne($group, $topic))
{
echo "subscribeOne failed\n";
exit(3);
}
$run = true;
function sig_handler($signo)
{
global $run;
$run = false;
}
pcntl_signal(SIGINT, "sig_handler");
if (false == $consumer->start())
{
echo "start failed";
exit(4);
}
$info = new QbusMsgContentInfo;
$count = 0;
while ($run)
{
declare(ticks = 1);
if ($consumer->consume($info))
{
echo "topic: ".$info->topic." | msg: ".$info->msg."\n";
}
}
$consumer->stop();
echo "done";
?>