RabbitMQ在本地环境下不消费数据
package com.test.core.condition; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component @Slf4j public class RabbitMQBeanDefinitionRegistryPostProcessor extends RabbitListenerAnnotationBeanPostProcessor { @Value("${spring.profiles.active}") private String environment; private final String UAT="uat"; private final String PROD="prod"; @Override public Object postProcessAfterInitialization(Object bean, String beanName) {
//只在UAT和PROD下消费数据 if (UAT.equals(environment)||PROD.equals(environment)) { return bean; } return null; } }