crysalead/queue

Simple queue consumer framework that supports message dispatching.

dev-master 2021-01-04 16:29 UTC

This package is auto-updated.

Last update: 2021-06-04 17:16:57 UTC


README

Build Status

Install

composer require crysalead/queue

Basic usage

Create Queue instance

$broker = new Lead\Queue\Adapter\Sqs(
    "https://queue.url",
    new SqsClient([
        'version' => 'latest',
        'region' => '<region>',
        'credentials' => [
            'key'=> '<key>',
            'secret'=>'<secretKey>'
        ]
    ])
);

Listen on queue

Listening is a blocking call and runs in an infinite loop (up to default 20s polling timout). Your callback will be triggered when a new Message has arrived.

$broker->listen(function($job) {

	if (!$job) {
		return;
	}
	/**
	 *
	 *  Process the job...
	 *
	 */

	// Delete the job from Queue.
	$job->delete();

});

Shutting down the Queue

You may shutdown the queue by using the shutdown() method.

The Queue instance will respond to PCNTL signals in a safe manner that will not interrupt in the middle of Message processing. You can install signal handlers in your code to cleanly and safely shutdown the service.

pcntl_signal(
	SIGINT,
	function() use ($broker) {
		$broker->shutdown();

	}
);

Acknowledgements

  • Syndicate (this repo is a simple fork of his brillant work).