The transport uses Redis as a message broker. It creates a collection (a queue or topic) there. Pushes messages to the tail of the collection and pops from the head. The transport works with phpredis php extension or predis library. Make sure you installed either of them
Limitations It works only in auto ack mode hence If consumer crashes the message is lost.
- Installation
- Create context
- Send message to topic
- Send message to queue
- Consume message
- Delete queue (purge messages)
- Delete topic (purge messages)
- With php redis extension:
$ apt-get install php-redis
$ composer require enqueue/redis
- With predis library:
$ composer require enqueue/redis predis/predis:^1
- With php redis extension:
<?php
use Enqueue\Redis\RedisConnectionFactory;
$connectionFactory = new RedisConnectionFactory([
'host' => 'localhost',
'port' => 6379,
'vendor' => 'phpredis',
]);
$psrContext = $connectionFactory->createContext();
- With predis library:
<?php
use Enqueue\Redis\RedisConnectionFactory;
$connectionFactory = new RedisConnectionFactory([
'host' => 'localhost',
'port' => 6379,
'vendor' => 'predis',
]);
$psrContext = $connectionFactory->createContext();
<?php
/** @var \Enqueue\Redis\RedisContext $psrContext */
$fooTopic = $psrContext->createTopic('aTopic');
$message = $psrContext->createMessage('Hello world!');
$psrContext->createProducer()->send($fooTopic, $message);
<?php
/** @var \Enqueue\Redis\RedisContext $psrContext */
$fooQueue = $psrContext->createQueue('aQueue');
$message = $psrContext->createMessage('Hello world!');
$psrContext->createProducer()->send($fooQueue, $message);
<?php
/** @var \Enqueue\Redis\RedisContext $psrContext */
$fooQueue = $psrContext->createQueue('aQueue');
$consumer = $psrContext->createConsumer($fooQueue);
$message = $consumer->receive();
// process a message
<?php
/** @var \Enqueue\Redis\RedisContext $psrContext */
$fooQueue = $psrContext->createQueue('aQueue');
$psrContext->deleteQueue($fooQueue);
<?php
/** @var \Enqueue\Redis\RedisContext $psrContext */
$fooTopic = $psrContext->createTopic('aTopic');
$psrContext->deleteTopic($fooTopic);