forked from Markzhaozzz/zipkin_php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmq2collector.php
37 lines (30 loc) · 964 Bytes
/
mq2collector.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
<?php
//对象转数组,使用get_object_vars返回对象属性组成的数组
function objectToArray($obj){
$arr = is_object($obj) ? get_object_vars($obj) : $obj;
if(is_array($arr)){
return array_map(__FUNCTION__, $arr);
}else{
return $arr;
}
}
//try{
include_once 'mq.php';
include 'Trace.php';
//error_reporting(E_ALL);
$span = MessageQueue::getInstance()->pop();
//echo "-->".gettype($span);
if(!is_null($span) && gettype($span)!= 'boolean')
{
$rk = new RdKafka\Producer();
$rk->setLogLevel(LOG_DEBUG);
$rk->addBrokers("127.0.0.1:9092");
$topic = $rk->newTopic("zipkin");
//var_dump(json_encode(array($span), true));exit;
$topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode(array($span), true));
}
// }catch(TException $tx){
// print 'TException: '.$tx->getMessage()."/n";
// echo 'TException: '.$tx->getMessage()."/n";
// }
?>