All Projects → eislambey → php-rsmq

eislambey / php-rsmq

Licence: MIT License
PHP implementation of Redis Simple Message Queue

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-rsmq

PyRSMQ
Python Implementation of Redis Simple Message Queue Algorithm
Stars: ✭ 35 (+59.09%)
Mutual labels:  queue, rsmq
jrsmq
A lightweight message queue for Java that requires no dedicated queue server. Just a Redis server.
Stars: ✭ 28 (+27.27%)
Mutual labels:  queue, rsmq
dynamic-queue
The dynamic queue
Stars: ✭ 17 (-22.73%)
Mutual labels:  queue, message-broker
Rsmq
Redis Simple Message Queue
Stars: ✭ 1,556 (+6972.73%)
Mutual labels:  queue, rsmq
rsmq-promise
Promise interface for RSMQ
Stars: ✭ 28 (+27.27%)
Mutual labels:  queue, rsmq
horusec-platform
Horusec Platform is a set of web services that integrate with the Horusec CLI to facilitate the visualization and management of found vulnerabilities.
Stars: ✭ 32 (+45.45%)
Mutual labels:  message-broker
egg-bus
🐣 用 egg 编写优雅的队列与事件
Stars: ✭ 38 (+72.73%)
Mutual labels:  queue
myleetcode
♨️ Detailed Java & Python solution of LeetCode.
Stars: ✭ 34 (+54.55%)
Mutual labels:  queue
InterviewBit
Collection of solution for problems on InterviewBit
Stars: ✭ 77 (+250%)
Mutual labels:  queue
Agile-Server
A simple, fast, complete Node.js server solution, based on KOA. 简单快速的 、性能强劲的、功能齐全的 node 服务器解决方案合集,基于 KOA。
Stars: ✭ 24 (+9.09%)
Mutual labels:  queue
laravisor
Generate laravel supervisor configuration in easiest way
Stars: ✭ 20 (-9.09%)
Mutual labels:  queue
k2hash
K2HASH - NoSQL Key Value Store(KVS) library
Stars: ✭ 33 (+50%)
Mutual labels:  queue
public
util toolkit for go.golang 通用函数包
Stars: ✭ 135 (+513.64%)
Mutual labels:  queue
coolbeans
Coolbeans is a distributed work queue that implements the beanstalkd protocol.
Stars: ✭ 56 (+154.55%)
Mutual labels:  queue
alicemq
RabbitMQ Visualizer
Stars: ✭ 102 (+363.64%)
Mutual labels:  message-broker
libmcu
A toolkit for firmware development
Stars: ✭ 33 (+50%)
Mutual labels:  queue
queue-for-kirby
Basic queue for Kirby 2, using Cron and Kirby's flat file system
Stars: ✭ 17 (-22.73%)
Mutual labels:  queue
messenger-extra
Additional transports and serializer support for symfony messenger
Stars: ✭ 20 (-9.09%)
Mutual labels:  queue
coyotes
非常简单的异步命令执行队列
Stars: ✭ 24 (+9.09%)
Mutual labels:  queue
b-rabbit
A thread safe library that aims to provide a simple API for interfacing with RabbitMQ. Built on top of rabbitpy, the library make it very easy to use the RabbitMQ message broker with just few lines of code. It implements all messaging pattern used by message brokers
Stars: ✭ 15 (-31.82%)
Mutual labels:  message-broker

Redis Simple Message Queue

Travis CI Codecov

A lightweight message queue for PHP that requires no dedicated queue server. Just a Redis server.

PHP implementation of smrchy/rsmq

Installation

composer require eislambey/rsmq

Methods

Construct

Creates a new instance of RSMQ.

Parameters:

  • $redis (Redis): *required The Redis instance
  • $ns (string): optional (Default: "rsmq") The namespace prefix used for all keys created by RSMQ
  • $realtime (Boolean): optional (Default: false) Enable realtime PUBLISH of new messages

Example:

<?php

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$rsmq = new \Islambey\RSMQ\RSMQ($redis);

Queue

createQueue

Create a new queue.

Parameters:

  • $name (string): The Queue name. Maximum 160 characters; alphanumeric characters, hyphens (-), and underscores (_) are allowed.
  • $vt (int): optional (Default: 30) The length of time, in seconds, that a message received from a queue will be invisible to other receiving components when they ask to receive messages. Allowed values: 0-9999999 (around 115 days)
  • $delay (int): optional (Default: 0) The time in seconds that the delivery of all new messages in the queue will be delayed. Allowed values: 0-9999999 (around 115 days)
  • $maxsize (int): optional (Default: 65536) The maximum message size in bytes. Allowed values: 1024-65536 and -1 (for unlimited size)

Returns:

  • true (Bool)

Throws:

  • \Islambey\RSMQ\Exception

Example:

<?php

$rsmq->createQueue('myqueue');

listQueues

List all queues

Returns an array:

  • ["qname1", "qname2"]

Example:

<?php

$queues = $rsmq->listQueues();

deleteQueue

Deletes a queue and all messages.

Parameters:

  • $name (string): The Queue name.

Returns:

  • true (Bool)

Throws:

  • \Islambey\RSMQ\Exception

Example:

<?php

$rsmq->deleteQueue('myqueue');

getQueueAttributes

Get queue attributes, counter and stats

Parameters:

  • $queue (string): The Queue name.

