scienta/php-rsmq-client

A client to publish messages to RSMQ, a nodejs message queue.

1.0.1 2020-12-01 14:48 UTC

This package is auto-updated.

Last update: 2024-10-29 05:40:20 UTC


README

Latest Stable Version Total Downloads License

php-rsmq-client

A library for queueing RSMQ messages in Redis.

TL;DR

A php implementation of the enqueue-code from RSMQ for adding messages to the queue. Supports realtime PUBLISH of new messages.

Installation

The recommended way to install php-rsmq-client is through Composer. Add the following dependency to your composer.json

{
	"require": {
		"scienta/php-rsmq-client": "~1.0"
	}
}

Alternatively, you can download the source code as a file and extract it.

Usage

Configuration for queues and messages can be more elaborate than specified below, all RSMQ options are supported. The library makes use of a Redis adapter make the usage of other php redis clients possible. Default (used in this example) is the phpredis C extension.

Creating a basic queue

use Scienta\RSMQClient\Config;
use Scienta\RSMQClient\Message;
use Scienta\RSMQClient\Queue;
use Scienta\RSMQClient\Redis\RedisAdapter;

//Create a redis connection
$redis = new \Redis();
$redis->connect('127.0.0.1', '6379');

//Configure and create/sync a queue
$config = new Config('myqueue');
$redisAdapter = new RedisAdapter($redis);
$queue = new Queue($config, $redisAdapter);

//Create a message
$message = new Message('Hello World');

//Send the message
$sentId = $queue->sendMessage($message);