inteve/message-queue

Simple message queue

Fund package maintenance!
Other

v2.0.0 2023-11-02 14:05 UTC

This package is auto-updated.

Last update: 2024-10-31 00:41:36 UTC


README

Build Status Downloads this Month Latest Stable Version License

Simple message queue

Donate

Installation

Download a latest package or use Composer:

composer require inteve/message-queue

Inteve\MessageQueue requires PHP 7.4.0 or later.

Usage

$exceptionHandler = function (\Throwable $e) {
	\Tracy\Debugger::log($e, \Tracy\Debugger::EXCEPTION);
};
$dateTimeFactory = new MyDateTimeFactory; // implementation of Phig\DateTimeFactory
$adapter = new MemoryAdapter($exceptionHandler);
$manager = new Manager($adapter, $dateTimeFactory);

Insert message

$manager->create(
	queue: 'name-of-queue',
	data: [
		'field' => 'value',
		'field2' => 'value2',
	]
);

Consume message

Process message from given queue:

$manager->fetch(
	queue: 'name-of-queue',
	handler: function (array $data) {
		$data['field'];
		$data['field2'];
	}
);

Process messages from ALL queues (logs missing handlers via $exceptionHandler):

$message = $manager->multiFetch(
	handlers: [
		'name-of-queue' => function (array $data) {
			$data['field'];
			$data['field2'];
		}
		'name-of-queue-B' => function (array $data) {
			$data['field'];
			$data['field2'];
		}
	],
	limit: 10 // number of messages processed in multiFetch() call
);

Process messages from SPECIFIC queues:

$message = $manager->multiFetch(
	handlers: [
		'name-of-queue' => function (array $data) {
			$data['field'];
			$data['field2'];
		}
		'name-of-queue-B' => function (array $data) {
			$data['field'];
			$data['field2'];
		}
	],
	limit: 10, // number of messages processed in multiFetch() call
	fetchFrom: $mananger::FROM_LISTED_ONLY
);

License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/