首页>代码>springboot-rabbitmq整合(rabbitmq的四种交换器演示、延时队列演示)>/springboot-rabbitmq-master/src/main/java/com/ajwensome/mq/delayqueue/DelaySender.java
package com.ajwensome.mq.delayqueue;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author created by qwb on 2018/12/22 14:59
 */
@Component
@Slf4j
public class DelaySender {
    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendDelay(Order order){
        log.info("【订单生成时间】" + new Date().toString() +"【1分钟后检查订单是否已经支付】" + order.toString() );
        this.amqpTemplate.convertAndSend(DelayRabbitConfig.ORDER_DELAY_EXCAHNGE, DelayRabbitConfig.ORDER_DELAY_ROUTING_KEY, order, message -> {
            // 如果配置了 params.put("x-message-ttl", 5 * 1000); 那么这一句也可以省略,具体根据业务需要是声明 Queue 的时候就指定好延迟时间还是在发送自己控制时间
            message.getMessageProperties().setExpiration(1 * 1000 * 20 + "");
            return message;
        });
    }
}
最近下载更多
安东尼online  LV11 2023年12月20日
gaoxin222  LV14 2023年6月16日
wxm4252  LV12 2023年5月30日
newhaijun  LV15 2023年3月21日
wangdengzhe  LV7 2022年12月28日
ewan007  LV29 2022年7月6日
axel990  LV6 2022年5月16日
chokkint  LV12 2022年4月14日
tianli3000  LV7 2021年8月10日
gao123qq  LV21 2021年7月8日
最近浏览更多
yhwyhw1  LV2 2023年12月21日
安东尼online  LV11 2023年12月20日
gaoxin222  LV14 2023年6月16日
wxm4252  LV12 2023年5月29日
crosa_Don  LV18 2023年5月19日
杨豫川  LV12 2023年4月27日
newhaijun  LV15 2023年3月21日
guviva  LV6 2023年3月15日
ROCK森  LV12 2022年11月7日
80730176  LV7 2022年10月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友