Skip to content

Magento Queue API definition proposal #1021

@alankent

Description

@alankent

Magento currently does not have a standard message queue API. There were plans based around “async events” (or a job queue) and “web hooks”, but this is not scheduled by the core team for Magento 2.0. This work is to propose a set of interfaces for Magento and community comment, ideally developed by someone who has practical experience of using a message queue within Magento in a real-life application. (Implementation of the interfaces would be a separate phase of development.)

The business goal is to support async processing of parts of requests. For example, to achieve greater performance, it may be desirable to accept an order and queue it for later processing, with the possible risk of the item becoming out of stock. This can deliver better throughput at peak, with the negative of occasionally having to later inform customers that an item is out of stock. (There is no proposal to change the current implementation of order processing. The only change is to provide a standardized message queue API that extensions can depend on.)

The work for this GitHub issue is to define service contracts (PHP interfaces) for sending messages to a queue, plus have a standardized API for receiving requests from the queue. The API/infrastructure should make it possible to plug in a different implementations, ideally per queue.

Example possible queue implementations include:

  • Call the processing function immediately (that is, don’t queue it at all – do it immediately). Useful for debugging and in environments where a separate process cannot be run.
  • Let the main processing flow form the HTTP response and send that back to the initiating web browser, then do all queued requests before exiting the current thread. This provides a faster response to the caller, while not requiring a separate process to manage to monitor the queue.
  • Use a table in MySQL as the queue. No need for another technology to be installed. Cron or similar could launch code to check for async requests and process them.
  • Redis, RabbitMQ, ActiveMQ, SQS, Kafka, … - the community should be able to plug in different queue implementations without change to the Magento code.

Magento might provide one or two implementations (e.g. no-queue, or no-queue and MySQL-queue). The community can then provide other implementations via extensions. No change should be required to producer code (code creating queue requests) or consumer code (code processing queue requests) when changing queue implementation.

The default Magento distribution most likely will not be changed to create messages. More likely a site would create a message inside a plugin or event observer.
Any synergies with the existing Magento event infrastructure should be considered. (e.g. can the event dispatch API be used for message queues?)

“Web hooks” was another related technology. One option was to supply a standard consumer implementation to send a queue message to a remote end point using a HTTP POST with JSON content.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions