-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathhelper_messagequeue.php
45 lines (39 loc) · 1.06 KB
/
helper_messagequeue.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
<?php
require_once __DIR__ . '/helper_load.php';
define('SY_MODULE', SY_PROJECT . 'task');
define('SY_SERVER_IP', (string)SyTool\Tool::getConfig('syserver.base.server.host'));
set_exception_handler('\SyError\ErrorHandler::handleException');
set_error_handler('\SyError\ErrorHandler::handleError');
SyLog\Log::setPath(SY_LOG_PATH);
/**
* 消息队列消费
*/
function syMessageQueueHelp()
{
print_r('帮助信息' . PHP_EOL);
print_r('-t 消息队列类型: redis kafka' . PHP_EOL);
}
function handleKafkaMessage()
{
global $kafka;
$kafka->refresh();
$kafka->handleMessage();
}
$type = SyTool\Tool::getClientOption('-t');
switch ($type) {
case 'redis':
$redis = new \Helper\MessageQueueRedis();
$redis->handleOption();
break;
case 'kafka':
$kafka = new \Helper\MessageQueueKafka();
pcntl_signal(SIGALRM, 'handleKafkaMessage');
while (true) {
pcntl_alarm(10);
pcntl_signal_dispatch();
sleep(10);
}
break;
default:
syMessageQueueHelp();
}