rocket-mq-client-thinkphp/README.md
2023-07-12 11:50:55 +08:00

99 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# rocket-mq-thinkphp 适配客户端
## 使用说明
本客户端对接公司mq实现mq消息推送与订阅目前支持一对一与一对多订阅
### 安装
1. 添加镜像地址
```shell
{
"repositories": [{
"type": "composer",
"url": "http://composer.saas.test.tianmagroup.com"
}]
}
```
2. composer安装
```shell
composer require tm_xls/rocket-mq-client-thinkphp
```
> 安装过程中需要允许`tm_xls/composer-thinkphp-installer`插件运行以便自动生成配置文件
### 配置
```php
return [
'host' => env('mq_host', 'http://192.168.21.170:8085'), //mq地址
'callback_host' => env('mq_callback_host', 'http://192.168.21.170:8085'),//回调host
'callback' => '/rocketmq/producer/notify',//回调地址默认不做修改
//订阅节点
'subscribe' => [
]
];
```
### 生产者
见example "Producer"
### 消费者
消费者执行逻辑由开发者定义,但是仍遵循如下规则:
1. 首先在config/rocket_mq.php 文件subscribe节点配置订阅
```php
return [
'subscribe' => [
//节点配置 由mq的topic.tag为标识
'[topic].[tag]' => [
Test:class
]
]
]
```
2. `Test:class` 需要实现 `tm\xls\rocketMq\thinkphp\consumer\contract\ListenerInterface` 接口
```php
namespace example;
use tm\xls\rocketMq\thinkphp\consumer\contract\ListenerInterface;
use tm\xls\rocketMq\thinkphp\consumer\message\Message;
class Consumer implements ListenerInterface
{
private $message;
/**
* 所有订阅监听会自动注入 tm\xls\rocketMq\thinkphp\consumer\message\Message 对象
*
* @param Message $message
*/
public function __construct(Message $message)
{
$this->message = $message;
}
public function handle()
{
//队列消息
$this->message;
//处理订阅逻辑
// code ...
}
public function enable(): bool
{
// 这边判断是否执行
return true;
}
}
```