赞
踩
//延迟交换机类型
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;
});
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。