VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • PHP 框架 Hyperf 实现处理超时未支付订单和延时队列

延时队列

  • Delayproducer.Php
  • Amqpbuilder.Php

AmqpBuilder.php

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
 
declare(strict_types = 1);
 
namespace App\Components\Amqp;
 
use Hyperf\Amqp\Builder\Builder;
 
use Hyperf\Amqp\Builder\QueueBuilder;
 
class AmqpBuilder extends QueueBuilder
 
{
 
    /**
 
     * @param array|\PhpAmqpLib\Wire\AMQPTable $arguments
 
     *
 
     * @return \Hyperf\Amqp\Builder\Builder
 
     */
 
    public function setArguments($arguments) : Builder
 
    {
 
        $this->arguments = array_merge($this->arguments, $arguments);
 
        return $this;
 
    }
 
    /**
 
     * 设置延时队列相关参数
 
     *
 
     * @param string $queueName
 
     * @param int    $xMessageTtl
 
     * @param string $xDeadLetterExchange
 
     * @param string $xDeadLetterRoutingKey
 
     *
 
     * @return $this
 
     */
 
    public function setDelayedQueue(string $queueName, int $xMessageTtl, string $xDeadLetterExchange, string $xDeadLetterRoutingKey) : self
 
    {
 
        $this->setArguments([
 
            'x-message-ttl'             => ['I', $xMessageTtl * 1000], // 毫秒
 
            'x-dead-letter-exchange'    => ['S', $xDeadLetterExchange],
 
            'x-dead-letter-routing-key' => ['S', $xDeadLetterRoutingKey],
 
        ]);
 
        $this->setQueue($queueName);
 
        return $this;
 
    }
 
}