https://github.com/dspacelabs/queue
General Queueing library that supports various backend storage systems
https://github.com/dspacelabs/queue
broker filequeue message-queue php redis-queue sqs-queue
Last synced: 3 months ago
JSON representation
General Queueing library that supports various backend storage systems
- Host: GitHub
- URL: https://github.com/dspacelabs/queue
- Owner: dSpaceLabs
- License: mit
- Created: 2015-06-22T22:50:22.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-11-30T00:55:33.000Z (over 7 years ago)
- Last Synced: 2025-03-25T16:51:12.598Z (3 months ago)
- Topics: broker, filequeue, message-queue, php, redis-queue, sqs-queue
- Language: PHP
- Size: 43 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Queue Component [](https://travis-ci.org/dSpaceLabs/Queue)
===============General queue library for PHP, ability to support various different queue
systems.For more documentation, see the [wiki](https://github.com/dSpaceLabs/Queue/wiki).
## Installation
```
composer require dspacelabs/queue
```## Usage
```php
publish($message);
/**
* This will publish a message to the queue you created, the $body can be
* anything you want.
*/// Receive messages
$message = $queue->receive();
$body = $message->getBody();
// ... Process Data ...
/**
* $message will be the message that was published. `->receive()` can be put
* into a foreach loop if you want to continue to process the queue until
* all the messages are processed, use a for loop in you only want to process
* a small number of the messages
*//**
* Once you are done processing a message, it needs to be deleted from the queue
*/
$queue->delete($message);
```## Messages, Queues, Broker
Messages are published to queues. When you receive a message from a queue, you
will be interacting with this class.Queues are where you publish your messages to. For example, a Queue could be an
AWS SQS, RabbitMQ, or any other queue you can think of.The Broker helps you keep track of queues. So instead of having 100 different
queue objects all over, you just add all those to the Broker and let the Broker
sort them out. You just get the ones you need.## Using the FileQueue
The FileQueue will store messages on disk and is good to use for local
development.Messages are stored on disk in the file naming format "name.timestamp.message"
so you can have multiple file queues share the same directory.```php
publish(new Message('Hello World!'));// ...
$message = $queue->receive();
$body = $message->getBody(); // $body === "Hello World!"
$queue->delete($message);
```## Using the SqsQueue
Requires Amazon PHP SDK.
```bash
php composer.phar require aws/aws-sdk-php
``````php
'latest',
'region' => 'us-east-1',
'credentials' => $credentials,
]);$queue = new SqsQueue($client, $queueUrl, $name);
```## Using the StandardQueue
The standard queue is mainly used for testing. Once this is setup you
can quickly test your workflow. Keep in mind that this has some drawbacks
mainly that the messages are not persisted.```php
publish($message);// Consume all messages
/** @var Message $msg **/
while ($msg = $queue->receive()) {
// process message
// ...
// Delete the Message from the queu
$queue->delete($msg);
}
```NOTE: When using the StandardQueue, you do not need to delete the message like
in this example `$queue->delete($msg);` HOWEVER there are some queues out there
that support this.## Using the RedisQueue
To use the `RedisQueue` you need to install Predis
```bash
composer require predis/predis
```Once you have done that, you can begin to use the Redis as one of the possible
Queues.```php
addQueue($queue);// `queue.name` is the name given to the queue you created
// I assume you already have a `$message` created
$broker->get('queue.name')->publish($message);
$broker->get('queue.other')->publish($messageOther);
```## Change Log
See [CHANGELOG.md].
## License
Copyright (c) 2015-2017 dSpace Labs LLC
See [LICENSE] for full license.
[CHANGELOG.md]: https://github.com/dSpaceLabs/Queue/blob/master/CHANGELOG.md
[LICENSE]: https://github.com/dSpaceLabs/Queue/blob/master/LICENSE