当前位置:   article > 正文

RabbitMQ-延迟队列_rabbitmq x-delayed-type python

rabbitmq x-delayed-type python

//延迟交换机类型
String DELAY_EXCHANGE_TYPE = “x-delayed-message”;
public static final String DELAY_QUEUE = “delay_queue”;
public static final String DELAY_EXCHANGE = “delay_exchange”;
public static final String DELAY_ROUTING_KEY = “delay_routing_key”;
@Bean
public CustomExchange delayCustomExchange() {
Map<String, Object> args = new HashMap<>(2);
args.put(“x-delayed-type”, “direct”);
return new CustomExchange(DELAY_EXCHANGE, DELAY_EXCHANGE_TYPE, true, false, args);
}

@Bean
public Queue delayQueue() {
return new Queue(DELAY_QUEUE, true, false, false);
}

@Bean
public Binding delaySendMsg() {
return BindingBuilder.bind(delayQueue()).to(delayCustomExchange()).with(DELAY_ROUTING_KEY).noargs();
}

public void sendDelayMsg(Object obj) {
    String jsonObject = JSONObject.toJSONString(obj);
rabbitTemplate.convertAndSend(RabbitConfig.DELAY_EXCHANGE,         RabbitConfig.DELAY_ROUTING_KEY, jsonObject, message -> {
message.getMessageProperties().setDelay(200);
// message.getMessageProperties().set;
return message;
});
}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/689525
推荐阅读
相关标签
  

闽ICP备14008679号