This package is similar to yiisoft/yii2-queue but with improved design and code style. The new package is less coupled and more structured than the old one allowing better maintenance.
- Individual adapters are now separate packages. This means each adapter must be
required with composer to be available in your application. - Adapter may be any class which implements
AdapterInterface. This means you can replace one adapter with another without changing any code in your app. For example, you can usedbadapter in development while usingamqpin production, then you may seamlessly switch toredisif needed. This also means you can write your own adapter implementation if necessary.
There was a concept in yiisoft/yii2-queue called Job: you had to push it to the queue, and it was handled after
being consumed. In the new package, it is divided into two different concepts: a message and a handler.
-
A
Messageis a class implementingMessageInterface. It contains two types of data:- Type. The worker uses it to find the right handler for a message.
- Data. Any serializable data that should be used by the message handler.
All the message data is fully serializable (that means message
datamust be serializable too). It allows you to freely choose where and how to send and process messages. Both can be implemented in a single application, or separated into multiple applications, or you can do sending/processing only, leaving part of the work to another system including non-PHP ones (for example, a Go service handling CPU-intensive jobs). -
A
Handleris called by aWorkerwhen a message is received. DefaultWorkerfinds a corresponding message handler by the message type. See more.