layout | title | parent | nav_order |
---|---|---|---|
default |
Filesystem |
Transports |
3 |
{% include support.md %}
Use files on local filesystem as queues. It creates a file per queue\topic. A message is a line inside the file. Limitations It works only in auto ack mode hence If consumer crashes the message is lost. Local by nature therefor messages are not visible on other servers.
- Installation
- Create context
- Send message to topic
- Send message to queue
- Send expiration message
- Consume message
- Purge queue messages
$ composer require enqueue/fs
<?php
use Enqueue\Fs\FsConnectionFactory;
// stores messages in /tmp/enqueue folder
$connectionFactory = new FsConnectionFactory();
// same as above
$connectionFactory = new FsConnectionFactory('file:');
// stores in custom folder
$connectionFactory = new FsConnectionFactory('/path/to/queue/dir');
// same as above
$connectionFactory = new FsConnectionFactory('file:///path/to/queue/dir');
// with options
$connectionFactory = new FsConnectionFactory('file:///path/to/queue/dir?pre_fetch_count=1');
// as an array
$connectionFactory = new FsConnectionFactory([
'path' => '/path/to/queue/dir',
'pre_fetch_count' => 1,
]);
$context = $connectionFactory->createContext();
// if you have enqueue/enqueue library installed you can use a factory to build context from DSN
$context = (new \Enqueue\ConnectionFactoryFactory())->create('file:')->createContext();
<?php
/** @var \Enqueue\Fs\FsContext $context */
$fooTopic = $context->createTopic('aTopic');
$message = $context->createMessage('Hello world!');
$context->createProducer()->send($fooTopic, $message);
<?php
/** @var \Enqueue\Fs\FsContext $context */
$fooQueue = $context->createQueue('aQueue');
$message = $context->createMessage('Hello world!');
$context->createProducer()->send($fooQueue, $message);
<?php
/** @var \Enqueue\Fs\FsContext $context */
$fooQueue = $context->createQueue('aQueue');
$message = $context->createMessage('Hello world!');
$context->createProducer()
->setTimeToLive(60000) // 60 sec
//
->send($fooQueue, $message)
;
<?php
/** @var \Enqueue\Fs\FsContext $context */
$fooQueue = $context->createQueue('aQueue');
$consumer = $context->createConsumer($fooQueue);
$message = $consumer->receive();
// process a message
$consumer->acknowledge($message);
// $consumer->reject($message);
<?php
/** @var \Enqueue\Fs\FsContext $context */
$fooQueue = $context->createQueue('aQueue');
$context->purge($fooQueue);