crysalead / queue
支持消息派发的简单队列消费者框架。
dev-master
2022-05-17 18:27 UTC
Requires
- php: >=7.0
- ext-json: *
Requires (Dev)
- aws/aws-sdk-php: ~3.0
- google/cloud-pubsub: ^1.29
- kahlan/kahlan: ~5.0
- microsoft/azure-storage-queue: ^1.3
- pda/pheanstalk: ~4.0
- predis/predis: ~1.0
Suggests
- aws/aws-sdk-php: To add support for AWS Simple Queue Service (SQS).
- google/cloud-pubsub: To add support for Google Cloud Pubsub.
- iron-io/iron_mq: To add support for IronMQ Queue.
- microsoft/azure-storage-queue: To add support for Microsoft Azure Storage Queue.
- pda/pheanstalk: To add support for Beanstalkd queue.
- predis/predis: To add support for Redis based queue and pub/sub functionality.
This package is auto-updated.
Last update: 2024-09-17 23:25:19 UTC
README
安装
composer require crysalead/queue
基本用法
创建队列实例
$broker = new Lead\Queue\Adapter\Sqs( "https://queue.url", new SqsClient([ 'version' => 'latest', 'region' => '<region>', 'credentials' => [ 'key'=> '<key>', 'secret'=>'<secretKey>' ] ]) );
监听队列
监听是一个 阻塞 调用,并以无限循环(默认20秒轮询超时)的方式运行。当有新消息到达时,您的回调函数将被触发。
$broker->listen(function($job) { if (!$job) { return; } /** * * Process the job... * */ // Delete the job from Queue. $job->delete(); });
关闭队列
您可以使用 shutdown()
方法关闭队列。
队列实例将以安全的方式响应PCNTL信号,不会在消息处理过程中中断。您可以在代码中安装信号处理程序,以干净、安全地关闭服务。
pcntl_signal( SIGINT, function() use ($broker) { $broker->shutdown(); } );
致谢
- Syndicate(此仓库是他的杰出作品的简单分支)。