feat:修复

dev.saas.RedisCar
chentaisen 2024-10-08 14:16:02 +08:00
parent b22e3f54ef
commit 8ce6502511
13 changed files with 17 additions and 151 deletions

View File

@ -4,10 +4,10 @@ server:
# nacos线上地址
nacos:
addr: 49.235.136.60:8848
addr: 47.116.173.119:8848
user-name: nacos
password: nacos
namespace: wyh
namespace: oneone
# Spring
spring:
application:

View File

@ -1,48 +0,0 @@
package com.muyu.common.rabbit.config;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
*
*
*/
@Component
@Log4j2
public class ConfirmCallbackConfig implements RabbitTemplate.ConfirmCallback {
@Autowired
private RabbitTemplate rabbitTemplate;
/**
* @PostContructspringspring
*/
@PostConstruct
public void init() {
rabbitTemplate.setConfirmCallback(this);
}
/**
*
*
* @param correlationData
* @param ack
* @param cause
*/
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
if (!ack) {
String exchange = correlationData.getReturned().getExchange();
String message = correlationData.getReturned().getMessage().getBody().toString();
// 发送异常
log.error("消息:{},发送到交换机:{}失败,原因是:{}", message, exchange, cause);
// TODO 可以把异常信息 以及 消息的内容直接添加到 MYSQL
}
}
}

View File

@ -1,41 +0,0 @@
package com.muyu.common.rabbit.config;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
@Configuration
public class RabbitListenerConfigurer implements org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer {
static {
System.setProperty("spring.amqp.deserialization.trust.all", "true");
}
//以下配置RabbitMQ消息服务
@Autowired
public ConnectionFactory connectionFactory;
/**
*
* @return
*/
@Bean
public DefaultMessageHandlerMethodFactory handlerMethodFactory() {
DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
// 这里的转换器设置实现了 通过 @Payload 注解 自动反序列化message body
factory.setMessageConverter(new MappingJackson2MessageConverter());
return factory;
}
@Override
public void configureRabbitListeners(RabbitListenerEndpointRegistrar rabbitListenerEndpointRegistrar) {
rabbitListenerEndpointRegistrar.setMessageHandlerMethodFactory(handlerMethodFactory());
}
}

View File

@ -1,41 +0,0 @@
package com.muyu.common.rabbit.config;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
*
*/
@Component
@Log4j2
public class ReturnCallbackConfig implements RabbitTemplate.ReturnsCallback {
@Autowired
private RabbitTemplate rabbitTemplate;
/**
* @PostContructspringspring
*/
@PostConstruct
public void init() {
rabbitTemplate.setReturnsCallback(this);
}
/**
*
*
* @param returnedMessage the returned message and metadata.
*/
@Override
public void returnedMessage(ReturnedMessage returnedMessage) {
log.error("消息:{},被交换机:{} 回退!退回原因为:{}",
returnedMessage.getMessage().toString(), returnedMessage.getExchange(), returnedMessage.getReplyText());
// TODO 回退了所有的信息,可做补偿机制
}
}

View File

@ -1,7 +1,3 @@
com.muyu.common.rabbit.config.RabbitListenerConfig
com.muyu.common.rabbit.config.RabbitAdminConfig
com.muyu.common.rabbit.config.RabbitMQMessageConverterConfig
com.muyu.common.rabbit.RabbitListenerConfigurer

View File

@ -4,10 +4,10 @@ server:
# nacos线上地址
nacos:
addr: 49.235.136.60:8848
addr: 47.116.173.119:8848
user-name: nacos
password: nacos
namespace: wyh
namespace: oneone
# Spring
spring:

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-server</artifactId>
<artifactId>cloud-modules</artifactId>
<version>3.6.3</version>
</parent>

View File

@ -4,10 +4,10 @@ server:
# nacos线上地址
nacos:
addr: 49.235.136.60:8848
addr: 47.116.173.119:8848
user-name: nacos
password: nacos
namespace: wyh
namespace: oneone
# Spring
spring:

View File

@ -4,10 +4,10 @@ server:
# nacos线上地址
nacos:
addr: 49.235.136.60:8848
addr: 47.116.173.119:8848
user-name: nacos
password: nacos
namespace: wyh
namespace: oneone
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -4,10 +4,10 @@ server:
# nacos线上地址
nacos:
addr: 49.235.136.60:8848
addr: 47.116.173.119:8848
user-name: nacos
password: nacos
namespace: wyh
namespace: oneone
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -4,10 +4,10 @@ server:
# nacos线上地址
nacos:
addr: 49.235.136.60:8848
addr: 47.116.173.119:8848
user-name: nacos
password: nacos
namespace: wyh
namespace: oneone
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -4,10 +4,10 @@ server:
# nacos线上地址
nacos:
addr: 49.235.136.60:8848
addr: 47.116.173.119:8848
user-name: nacos
password: nacos
namespace: wyh
namespace: oneone
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -4,10 +4,10 @@ server:
# nacos线上地址
nacos:
addr: 49.235.136.60:8848
addr: 47.116.173.119:8848
user-name: nacos
password: nacos
namespace: wyh
namespace: oneone
# Spring
spring: