rocket-mq-client-thinkphp/README.md

86 lines
1.5 KiB
Markdown
Raw Normal View History

2023-07-07 08:20:30 +00:00
# rocket-mq-thinkphp 适配客户端
## 使用说明
2023-07-09 10:19:57 +00:00
本客户端对接公司mq实现mq消息推送与订阅目前支持一对一与一对多订阅
2023-07-07 08:20:30 +00:00
### 安装
2023-07-09 10:19:57 +00:00
1. 添加镜像地址
```shell
{
"repositories": [{
"type": "composer",
"url": "http://composer.saas.test.tianmagroup.com"
}]
}
```
2. composer安装
```shell
composer require tm_xls/rocket-mq-client-thinkphp
```
2023-07-07 08:20:30 +00:00
### 配置
2023-07-09 10:19:57 +00:00
```php
return [
'host' => '', //mq地址
'callback' => '/rocketmq/producer/notify', //回调地址默认不做修改
//订阅节点
'subscribe' => [
]
];
2023-07-07 08:20:30 +00:00
2023-07-09 10:19:57 +00:00
```
2023-07-07 08:20:30 +00:00
### 生产者
2023-07-09 10:19:57 +00:00
见example "Producer"
2023-07-07 08:20:30 +00:00
2023-07-09 10:12:14 +00:00
### 消费者
消费者执行逻辑由开发者定义,但是仍遵循如下规则:
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;
public function __construct(Message $message)
{
$this->message = $message;
}
public function handle()
{
//处理订阅逻辑
}
public function enable(): bool
{
// 这边判断是否执行
return true;
}
}
```