diff --git a/app/command/ApplySmsTemp.php b/app/command/ApplySmsTemp.php index 2412aca..8b67dea 100644 --- a/app/command/ApplySmsTemp.php +++ b/app/command/ApplySmsTemp.php @@ -87,6 +87,10 @@ class ApplySmsTemp extends Command }else { Log::info('MQ收到消息[申请新短信模版/营销短信发送/微信模版消息]格式错误'); } + + + + $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); }; $rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback); diff --git a/config/process.php b/config/process.php index fb8b6cb..88d4101 100644 --- a/config/process.php +++ b/config/process.php @@ -70,8 +70,4 @@ return [ 'QuerySmsStatus' => [ 'handler' => MessagePushTask::class ], - // rabbitmq 消费者 - 'RabbitmqConsum' => [ - 'handler' => RabbConsumApplySmsTemp::class - ] ]; diff --git a/sd.php b/sd.php new file mode 100644 index 0000000..5b1986d --- /dev/null +++ b/sd.php @@ -0,0 +1,48 @@ +eventLoop = \Workerman\Events\Fiber::class; + +$worker->onWorkerStart = function() { + // Create RabbitMQ Client + $client = Client::factory([ + 'host' => '127.0.0.1', + 'port' => 5672, + 'user' => 'guest', + 'password' => 'guest', + 'vhost' => '/', + 'heartbeat' => 60, + 'heartbeat_callback' => function () { + echo " [-] coroutine-consumer-heartbeat\n"; + }, + 'interval' => [100, 300] + ])->connect(); + $channel = $client->channel(); + $channel->queueDeclare('hello-coroutine'); + // Consumer + $channel->consume(function (Message $message, Channel $channel, \Bunny\AbstractClient $client) { + echo " [>] Received ", $message->content, "\n"; + }, + 'hello-coroutine', + '', + false, + true + ); + $client->run(); + echo ' [*] Waiting for messages. To exit press CTRL+C', "\n"; + // Producer + \Workerman\Timer::add($interval = 5 , function () use ($channel) { + $channel->publish($message = 'Hello World By Self Timer. ' . time(), [], '', 'hello-coroutine'); + echo " [<] Sent $message\n"; + }); + echo " [!] Producer timer created, interval: $interval s.\n"; +}; +Worker::runAll(); \ No newline at end of file