Download the PHP package lukasz93p/async-message-channel without Composer
On this page you can find all versions of the php package lukasz93p/async-message-channel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lukasz93p/async-message-channel
More information about lukasz93p/async-message-channel
Files in lukasz93p/async-message-channel
Package async-message-channel
Short Description Package which allow to add and then process asynchronous messages. Currently based on RabbitMQ.
License MIT
Informations about the package async-message-channel
async-message-channel
Current implementation uses RabbitMQ, so to utilize it You have to install this broker.
Why to use this package?
- It abstracts all difficulties associated with asynchronous messages publishing and processing.
- It guarantees reliable publication of messages - in case of failure in publication even one of the messages exception is thrown.
- It helps with passing unsuccessfully processed messages back to queue.
How to use
Publishing
1 Add env configuration:
2 Create instance of :
Logger is instance of class implementing , it will be used to log error which can occur during message processing.
3 Publish message:
Message have to be instance of class implementing . Currently implementation is aligned with RabbitMQ requirements so defines three methods:
-
- returns body of a message as string
-
- returns routing key which will be used by RabbitMQ to route message into proper queues
-
- returns RabbitMQ's exchange name to use for message publishing
You can use default implementation:
receives array of s and publish them reliably in batch manner. If it receives information about publishing failure from RabbitMQ is thrown.
Processing
1 Create :
For messages processing implementation of is needed, this interface defines only one method:
As You can see receives as an only argument.
2 Decide what to do with processed messages inside :
Client code can decide what to do with processed message thorough implementation of method :
- if method method throws any exception/throwable(excluding ) will message from RabbitMQ. When message is rejected it will be deleted from queue but You can configure RabbitMQ to use for that purposes and instruct broker to pass messages back from to any other queue(probably the one to which message was originally added) with some delay.
- if throws then informs RabbitMQ that message was processed successfully then RabbitMQ simply deletes the message.
Summary:
- All exception thrown by will be logged.
- If message has been processed successfully should not throw any exception.
- If message processing failed but You don't want to receive that message again and log exception then throw inside .
- If message processing failed but You want to receive that message again and log exception throw any exception inside (You can be more explicit and throw ). To receive message again You also have to configure for RabbitMQ.
3 Start processing messages:
To start processing messages You need and instance of :
And then You should use :