renatocason/magento2-module-mq

Magento 2 消息队列操作系统模块

安装数: 14,909

依赖项: 3

建议者: 0

安全性: 0

星级: 36

关注者: 9

分支: 18

公开问题: 5

类型:magento2-module

1.1.4 2020-11-07 18:59 UTC

This package is auto-updated.

Last update: 2024-09-08 03:41:28 UTC


README

为 Magento 2 社区版提供的轻量级消息队列实现。

Build Status Coverage Status Latest Stable Version Latest Unstable Version Total Downloads License

系统要求

本扩展支持以下版本的 Magento

  • 社区版 (CE) 版本 2.1.x
  • 社区版 (CE) 版本 2.2.x
  • 社区版 (CE) 版本 2.3.x

安装

  1. 通过 Composer 需求此模块
$ composer require renatocason/magento2-module-mq
  1. 启用模块
$ bin/magento module:enable Rcason_Mq
$ bin/magento setup:upgrade
  1. 安装您选择的任何消息队列后端扩展(见 消息队列后端 部分)
  2. 配置您的队列并实现您的消费者(见 实现 部分)
  3. 检查您的队列配置是否正确
$ bin/magento ce_mq:queues:list
  1. 运行您的消费者
$ bin/magento ce_mq:consumers:start product.updates

消息队列后端

本模块不包含任何消息队列后端实现。您需要选择并安装以下模块之一(或实现自己的模块),以便使消息队列工作

  • MqMysql - 在数据库中存储消息
  • MqAmqp - 集成任何 AMQP 队列管理器(例如 RabbitMQ)
  • Amazon SQS - 集成 Amazon SQS 作为队列管理器(进行中)

实现

一个简单的示例可以在这里找到这里

  1. 在模块的 etc/m2_mq.xml 文件中配置队列
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Rcason_Mq:etc/ce_mq.xsd">
    <ceQueue name="product.updates" broker="mysql"
        messageSchema="int"
        consumerInterface="Rcason\MqExample\Model\ExampleConsumer"/>
</config>
  1. 在您需要的类中需要发布者
/**
 * @param \Rcason\Mq\Api\PublisherInterface $publisher
 */
public function __construct(
    \Rcason\Mq\Api\PublisherInterface $publisher
) {
    $this->publisher = $publisher;
}
  1. 用它来排队消息
$this->publisher->publish('product.updates', $productId);
  1. 实现您的消费者
class ExampleConsumer implements \Rcason\Mq\Api\ConsumerInterface
{
    /**
     * {@inheritdoc}
     */
    public function process($productId)
    {
        // Your code here
    }
}

作者、贡献者和维护者

作者

贡献

许可证

在 Open Software License 版本 3.0 下许可