feat:修复
parent
b22e3f54ef
commit
8ce6502511
|
@ -4,10 +4,10 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 49.235.136.60:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: wyh
|
namespace: oneone
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
|
|
|
@ -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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @PostContruct是spring框架的注解,在⽅法上加该注解会在项⽬启动的时候执⾏该⽅法,也可以理解为在spring容器初始化的时候执
|
|
||||||
*/
|
|
||||||
@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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @PostContruct是spring框架的注解,在⽅法上加该注解会在项⽬启动的时候执⾏该⽅法,也可以理解为在spring容器初始化的时候执
|
|
||||||
*/
|
|
||||||
@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 回退了所有的信息,可做补偿机制
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +1,3 @@
|
||||||
|
|
||||||
com.muyu.common.rabbit.config.RabbitListenerConfig
|
com.muyu.common.rabbit.config.RabbitListenerConfig
|
||||||
com.muyu.common.rabbit.config.RabbitAdminConfig
|
com.muyu.common.rabbit.config.RabbitAdminConfig
|
||||||
com.muyu.common.rabbit.config.RabbitMQMessageConverterConfig
|
com.muyu.common.rabbit.config.RabbitMQMessageConverterConfig
|
||||||
|
|
||||||
com.muyu.common.rabbit.RabbitListenerConfigurer
|
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,10 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 49.235.136.60:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: wyh
|
namespace: oneone
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-server</artifactId>
|
<artifactId>cloud-modules</artifactId>
|
||||||
<version>3.6.3</version>
|
<version>3.6.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,10 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 49.235.136.60:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: wyh
|
namespace: oneone
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -4,10 +4,10 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 49.235.136.60:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: wyh
|
namespace: oneone
|
||||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -4,10 +4,10 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 49.235.136.60:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: wyh
|
namespace: oneone
|
||||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -4,10 +4,10 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 49.235.136.60:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: wyh
|
namespace: oneone
|
||||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -4,10 +4,10 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 49.235.136.60:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: wyh
|
namespace: oneone
|
||||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -4,10 +4,10 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 49.235.136.60:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: wyh
|
namespace: oneone
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
Loading…
Reference in New Issue