This commit is contained in:
dute7liang
2023-12-29 02:04:32 +08:00
parent 934a613f11
commit 8a53930160
6 changed files with 141 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package com.ruoyi.cai.mq;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class AmqpProducer {
@Autowired
private RabbitTemplate rabbitTemplate;
public void sendCalculateSales(String message,Integer timeout){
rabbitTemplate.convertAndSend(AmqpConsumer.CALCULATE_SALES_EXCHANGE, AmqpConsumer.CALCULATE_SALES_KEY, message);
}
public void sendCheckTimeOut(String message,Integer timeout){
rabbitTemplate.convertAndSend(CheckTimeOutMqConfig.EXCHANGE_NAME,
CheckTimeOutMqConfig.ROUTING_KEY,
message,
messagePostProcessor -> {
messagePostProcessor.getMessageProperties().setDelay(timeout*1000); // 设置延迟时间,单位毫秒
return messagePostProcessor;
});
}
}