From 4cdaf222e8613ba7b16c1b5d4820afd4ccb73a5a Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Tue, 21 Nov 2017 15:43:30 +0200 Subject: [PATCH 01/13] [doc] upd amqp note about ext version. --- docs/transport/amqp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/transport/amqp.md b/docs/transport/amqp.md index c094b88a4..ac7636604 100644 --- a/docs/transport/amqp.md +++ b/docs/transport/amqp.md @@ -18,7 +18,7 @@ Build on top of [php amqp extension](https://github.com/pdezwart/php-amqp). ## Installation -_**Warning**: You need amqp extension of at least 1.9.3 version. Though there are some cruicial changes that has not been released yet (it is supposed to be 1.10). Consider comiling the extension from source._ +_**Warning**: You need amqp extension of at least 1.9.3. Here's how you can [compile](https://github.com/php-enqueue/enqueue-dev/blob/09d209447b9dbdf118bff7d983fcb8b0f919e789/docker/Dockerfile#L8) the extension from the [source code](https://github.com/pdezwart/php-amqp)._ ```bash $ composer require enqueue/amqp-ext From d2c6e8b196ec5e75fa9efe0cff8c98ee96cb9ab3 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Tue, 28 Nov 2017 14:24:57 +0200 Subject: [PATCH 02/13] Update quick_tour.md --- docs/laravel/quick_tour.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/laravel/quick_tour.md b/docs/laravel/quick_tour.md index 84603c8f5..7b4b89107 100644 --- a/docs/laravel/quick_tour.md +++ b/docs/laravel/quick_tour.md @@ -1,6 +1,6 @@ # Laravel Queue. Quick tour. -You can use all transports built on top of [queue-interop](https://github.com/queue-interop/queue-interop) including [all supported](https://github.com/php-enqueue/enqueue-dev/tree/master/docs/transport) by Enqueue. +The [enqueue/laravel-queue](https://github.com/php-enqueue/laravel-queue) is message queue bridge for Enqueue. You can use all transports built on top of [queue-interop](https://github.com/queue-interop/queue-interop) including [all supported](https://github.com/php-enqueue/enqueue-dev/tree/master/docs/transport) by Enqueue. The package allows you to use queue interop transport the [laravel way](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/laravel/queues.md) as well as integrates the [enqueue simple client](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/laravel/quick_tour.md#enqueue-simple-client). From 338f08f604af295a5ea7a54136203912dbfe4846 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Tue, 28 Nov 2017 22:58:31 +0200 Subject: [PATCH 03/13] Fix "Warning: array_key_exists() expects parameter 2 to be array, null given" Warning: array_key_exists() expects parameter 2 to be array, null given in /mqdev/pkg/amqp-lib/AmqpContext.php on line 320 --- pkg/amqp-lib/AmqpContext.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/amqp-lib/AmqpContext.php b/pkg/amqp-lib/AmqpContext.php index d4616c60e..1c28eb7e2 100644 --- a/pkg/amqp-lib/AmqpContext.php +++ b/pkg/amqp-lib/AmqpContext.php @@ -70,6 +70,7 @@ public function __construct(AbstractConnection $connection, $config = []) $this->connection = $connection; $this->buffer = new Buffer(); + $this->subscribers = []; } /** From a071bcbaf4f416d8be618c35da72d923cdf6636c Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Tue, 28 Nov 2017 23:03:17 +0200 Subject: [PATCH 04/13] [amqp-bunny] Fix "Warning: array_key_exists() expects parameter 2 to be array, null given" Warning: array_key_exists() expects parameter 2 to be array, null given in /mqdev/pkg/amqp-lib/AmqpContext.php on line 320 --- pkg/amqp-bunny/AmqpContext.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/amqp-bunny/AmqpContext.php b/pkg/amqp-bunny/AmqpContext.php index e034d75fe..09c810bca 100644 --- a/pkg/amqp-bunny/AmqpContext.php +++ b/pkg/amqp-bunny/AmqpContext.php @@ -77,6 +77,7 @@ public function __construct($bunnyChannel, $config = []) } $this->buffer = new Buffer(); + $this->subscribers = []; } /** From 5c538d39a09f9fbf7d8f1cc8a5378d969ed7538e Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Thu, 30 Nov 2017 17:52:33 +0200 Subject: [PATCH 05/13] [amqp-bunny] In case of zero timeout we should pass null to bunny lib. --- pkg/amqp-bunny/AmqpContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/amqp-bunny/AmqpContext.php b/pkg/amqp-bunny/AmqpContext.php index 09c810bca..a519227ca 100644 --- a/pkg/amqp-bunny/AmqpContext.php +++ b/pkg/amqp-bunny/AmqpContext.php @@ -388,7 +388,7 @@ public function consume($timeout = 0) throw new \LogicException('There is no subscribers. Consider calling basicConsumeSubscribe before consuming'); } - $this->getBunnyChannel()->getClient()->run($timeout / 1000); + $this->getBunnyChannel()->getClient()->run(0 !== $timeout ? $timeout / 1000 : null); } /** From cbafaa19e14658e8ab65ec1cd89807a7898d3fd1 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Thu, 30 Nov 2017 18:33:46 +0200 Subject: [PATCH 06/13] [travis] add PHP 7.2 to build matrix. --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8e62e69a7..d8dbc8879 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,8 @@ matrix: - php: 7.1 env: SYMFONY_VERSION=v4.0.0-BETA4 UNIT_TESTS=true - php: 7.1 + env: SYMFONY_VERSION=3.4.* UNIT_TESTS=true + - php: 7.2 services: docker env: SYMFONY_VERSION=2.8.* FUNCTIONAL_TESTS=true PREPARE_CONTAINER=true - php: 7.1 From fb934bb04c1914951662e0c5b01f85300ac69a88 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 1 Dec 2017 10:22:32 +0200 Subject: [PATCH 07/13] Update quick_tour.md --- docs/quick_tour.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/quick_tour.md b/docs/quick_tour.md index 9a5eb4fa9..5e83bef35 100644 --- a/docs/quick_tour.md +++ b/docs/quick_tour.md @@ -161,7 +161,7 @@ The goal of the component is hide as much as possible low level details so you c For example, It configure a broker for you by creating queuest, exchanges and bind them. It provides easy to use services for producing and processing messages. It supports unified format for setting message expiration, delay, timestamp, correlation id. -It supports message bus so different applications can talk to each other. +It supports [message bus](http://www.enterpriseintegrationpatterns.com/patterns/messaging/MessageBus.html) so different applications can talk to each other. Here's an example of how you can send and consume event messages. From 157feaef3efabeaf9d8cd7e6de7641a6b08fc792 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 1 Dec 2017 12:20:03 +0200 Subject: [PATCH 08/13] [doc][skip ci] Add processor examples, notes on exception and more. fixes https://github.com/php-enqueue/enqueue-dev/issues/240 --- docs/consumption/message_processor.md | 48 ++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/docs/consumption/message_processor.md b/docs/consumption/message_processor.md index 470cdd8a6..56c239737 100644 --- a/docs/consumption/message_processor.md +++ b/docs/consumption/message_processor.md @@ -1,5 +1,13 @@ # Message processor +* [Basics](#basics) +* [Reply result](#reply-result) +* [On exceptions](#on-exceptions) +* [Examples](#examples) + + +## Basics + The message processor is an object that actually process the message and must return a result status. Here's example: @@ -20,9 +28,15 @@ class SendMailProcessor implements PsrProcessor } ``` -Usually there is no need to catch exceptions. -The message broker can detect consumer has failed and redeliver the message. -Sometimes you have to reject messages explicitly. +By returning `self::ACK` a processor tells a broker that the message has been processed correctly. + +There are other statuses: + +* `self::ACK` - Use this constant when the message is processed successfully and the message could be removed from the queue. +* `self::REJECT` - Use this constant when the message is not valid or could not be processed. The message is removed from the queue. +* `self::REQUEUE` - Use this constant when the message is not valid or could not be processed right now but we can try again later + +Look at the next example that shows the message validation before sending a mail. If the message is not valid a processor rejects it. ```php bind('foo', new SendMailProcessor()); $queueConsumer->consume(); ``` + +## On exceptions + +It is advised to not catch exceptions and [fail fast](https://en.wikipedia.org/wiki/Fail-fast). +Also consider using [supervisord](supervisord.org) or similar process manager to restart exited consumers. + +Despite advising to fail there are some cases where you might want to catch exceptions. + +* A message validator throws an exception on invalid message. It is better to catch it and return `REJECT`. +* Some transports ([Doctrine DBAL](../transport/dbal.md), [Filesystem](../transport/filesystem.md), [Redis](../transport/redis.md)) does notice an error, +and therefor won't be able to redeliver the message. The message is completely lost. You might want to catch an exception to properly redelivery\requeue the message. + +# Examples + +Feel free to contribute your own. + +* [LiipImagineBundle. ResolveCacheProcessor](https://github.com/liip/LiipImagineBundle/blob/713e36f5df353d7c5345daed5a2eefc23c103849/Async/ResolveCacheProcessor.php#L1) +* [EnqueueElasticaBundle. ElasticaPopulateProcessor](https://github.com/php-enqueue/enqueue-elastica-bundle/blob/7c05c55b1667f9cae98325257ba24fc101f87f97/Async/ElasticaPopulateProcessor.php#L1) +* [formapro/pvm. HandleAsyncTransitionProcessor](https://github.com/formapro/pvm/blob/d5e989a77eb1540a93e69abacc446b3d7937292d/src/Enqueue/HandleAsyncTransitionProcessor.php#L1) +* [php-quartz. EnqueueRemoteTransportProcessor](https://github.com/php-quartz/quartz-dev/blob/91690aa535b0322510b4555dab59d6ae9d7044e5/pkg/bridge/Enqueue/EnqueueRemoteTransportProcessor.php#L1) +* [php-comrade. CreateJobProcessor](https://github.com/php-comrade/comrade-dev/blob/43c0662b74340aae318bceb15d8564670325dcee/apps/jm/src/Queue/CreateJobProcessor.php#L1) + [back to index](../index.md) \ No newline at end of file From a4c4544c1f2a3da8a5e06174fc0a082af05d63ba Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 1 Dec 2017 13:49:30 +0200 Subject: [PATCH 09/13] [doc][skip ci] add doc for client on send extensions. --- docs/client/extensions.md | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 docs/client/extensions.md diff --git a/docs/client/extensions.md b/docs/client/extensions.md new file mode 100644 index 000000000..0e121b5c3 --- /dev/null +++ b/docs/client/extensions.md @@ -0,0 +1,45 @@ +# Client extensions. + +There is an ability to hook into sending process. You have to create an extension class that implements `Enqueue\Client\ExtensionInterface` interface. +For example, `TimestampMessageExtension` extension adds timestamps every message before sending it to MQ. + +```php +getTimestamp()) { + $message->setTimestamp(time()); + } + } + + public function onPostSend($topic, Message $message) + { + + } +} +``` + +## Symfony + +To use the extension in Symfony, you have to register it as a container service with a special tag. + +```yaml +# config/services.yaml + +services: + timestamp_message_extension: + class: Acme\TimestampMessageExtension + tags: + - { name: 'enqueue.client.extensions' } +``` + +You can add `priority` attribute with a number. The higher value you set the earlier the extension is called. + +[back to index](../index.md) From 1bc875eca0fea53a8dd2003a3144fd64016b7073 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 1 Dec 2017 13:51:31 +0200 Subject: [PATCH 10/13] [doc][skip ci] add client extensions doc to index. --- docs/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.md b/docs/index.md index c72d2ec73..3148c42ab 100644 --- a/docs/index.md +++ b/docs/index.md @@ -22,6 +22,7 @@ - [Supported brokers](client/supported_brokers.md) - [Message bus](client/message_bus.md) - [RPC call](client/rpc_call.md) + - [Extensions](client/extensions.md) * [Job queue](#job-queue) - [Run unique job](job_queue/run_unique_job.md) - [Run sub job(s)](job_queue/run_sub_job.md) From 02f992c44871333bb31f85e93acd32b96425f093 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 1 Dec 2017 19:03:44 +0200 Subject: [PATCH 11/13] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 150e674cf..a93a1401b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ This is where all development happens. The repository provides a friendly enviro Features: * [Feature rich](docs/quick_tour.md). -* Implements [JMS](https://docs.oracle.com/javaee/7/api/javax/jms/package-summary.html) like transports based on [queue-interop](https://github.com/queue-interop/queue-interop) interfaces. + +* Adopts [queue interoperable](https://github.com/queue-interop/queue-interop) interfaces (inspired by [Java JMS](https://docs.oracle.com/javaee/7/api/javax/jms/package-summary.html)). +* Battle-tested. Used in production. * Supported transports * [AMQP(s)](docs/transport/amqp.md) based on [PHP AMQP extension](https://github.com/pdezwart/php-amqp). [![Build Status](https://travis-ci.org/php-enqueue/amqp-ext.png?branch=master)](https://travis-ci.org/php-enqueue/amqp-ext) @@ -69,8 +71,8 @@ Features: * [Message bus](http://www.enterpriseintegrationpatterns.com/patterns/messaging/MessageBus.html) support. * [RPC over MQ](https://www.rabbitmq.com/tutorials/tutorial-one-php.html) support. * Temporary queues support. -* Well designed components decoupled and reusable. -* Carefully tested including unit and functional tests. +* Well designed, decoupled and reusable components. +* Carefully tested (unit & functional). * For more visit [quick tour](docs/quick_tour.md). ## Resources From 58ddc3132efbef63f27659b88d19d11dfcadaabc Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Mon, 4 Dec 2017 11:58:42 +0200 Subject: [PATCH 12/13] Update message_processor.md --- docs/consumption/message_processor.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/consumption/message_processor.md b/docs/consumption/message_processor.md index 56c239737..fe1d30ae5 100644 --- a/docs/consumption/message_processor.md +++ b/docs/consumption/message_processor.md @@ -169,5 +169,7 @@ Feel free to contribute your own. * [formapro/pvm. HandleAsyncTransitionProcessor](https://github.com/formapro/pvm/blob/d5e989a77eb1540a93e69abacc446b3d7937292d/src/Enqueue/HandleAsyncTransitionProcessor.php#L1) * [php-quartz. EnqueueRemoteTransportProcessor](https://github.com/php-quartz/quartz-dev/blob/91690aa535b0322510b4555dab59d6ae9d7044e5/pkg/bridge/Enqueue/EnqueueRemoteTransportProcessor.php#L1) * [php-comrade. CreateJobProcessor](https://github.com/php-comrade/comrade-dev/blob/43c0662b74340aae318bceb15d8564670325dcee/apps/jm/src/Queue/CreateJobProcessor.php#L1) +* [prooph/psb-enqueue-producer. EnqueueMessageProcessor](https://github.com/prooph/psb-enqueue-producer/blob/c80914a4092b42b2d0a7ba698b216e0af23bab42/src/EnqueueMessageProcessor.php#L1) -[back to index](../index.md) \ No newline at end of file + +[back to index](../index.md) From 3472424777b39d796ee100fec50e204f0ddcc33c Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Mon, 4 Dec 2017 20:16:53 +0200 Subject: [PATCH 13/13] Release 0.8.10 --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 458a90c15..70c3f88ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Change Log +## [0.8.10](https://github.com/php-enqueue/enqueue-dev/tree/0.8.10) (2017-12-04) +[Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.8.9...0.8.10) + +- \[dbal\] Store id \(uuid\) as binary data. [\#279](https://github.com/php-enqueue/enqueue-dev/issues/279) +- \[doc\] Add a doc with job queue doctrine migration example [\#278](https://github.com/php-enqueue/enqueue-dev/issues/278) +- Add mongodb support. [\#251](https://github.com/php-enqueue/enqueue-dev/issues/251) +- Add zeromq support [\#208](https://github.com/php-enqueue/enqueue-dev/issues/208) +- \[amqp-lib\] It should be possible to create queue without a name, [\#145](https://github.com/php-enqueue/enqueue-dev/issues/145) +- \[doc\] Add the doc for client extensions [\#73](https://github.com/php-enqueue/enqueue-dev/issues/73) +- \[doc\]\[skip ci\] add doc for client on send extensions. [\#285](https://github.com/php-enqueue/enqueue-dev/pull/285) ([makasim](https://github.com/makasim)) +- \[doc\]\[skip ci\] Add processor examples, notes on exception and more. [\#283](https://github.com/php-enqueue/enqueue-dev/pull/283) ([makasim](https://github.com/makasim)) +- \[travis\] add PHP 7.2 to build matrix. [\#281](https://github.com/php-enqueue/enqueue-dev/pull/281) ([makasim](https://github.com/makasim)) + +- \[enqueue/dbal\] Logic for "The platform does not support UUIDs natively" is incorrect [\#276](https://github.com/php-enqueue/enqueue-dev/issues/276) + ## [0.8.9](https://github.com/php-enqueue/enqueue-dev/tree/0.8.9) (2017-11-21) [Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.8.8...0.8.9)