Skip to content

Latest commit

 

History

History
61 lines (40 loc) · 5.43 KB

File metadata and controls

61 lines (40 loc) · 5.43 KB

UPGRADE FROM 1.x to 2.0

UsesGuzzleHttpClient Trait & HttpClientInterface Interface

  • HttpClientInterface interface was added and RestConfigurableProducer implements it via the UsesGuzzleHttpClient trait. The interface adds an extra function addHandler() that allows users to add extra Handlers to the ClientInterface. By default a new handler is added (Smartbox\Integration\FrameworkBundle\Components\WebService\Rest\Middleware) while building the container fixing an bug in Guzzle that incorrectly splits multibyte charaters in two when truncating the response body. If you're already tweaking the Guzzle client used by the RestConfigurableProducer, you'll have to check if this new handler overrides it.

AMQP Support

The AMQP driver was revamped to use the php-amqplib library instead of the PHP's built-in AMQP functions. The reason behind this was to take advantage of the non-blocking consume() function of this library, which the native driver doesn't support. Now the AMQP driver does not ignore posix signals bringing the possibility to stop the consumer gracefully with kill -s INT {pid}. To facilitate this feature, now the consumer name in AMQP shows the PID number as the last part of the name.

Naturally, now the php-amqplib is a dev-dependency of this bundle and a hard dependency of your project if you plan to use AMQP.

Configuration

Driver

  • timeout was renamed to read_timeout. If you use the heartbeat feature, the recommended value is 2 times the configured heartbeat value.
  • connection_timeout was added to work with both drivers. The default value is 30 seconds.
  • prefetch_count was added. STOMP defaults to 1 (and currently only supports that value) and AMQP to 10.
  • hearbeat was added and defaults to 60 seconds. Available only for the AMQP driver.
  • connections was removed. Use hostname instead.

Consumer

  • queue_consumers was added to configure the consumers. For a consumer, the following can be configured:
    • type determines which type of consumer is going to be used (possible values are sync or async).
    • decoding_exception_handler determines which exception handler should be used if a message can't be decoded. By default ReThrowExceptionHandler is used.
  • default_queue_consumer was added. Set your default queue consumer with this key. Useful to switch from STOMP to AMQP if you're already using this bundle.

Interfaces and classes

  • To accommodate the async nature of AMQP, QueueDriverInterface was heavily modified and two new interfaces extend it: SyncQueueDriverInterface and AsyncQueueDriverInterface. STOMP uses the former and AMQP the latter. Functions strictly related to STOMP or synchronous drivers were moved to the SyncQueueDriverInterface (i.e.: subscribe(), receive()).

  • Signatures for the QueueDriverInterface vary slightly from the original implementation:

    • format (i.e.: json) was removed from the configure() function and it was replaced by vhost (string).
  • PurgableQueueDriverInterface was removed.

  • AmqpQueueHandler and QueueManager were removed.

  • QueueMessage now includes an extra property called messageId. This is used to keep track of which message needs to be ack-ed in the broker. QueueMessageInterface was updated as well.

Smoke tests

  • QueueDriverConnectionSmokeTest will now insert a message into the isalive queue with a queue TTL of 1 second (via the x-message-ttl header). Depending on your DLX configuration, you might need to exclude this queue from the exchange's policy to prevent polluting the queue where your DLX inserts dead messages.

Other requirements

  • PHP's ext-sockets is now a requirement of this bundle, due to php-amqplib requiring it.

Exception handler

  • The original ExceptionHandler for poisoned messages was renamed to DecodingExceptionHandler and gives the consumer a chance to fix the message. The default behaviour remains rethrowing the exception, but if you have a custom handler, now you can return a new MessageInterface and continue the processing of the message.
  • Instead of using __invoke(), DecodingExceptionHandlers must implement the handle() function and return a new MessageInterface, null or throw an exception.

Serializer

  • The responsibility to serialize and deserialize a message has been decoupled from the driver to a new service that implements QueueSerializerInterface.
  • This new service is configured with JMS serializer to serialize and deserialize messages and a format that by default is configured to json.
  • This service is injected in the QueueProducer, QueueConsumer and AsyncQueueConsumer and has the responsibility to encode (prepare the message for what the driver expects) and decode (prepare the message received from the broker to what the consumer expects) messages.

Drivers

  • QueueDriverInterface was modified to decouple the serialization responsibility. Now the driver only accepts a string, instead of a QueueMessage. To achieve this, the send() function signature was changed to accept a destination, body (serialized payload), and headers.
  • The signature of the receive() function has been changed to return a Smartbox\Integration\FrameworkBundle\Core\Dtos\Message instead of a QueueMessage.
  • The function createQueueMessage() has been moved from the driver to the QueueProducer