queue

Catalogue
  1. 1. @producer 生产数据
  2. 2. @consumer 消费队列数据

@producer 生产数据

1
2
3
4
5
use App\Lib\Producer;
/** @var Producer $producers */
$producers = \bean(Producer::class);
//发送到队列里
producer()->produce($producers->producer($pushmsg));

@consumer 消费队列数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use ImQueue\Amqp\Message\ConsumerMessage;
use ImQueue\Amqp\Result;
/**
* Class Consumer
* @package App\Lib
*/
class Consumer extends ConsumerMessage
{
public function __construct()
{
$this->setExchange(env("EXCHANGE"));
$this->setQueue(env("QUEUE"));
$this->setRoutingKey(env("ROUTE_KEY"));
}

/**
* 主流程消费数据入口
* @param PushMsg $data
* @return string
*/
public function consume($data): string
{
return Result::ACK;
}

/**
* 重新排队
* @return bool
*/
public function isRequeue(): bool
{
return true;
}

}