Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 1.89 KB

File metadata and controls

32 lines (23 loc) · 1.89 KB

Migrating from yii2-queue

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.

Adapters

  • 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 use db adapter in development while using amqp in production, then you may seamlessly switch to redis if needed. This also means you can write your own adapter implementation if necessary.

Messages and Handlers

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 Message is a class implementing MessageInterface. 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 data must 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 Handler is called by a Worker when a message is received. Default Worker finds a corresponding message handler by the message type. See more.