debug
This commit is contained in:
@@ -7,44 +7,48 @@ use PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||
use support\Log;
|
||||
use Webman\RedisQueue\Redis;
|
||||
|
||||
// 生日有礼
|
||||
define('AMQP_DEBUG', true);
|
||||
$host = config('cons.mq.host');
|
||||
$port = config('cons.mq.port');
|
||||
$user = config('cons.mq.user');
|
||||
$password = config('cons.mq.password');
|
||||
$queue = config('cons.mq.queue_t') . '-birthday.gift.sms';
|
||||
|
||||
// 防止空闲时间断线必须设置心跳
|
||||
$connection = new AMQPStreamConnection($host, $port, $user, $password,
|
||||
'/',
|
||||
false,
|
||||
'AMQPLAIN',
|
||||
null,
|
||||
'en_US',
|
||||
60,
|
||||
60,
|
||||
null,
|
||||
false,
|
||||
30
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false, false, [
|
||||
// 'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
try {
|
||||
// 生日有礼
|
||||
define('AMQP_DEBUG', true);
|
||||
$host = config('cons.mq.host');
|
||||
$port = config('cons.mq.port');
|
||||
$user = config('cons.mq.user');
|
||||
$password = config('cons.mq.password');
|
||||
$queue = config('cons.mq.queue_t') . '-birthday.gift.sms';
|
||||
|
||||
// 防止空闲时间断线必须设置心跳
|
||||
$connection = new AMQPStreamConnection($host, $port, $user, $password,
|
||||
'/',
|
||||
false,
|
||||
'AMQPLAIN',
|
||||
null,
|
||||
'en_US',
|
||||
60,
|
||||
60,
|
||||
null,
|
||||
false,
|
||||
30
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false);
|
||||
|
||||
$callback = function ($msg) use ($queue){
|
||||
$date_time = date('Y-m-d H:i:s');
|
||||
$data = $msg->body;
|
||||
Log::info('MQ收到消息[生日有礼]--->' . $data . '--->' . $date_time . "\n");
|
||||
// 发给队列
|
||||
Redis::send('birthday.gift.sms', $data);
|
||||
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
||||
};
|
||||
$rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback);
|
||||
while ($rabbit_channel->is_consuming()) {
|
||||
Log::info('birthday.gift.sms-MQ准备调用wait');
|
||||
$rabbit_channel->wait();
|
||||
}
|
||||
$rabbit_channel->close();
|
||||
$connection->close();
|
||||
}catch (Exception $exception) {
|
||||
Log::info('birthday.gift.sms-MQ错误' . $exception->getMessage());
|
||||
}
|
||||
|
||||
$callback = function ($msg) use ($queue){
|
||||
$date_time = date('Y-m-d H:i:s');
|
||||
$data = $msg->body;
|
||||
Log::info('MQ收到消息[生日有礼]--->' . $data . '--->' . $date_time . "\n");
|
||||
// 发给队列
|
||||
Redis::send('birthday.gift.sms', $data);
|
||||
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
||||
};
|
||||
$rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback);
|
||||
while ($rabbit_channel->is_consuming()) {
|
||||
Log::info('birthday.gift.sms-MQ准备调用wait');
|
||||
$rabbit_channel->wait();
|
||||
}
|
||||
$rabbit_channel->close();
|
||||
$connection->close();
|
||||
|
||||
Reference in New Issue
Block a user