Go to file
2023-07-09 18:29:44 +08:00
example composer update 2023-07-09 18:12:14 +08:00
src doc:支持环境变量 2023-07-09 18:29:44 +08:00
.gitignore 初始化 2023-07-07 16:20:30 +08:00
composer.json composer update 2023-07-09 17:20:38 +08:00
README.md doc:文件说明 2023-07-09 18:19:57 +08:00

rocket-mq-thinkphp 适配客户端

使用说明

本客户端对接公司mq实现mq消息推送与订阅目前支持一对一与一对多订阅

安装

  1. 添加镜像地址
{
  "repositories": [{
    "type": "composer",
    "url": "http://composer.saas.test.tianmagroup.com"
  }]
}

  1. composer安装
composer  require  tm_xls/rocket-mq-client-thinkphp

配置

return [
    'host'      => '', //mq地址
    'callback'  => '/rocketmq/producer/notify', //回调地址默认不做修改
    //订阅节点
    'subscribe' => [
    ]
];

生产者

见example "Producer"

消费者

消费者执行逻辑由开发者定义,但是仍遵循如下规则:

  1. 首先在config/rocket_mq.php 文件subscribe节点配置订阅
return [
    'subscribe' => [
        //节点配置 由mq的topic.tag为标识 
        '[topic].[tag]' => [
            Test:class
        ] 
    ]
]

  1. Test:class 需要实现 tm\xls\rocketMq\thinkphp\consumer\contract\ListenerInterface 接口


namespace example;


use tm\xls\rocketMq\thinkphp\consumer\contract\ListenerInterface;
use tm\xls\rocketMq\thinkphp\consumer\message\Message;

class Consumer implements ListenerInterface
{

    private $message;

    public function __construct(Message $message)
    {
        $this->message = $message;
    }

    public function handle()
    {
        //处理订阅逻辑
    }

    public function enable(): bool
    {
        // 这边判断是否执行
        return true;
    }
}