|
@@ -1,10 +1,13 @@
|
|
package com.macro.mall.portal.component;
|
|
package com.macro.mall.portal.component;
|
|
|
|
|
|
|
|
+import com.macro.mall.portal.domain.QueueEnum;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.amqp.AmqpException;
|
|
import org.springframework.amqp.core.AmqpTemplate;
|
|
import org.springframework.amqp.core.AmqpTemplate;
|
|
|
|
+import org.springframework.amqp.core.Message;
|
|
|
|
+import org.springframework.amqp.core.MessagePostProcessor;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -14,13 +17,19 @@ import org.springframework.stereotype.Component;
|
|
@Component
|
|
@Component
|
|
public class CancelOrderSender {
|
|
public class CancelOrderSender {
|
|
private static Logger LOGGER =LoggerFactory.getLogger(CancelOrderSender.class);
|
|
private static Logger LOGGER =LoggerFactory.getLogger(CancelOrderSender.class);
|
|
- @Value("${rabbitmq.queue.name.cancelOrder}")
|
|
|
|
- private String QUEUE_NAME_CANCEL_ORDER;
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private AmqpTemplate amqpTemplate;
|
|
private AmqpTemplate amqpTemplate;
|
|
|
|
|
|
- public void send(Long orderId){
|
|
|
|
- amqpTemplate.convertAndSend(QUEUE_NAME_CANCEL_ORDER,orderId);
|
|
|
|
|
|
+ public void sendMessage(Long orderId,final long delayTimes){
|
|
|
|
+ //给延迟队列发送消息
|
|
|
|
+ amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(), QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(), orderId, new MessagePostProcessor() {
|
|
|
|
+ @Override
|
|
|
|
+ public Message postProcessMessage(Message message) throws AmqpException {
|
|
|
|
+ //给消息设置延迟毫秒值
|
|
|
|
+ message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
|
|
|
|
+ return message;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
LOGGER.info("send orderId:{}",orderId);
|
|
LOGGER.info("send orderId:{}",orderId);
|
|
}
|
|
}
|
|
}
|
|
}
|