rabbitmq 中的队列 交换机 路由的创建与绑定介绍以及队列参数介绍

5 篇文章 0 订阅

 

x-message-ttl:number
How long a message published to a queue can live before it is discarded (milliseconds).
(Sets the "x-message-ttl" argument.)
x-expires:number
How long a queue can be unused for before it is automatically deleted (milliseconds).
(Sets the "x-expires" argument.)
x-max-length:number
How many (ready) messages a queue can contain before it starts to drop them from its head.
x-max-length-bytes:number
Total body size for ready messages a queue can contain before it starts to drop them from its head.
x-overflow:string:number
Sets the queue overflow behaviour. This determines what happens to messages when the maximum length of a queue is reached.
 Valid values are drop-head, reject-publish or reject-publish-dlx. The quorum queue type only supports drop-head.
x-dead-letter-exchange:string
Optional name of an exchange to which messages will be republished if they are rejected or expire.
x-dead-letter-routing-key:string
Optional replacement routing key to use when a message is dead-lettered. If this is not set, the message's original routing key will be used.
x-single-active-consumer:boolean
If set, makes sure only one consumer at a time consumes from the queue and fails 
over to another registered consumer in case the active one is cancelled or dies.
x-max-priority:number
Maximum number of priority levels for the queue to support; if not set, the queue will not support message priorities.
x-queue-mode:lazy
Set the queue into lazy mode, keeping as many messages as possible on disk to reduce RAM usage; if not set, 
the queue will keep an in-memory cache to deliver messages as fast as possible.
x-queue-master-locator:string
Set the queue into master location mode, 
determining the rule by which the queue master is located when declared on a cluster of nodes.

mq 中的交换机 路由 队列的绑定示例:code eg1:

Logger logger = LoggerFactory.getLogger(MqTest.class);
public static final String DEAD_EXCHANGE = "dead_exchange";
public static final String DEAD_QUEUE = "dead_queue";
public static final String DEAD_ROUT_KEY = "dead_route";

public static final String NORMAL_EXCHANGE = "normal_exchange";
public static final String NORMAL_QUEUE = "normal_queue";
public static final String NORMAL_ROUT_KEY = "normal_route";

@Test
void initQueueAndExchange() throws Exception {
    //队列 交换机 路由的绑定
    Channel channel = RabbitmqUtil.getChannel(false);
    // 死信交换机
    channel.exchangeDeclare(DEAD_EXCHANGE, BuiltinExchangeType.DIRECT);
    // 普通交换机
    channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);

    HashMap<String, Object> hashMap = new HashMap<>();
    hashMap.put("x-dead-letter-exchange", DEAD_EXCHANGE);
    hashMap.put("x-dead-letter-routing-key", DEAD_ROUT_KEY);
    hashMap.put("x-max-length", 6);

    channel.queueDeclare(NORMAL_QUEUE, false, false, false, hashMap);
    channel.queueBind(NORMAL_QUEUE, NORMAL_EXCHANGE, NORMAL_ROUT_KEY);
    channel.queueDeclare(DEAD_QUEUE, false, false, false, null);
    channel.queueBind(DEAD_QUEUE, DEAD_EXCHANGE, DEAD_ROUT_KEY);
    logger.info("init ok ");
}

eg2 :

import com.lt.springcloudcommon.mqfile.MqConts;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author admin
 * @description DemoMqConfig
 * @date 2021/12/29 16:15
 */
@Configuration
public class DemoMqConfig {
    @Bean
    public Queue directQueue1() {
        return new Queue(MqConts.testQueue);
    }

    @Bean
    public DirectExchange directExchangeDemo() {
        // 三个构造参数:name durable autoDelete
        return new DirectExchange(MqConts.testExchange, false, false);
    }

    @Bean
    public Binding directBinding1() {
        return BindingBuilder.bind(directQueue1()).to(directExchangeDemo()).with(MqConts.testRoutKey);
    }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Diligently_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值