码迷,mamicode.com
首页 > 其他好文 > 详细

rabbitmq死信队列(延迟队列)demoe

时间:2021-05-25 18:09:40      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:str   pre   sdn   load   details   tab   direct   hang   dem   

<?php

require_once ‘./vendor/autoload.php‘;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;
use PhpAmqpLib\Exchange\AMQPExchangeType;

$connection = new AMQPStreamConnection(‘127.0.0.1‘, 5672, ‘mq‘, ‘mq123‘, ‘/‘);
$channel = $connection->channel();

$channel->exchange_declare(‘exchange.dlx‘, AMQPExchangeType::DIRECT, false, true);
$channel->exchange_declare(‘exchange.normal‘, AMQPExchangeType::FANOUT, false, true);
$args = new AMQPTable();
// 消息过期方式:设置 queue.normal 队列中的消息10s之后过期
$args->set(‘x-message-ttl‘, 10000);
$args->set(‘x-dead-letter-exchange‘, ‘exchange.dlx‘);
$args->set(‘x-dead-letter-routing-key‘, ‘routingkey‘);
$channel->queue_declare(‘queue.normal‘, false, true, false, false, false, $args);
$channel->queue_declare(‘queue.dlx‘, false, true, false, false);

$channel->queue_bind(‘queue.normal‘, ‘exchange.normal‘);
$channel->queue_bind(‘queue.dlx‘, ‘exchange.dlx‘, ‘routingkey‘);
$message = new AMQPMessage(‘死信队列消息‘);
$channel->basic_publish($message, ‘exchange.normal‘, ‘rk‘);

$channel->close();
$connection->close();
————————————————

原文链接:https://blog.csdn.net/qq_42724459/article/details/109571547

  

rabbitmq死信队列(延迟队列)demoe

标签:str   pre   sdn   load   details   tab   direct   hang   dem   

原文地址:https://www.cnblogs.com/andydao/p/14807170.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!