Download the PHP package antidot-fw/message-queue without Composer
On this page you can find all versions of the php package antidot-fw/message-queue. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download antidot-fw/message-queue
More information about antidot-fw/message-queue
Files in antidot-fw/message-queue
Package message-queue
Short Description Message bus and Pub-Sub integration queues for Antidot Framework.
License BSD-2-Clause
Informations about the package message-queue
Antidot Framework Message Queue
Message queue implementation using enqueue/enqueue for Antidot Framework.
Message Queue
A message queue is an asynchronous communication method. It allows storing messages in the queue system until they are consumed and destroyed. Each message is processed only once by a unique consumer.
Different Queue Systems
- Null Queue
- Filesystem Queue
- DBAL Queue
- Redis Queue
- Beanstalk
- Amazon SQS
Each implementation will have different configuration details, see concrete documentation section. Furthermore, you can use any of systems implemented in the PHP-enqueue package, making the needed factories.
Usage
You can define as many contexts as you need. You can bind each context to different queues. Once you have created a Context class, you can start sending jobs to the queue. The job should contain the queue name, the message type, and the message itself.
Start listening a queue
Now you can configure actions for the message types received by the queue. The action is a callable class that receives a JobPayload as the first parameter.
Jobs and Producer
A Job is a class responsible for transport given data to the queue. It is composed of two parameters: the Queue name as a single string, and the JobPayload with the data to process in the queue. JsonPayload is a JSON serializable object composed of two other parameters: the message type and the message data as string or array.
Once you have a job class, you need to pass it to the producer to send the message to the queue. See the example below.
Actions
The actions are invokable classes that will execute when the queue processes the given message. This class has a unique parameter, the JobPayload.
Config
Bind an action to a message type.
This is the default config.
Transport specific config
Null Queue
So util for testing purposes, it discards any received job. The only configuration required by this transport type is to set it as context.
Filesystem Queue
The Filesystem queue stores produced jobs inside a file in memory. It requires the absolute file path to store the jobs.
DBAL Queue
The Doctrine DBAL queue stores produced jobs inside a database. It requires the name of the DBAL connection service.
Redis Queue
The redis queue stores produced jobs inside a redis database. It requires the redis connection params. You can use it with Predis or with the PHP Redis extension.
With Predis:
With PHP extension:
Ensure that you have PHP Redis extension installed and enabled
Beanstalk Queue
The Beanstalk queue requires the beanstalk host and beanstalk port to work. It uses Pheanstalk PHP library.
Amazon SQS Queue
The Amazon SQS queue stores produced jobs at aws. It requires the AWS console credentials. You can use both standard and FIFO queues depending on your requirements. The queue must exist in AWS before sending a Job to work.
Consumer
The worker is the CLI command responsible for listening to the given queue to get messages and process each message one by one. In this early version, the only argument that it uses is the queue name to start listening.
Events
The Antidot Framework Message Queue uses the PSR-14 Event Dispatcher to allow listening different instant occurred in the queue execution:
- QueueConsumeWasStarted: Dispatches on queue start.
- MessageReceived: Dispatches for any received job before process.
- MessageProcessed: Dispatches after the job processed, it will have the result of the process.
Extensions
See more about extensions on php-enqueue official docs
LogExtension
You can enable or disable debug mode logger in the framework default config. it uses PSR-3 Logger Interface internally.
Running in Production
In the production environment, you usually need a daemon to keep the consumer process alive. You can use Supervisor or any other system daemon alternative.
Supervisor
You need to install supervidor in your system. Then you need to configure the consumer as a supervisor job.
All versions of message-queue with dependencies
beberlei/assert Version ^3.2
enqueue/enqueue Version ^0.10.1
psr/container Version ^1.0.0
psr/event-dispatcher Version ^1.0