Skip to content

Commit 46106a2

Browse files
committed
[docs][skip ci] Update amqp and redis doc.
1 parent 82b1d77 commit 46106a2

2 files changed

Lines changed: 81 additions & 1 deletion

File tree

‎docs/transport/amqp_lib.md‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ Enqueue is an MIT-licensed open source project with its ongoing development made
1212
Implements [AMQP specifications](https://www.rabbitmq.com/specification.html) and implements [amqp interop](https://github.com/queue-interop/amqp-interop) interfaces.
1313
Build on top of [php amqp lib](https://github.com/php-amqplib/php-amqplib).
1414

15+
Features:
16+
* Configure with DSN string
17+
* Delay strategies out of the box
18+
* Interchangeable with other AMQP Interop implementations
19+
* Fixes AMQPIOWaitException when signal is sent.
20+
* More reliable heartbeat implementations.
21+
* Supports Subscription consumer
22+
23+
Parts:
1524
* [Installation](#installation)
1625
* [Create context](#create-context)
1726
* [Declare topic](#declare-topic)
@@ -25,6 +34,7 @@ Build on top of [php amqp lib](https://github.com/php-amqplib/php-amqplib).
2534
* [Consume message](#consume-message)
2635
* [Subscription consumer](#subscription-consumer)
2736
* [Purge queue messages](#purge-queue-messages)
37+
* [Long running task, heartbeat, timeouts](#long-running-task,-heartbeat,-timeouts)
2838

2939
## Installation
3040

@@ -275,4 +285,64 @@ $queue = $context->createQueue('aQueue');
275285
$context->purgeQueue($queue);
276286
```
277287

288+
## Long running task, heartbeat, timeouts
289+
290+
AMQP relies on heartbeat feature to make sure consumer is still there.
291+
Basically consumer is expected to send heartbeat frames from time to time to RabbitMQ broker.
292+
It is not possible to implement heartbeat feature in PHP, due to its synchronous nature.
293+
You could read more about the issues in post: [Keeping RabbitMQ connections alive in PHP](https://blog.mollie.com/keeping-rabbitmq-connections-alive-in-php-b11cb657d5fb).
294+
295+
`enqueue/amqp-lib` address the issue by registering heartbeat call as a [tick callbacks](http://php.net/manual/en/function.register-tick-function.php).
296+
To make it work you have to wrapp your long running task by `decalre(ticks=1) {}`.
297+
The number of ticks could be adjusted to your needs.
298+
Calling it at every tick is not good.
299+
300+
Please note that it does not fix heartbeat issue if you spent most of the time on IO operation.
301+
302+
Example:
303+
304+
```php
305+
<?php
306+
307+
use Enqueue\AmqpLib\AmqpConnectionFactory;
308+
use Interop\Amqp\AmqpConsumer;
309+
use Interop\Amqp\AmqpMessage;
310+
311+
$context = (new AmqpConnectionFactory('amqp:?heartbeat_on_tick=1'))->createContext();
312+
313+
$queue = $context->createQueue('a_queue');
314+
$consumer = $context->createConsumer($queue);
315+
316+
$subscriptionConsumer = $context->createSubscriptionConsumer();
317+
$subscriptionConsumer->subscribe($consumer, function(AmqpMessage $message, AmqpConsumer $consumer) {
318+
// ticks number should be adjusted.
319+
declare(ticks=1) {
320+
foreach (fetchHugeSet() as $item) {
321+
// cycle does something for a long time, much longer than amqp heartbeat.
322+
}
323+
}
324+
325+
$consumer->acknowledge($message);
326+
327+
return true;
328+
});
329+
330+
$subscriptionConsumer->consume(10000);
331+
332+
333+
function fetchHugeSet(): array {};
334+
```
335+
336+
Fixes partly `Invalid frame type 65` issue.
337+
338+
```
339+
Error: Uncaught PhpAmqpLib\Exception\AMQPRuntimeException: Invalid frame type 65 in /some/path/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php:528
340+
```
341+
342+
Fixes partly `Broken pipe or closed connection` issue.
343+
344+
```
345+
PHP Fatal error: Uncaught exception 'PhpAmqpLib\Exception\AMQPRuntimeException' with message 'Broken pipe or closed connection' in /some/path/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:190
346+
```
347+
278348
[back to index](../index.md)

‎docs/transport/redis.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ Enqueue is an MIT-licensed open source project with its ongoing development made
1212
The transport uses [Redis](https://redis.io/) as a message broker.
1313
It creates a collection (a queue or topic) there. Pushes messages to the tail of the collection and pops from the head.
1414
The transport works with [phpredis](https://github.com/phpredis/phpredis) php extension or [predis](https://github.com/nrk/predis) library.
15-
Make sure you installed either of them
15+
Make sure you installed either of them
16+
17+
Features:
18+
* Configure with DSN string
19+
* Delay strategies out of the box
20+
* Recovery&Redelivery support
21+
* Expiration support
22+
* Delaying support
23+
* Interchangeable with other Queue Interop implementations
24+
* Supports Subscription consumer
1625

26+
Parts:
1727
* [Installation](#installation)
1828
* [Create context](#create-context)
1929
* [Send message to topic](#send-message-to-topic)

0 commit comments

Comments
 (0)