crysalead/queue

支持消息派发的简单队列消费者框架。

dev-master 2022-05-17 18:27 UTC

This package is auto-updated.

Last update: 2024-09-17 23:25:19 UTC


README

Build Status

安装

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(此仓库是他的杰出作品的简单分支)。