| | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import com.xcong.excoin.configurations.RabbitMqConfig; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.amqp.AmqpException; |
| | | import org.springframework.amqp.core.AmqpTemplate; |
| | | import org.springframework.amqp.core.Message; |
| | | import org.springframework.amqp.core.MessageDeliveryMode; |
| | | import org.springframework.amqp.core.MessagePostProcessor; |
| | | import org.springframework.amqp.rabbit.connection.CorrelationData; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | public void sendDelayOrderMsg(String content) { |
| | | log.info("-----{}", new Date()); |
| | | CorrelationData correlationData = new CorrelationData(IdUtil.simpleUUID()); |
| | | amqpTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_DELAY, RabbitMqConfig.ROUTING_KEY_DELAY, content); |
| | | amqpTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_DELAY, RabbitMqConfig.ROUTING_KEY_DELAY, content, new MessagePostProcessor() { |
| | | @Override |
| | | public Message postProcessMessage(Message message) throws AmqpException { |
| | | //设置消息持久化 |
| | | message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT); |
| | | message.getMessageProperties().setHeader("x-delay", 6000);//设置延时时间 |
| | | return message; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |