Compare commits
2 Commits
5b81d000e2
...
02c744d8ca
Author | SHA1 | Date |
---|---|---|
|
02c744d8ca | 4 months ago |
|
b64530743e | 4 months ago |
@ -0,0 +1,28 @@
|
||||
package com.mashibing.api.config;
|
||||
|
||||
import com.mashibing.common.constant.RabbitMQConstant;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.core.QueueBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author heqijun
|
||||
* @ClassName: RabbitMQConfig
|
||||
* @Description: RabbitMQConfig
|
||||
* @date 2025/6/7 17:07
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class RabbitMQConfig {
|
||||
|
||||
/**
|
||||
* 构建接口模块发送消息到策略模块的队列
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Queue preSendQueue() {
|
||||
return QueueBuilder.durable(RabbitMQConstant.SMS_PRE_SEND).build();
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.mashibing.api.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author heqijun
|
||||
* @ClassName: RabbitMQTemplateConfig
|
||||
* @Description: 配置RabbitMQTemplate的confirm和return机制
|
||||
* @date 2025/6/7 17:12
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class RabbitMQTemplateConfig {
|
||||
|
||||
@Bean
|
||||
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
|
||||
|
||||
//设置connectionFactory
|
||||
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
|
||||
|
||||
//配置confirm机制回调
|
||||
rabbitTemplate.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {
|
||||
@Override
|
||||
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
||||
//消息妹有发送到交换机
|
||||
if (!ack) {
|
||||
log.error("【接口模块-发送消息】消息没有发送到交换机。。。" +
|
||||
"\n correlationData={},ack={},cause:{} ", correlationData, ack, cause);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//配置return机制回调
|
||||
rabbitTemplate.setReturnCallback(new RabbitTemplate.ReturnCallback() {
|
||||
@Override
|
||||
public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
|
||||
log.error("【接口模块-发送消息】消息没有路由到指定的队列。。。" +
|
||||
"\nmessage={},exchange={},routingKey={}", new String(message.getBody()), exchange, routingKey);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return rabbitTemplate;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.mashibing.common.constant;
|
||||
|
||||
/**
|
||||
* @author heqijun
|
||||
* @ClassName: RabbitMQConstant
|
||||
* @Description: RabbitMQConstant常量
|
||||
* @date 2025/6/7 17:02
|
||||
*/
|
||||
|
||||
public interface RabbitMQConstant {
|
||||
/**
|
||||
* 接口模块发送消息到策略模块的队列名称
|
||||
*/
|
||||
String SMS_PRE_SEND = "sms_pre_send_topic";
|
||||
}
|
Loading…
Reference in new issue