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 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) 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 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) diff --git a/docs/consumption/message_processor.md b/docs/consumption/message_processor.md index 470cdd8a6..fe1d30ae5 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(); ``` -[back to index](../index.md) \ No newline at end of file + +## 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) +* [prooph/psb-enqueue-producer. EnqueueMessageProcessor](https://github.com/prooph/psb-enqueue-producer/blob/c80914a4092b42b2d0a7ba698b216e0af23bab42/src/EnqueueMessageProcessor.php#L1) + + +[back to index](../index.md) 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) 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). 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. 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 diff --git a/pkg/amqp-bunny/AmqpContext.php b/pkg/amqp-bunny/AmqpContext.php index e034d75fe..a519227ca 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 = []; } /** @@ -387,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); } /** 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 = []; } /**