Returns an associative array:

  • vt (int): The visibility timeout for the queue in seconds
  • delay (int): The delay for new messages in seconds
  • maxsize (int): The maximum size of a message in bytes
  • totalrecv (int): Total number of messages received from the queue
  • totalsent (int): Total number of messages sent to the queue
  • created (float): Timestamp (epoch in seconds) when the queue was created
  • modified (float): Timestamp (epoch in seconds) when the queue was last modified with setQueueAttributes
  • msgs (int): Current number of messages in the queue
  • hiddenmsgs (int): Current number of hidden / not visible messages. A message can be hidden while "in flight" due to a vt parameter or when sent with a delay

Example:

<?php

$attributes =  $rsmq->getQueueAttributes('myqueue');
echo "visibility timeout: ", $attributes['vt'], "\n";
echo "delay for new messages: ", $attributes['delay'], "\n";
echo "max size in bytes: ", $attributes['maxsize'], "\n";
echo "total received messages: ", $attributes['totalrecv'], "\n";
echo "total sent messages: ", $attributes['totalsent'], "\n";
echo "created: ", $attributes['created'], "\n";
echo "last modified: ", $attributes['modified'], "\n";
echo "current n of messages: ", $attributes['msgs'], "\n";
echo "hidden messages: ", $attributes['hiddenmsgs'], "\n";

setQueueAttributes

Sets queue parameters.

Parameters:

  • $queue (string): The Queue name.
  • $vt (int): optional * The length of time, in seconds, that a message received from a queue will be invisible to other receiving components when they ask to receive messages. Allowed values: 0-9999999 (around 115 days)
  • $delay (int): optional The time in seconds that the delivery of all new messages in the queue will be delayed. Allowed values: 0-9999999 (around 115 days)
  • $maxsize (int): optional The maximum message size in bytes. Allowed values: 1024-65536 and -1 (for unlimited size)

Note: At least one attribute (vt, delay, maxsize) must be supplied. Only attributes that are supplied will be modified.

Returns an associative array:

  • vt (int): The visibility timeout for the queue in seconds
  • delay (int): The delay for new messages in seconds
  • maxsize (int): The maximum size of a message in bytes
  • totalrecv (int): Total number of messages received from the queue
  • totalsent (int): Total number of messages sent to the queue
  • created (float): Timestamp (epoch in seconds) when the queue was created
  • modified (float): Timestamp (epoch in seconds) when the queue was last modified with setQueueAttributes
  • msgs (int): Current number of messages in the queue
  • hiddenmsgs (int): Current number of hidden / not visible messages. A message can be hidden while "in flight" due to a vt parameter or when sent with a delay

Throws:

  • \Islambey\RSMQ\Exception

Example:

<?php

$queue = 'myqueue';
$vt = 50;
$delay = 10;
$maxsize = 2048;
$rsmq->setQueueAttributes($queue, $vt, $delay, $maxsize)

Messages

sendMessage

Sends a new message.

Parameters:

  • $queue (string)
  • $message (string)
  • $delay (int): optional (Default: queue settings) The time in seconds that the delivery of the message will be delayed. Allowed values: 0-9999999 (around 115 days)

Returns:

  • $id (string): The internal message id.

Throws:

  • \Islambey\RSMQ\Exception

Example:

<?php

$id = $rsmq->sendMessage('myqueue', 'a message');
echo "Message Sent. ID: ", $id;

receiveMessage

Receive the next message from the queue.

Parameters:

  • $queue (string): The Queue name.
  • $vt (int): optional (Default: queue settings) The length of time, in seconds, that the received message will be invisible to others. Allowed values: 0-9999999 (around 115 days)

Returns an associative array:

  • message (string): The message's contents.
  • id (string): The internal message id.
  • sent (int): Timestamp of when this message was sent / created.
  • fr (int): Timestamp of when this message was first received.
  • rc (int): Number of times this message was received.

Note: Will return an empty array if no message is there

Throws:

  • \Islambey\RSMQ\Exception

Example:

<?php

$message = $rsmq->receiveMessage('myqueue');
echo "Message ID: ", $message['id'];
echo "Message: ", $message['message'];

deleteMessage

Parameters:

  • $queue (string): The Queue name.
  • $id (string): message id to delete.

Returns:

  • true if successful, false if the message was not found (bool).

Throws:

  • \Islambey\RSMQ\Exception

Example:

<?php

$id = $rsmq->sendMessage('queue', 'a message');
$rsmq->deleteMessage($id);

popMessage

Receive the next message from the queue and delete it.

Important: This method deletes the message it receives right away. There is no way to receive the message again if something goes wrong while working on the message.

Parameters:

  • $queue (string): The Queue name.

Returns an associvative array:

  • message (string): The message's contents.
  • id (string): The internal message id.
  • sent (int): Timestamp of when this message was sent / created.
  • fr (int): Timestamp of when this message was first received.
  • rc (int): Number of times this message was received.

Note: Will return an empty object if no message is there

Throws:

  • \Islambey\RSMQ\Exception

Example:

<?php

$message = $rsmq->popMessage('myqueue');
echo "Message ID: ", $message['id'];
echo "Message: ", $message['message'];

changeMessageVisibility

Change the visibility timer of a single message. The time when the message will be visible again is calculated from the current time (now) + vt.

Parameters:

  • qname (string): The Queue name.
  • id (string): The message id.
  • vt (int): The length of time, in seconds, that this message will not be visible. Allowed values: 0-9999999 (around 115 days)

Returns:

  • true if successful, false if the message was not found (bool).

Throws:

  • \Islambey\RSMQ\Exception

Example:

<?php

$queue = 'myqueue';
$id = $rsmq->sendMessage($queue, 'a message');
if($rsmq->changeMessageVisibility($queue, $id, 60)) {
	echo "Message hidden for 60 secs";
}

LICENSE

The MIT LICENSE. See LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].