即时队列戳这里>即时队列
Tp6操作Rabbitmq实例 直连模式 direct
win本地安装
官网下载 erlang和rabbitmq
rabbitmq下载地址
erlang下载地址
启动rabbitmq


进入rabbitmq控制台
控制台链接

composer 安装amqp类库
composer requirer php-amqplib/php-amqplib
整合rabbitmq代码
<?php
declare(strict_types=1);
namespace xxx\rabbitmq;
use ErrorException;
use Exception;
use PhpAmqpLib\Channel\AMQPChannel;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;
class RabbitMQ
{
static private $instance;
private $host = '127.0.0.1';
private $port = 5672;
private $user = 'guest';
private $password = 'guest';
private $vhost = '/';
protected $connection;
protected $channel;
/**
* RabbitMQ constructor.
* @param array $config
*/
public function __construct(array $config = [])
{
!empty($config['host']) && $this->host = $config['host'];
!empty($config['port']) && $this->host = $config['port'];
!empty($config['user']) && $this->host = $config['user'];
!empty($config['password']) && $this->host = $config['password'];
!empty($config['vhost']) && $this->host = $config['vhost'];
$this->connection = new AMQPStreamConnection($this->host, $this->port, $this->user, $this->password, $this->vhost);
$this->channel = $this->connection->channel();
}
/**
* 实例化
* @param array $config
* @return RabbitMQ
*/
public static function instance(array $config = [])
{
if (!self::$instance instanceof self) {
self::$instance =

本文介绍如何使用RabbitMQ实现延时队列,包括配置安装步骤、代码示例以及如何设置消息过期时间及重试机制。
最低0.47元/天 解锁文章
5万+

被折叠的 条评论
为什么被折叠?



