不想做厨师的程序员不是好农民 2018-10-22 03:53 采纳率: 0%
浏览 8215

@RabbitListener 不起作用,但是信息可以发。

这两天整理RabbitMq,写了个问个测试东西,但是一直收到不信息,发就可以,在mq的
界面也能看到信息。以下是代码,大神帮忙看看哇

//连接rabbitMQ的基本配置
@Configuration
@EnableRabbit
public class RabbitConfig {
        @Bean
        public ConnectionFactory connectionFactory() {
            CachingConnectionFactory connectionFactory = new CachingConnectionFactory("192.168.88.246");
            connectionFactory.setUsername("admin");
            connectionFactory.setPassword("123456");
            connectionFactory.setPort(5672);
            return connectionFactory;
        }
        @Bean
        public AmqpAdmin amqpAdmin() {
            return new RabbitAdmin(connectionFactory());
        }
        @Bean
        public RabbitTemplate rabbitTemplate() {
            return new RabbitTemplate(connectionFactory());
        }
        //配置消费者监听的容器
        @Bean
        public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
            SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
            factory.setConnectionFactory(connectionFactory());
            factory.setConcurrentConsumers(3);
            factory.setMaxConcurrentConsumers(10);
            return factory;
        }
}

订阅配置


@Configuration
public class PublishSubscribeConfig {

    @Autowired
    RabbitConfig rabbitconfig;

    @Autowired
    UpdateOrgConfig orgConfig;

    @Bean
    public Queue myQueue1() {
       Queue queue=new Queue(orgConfig.getName());
       return queue;
    }

    @Bean
    public Queue myQueue2() {
       Queue queue=new Queue("com..updateorg.msg.2");
       return queue;
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        FanoutExchange fanoutExchange=new FanoutExchange("fanout");
        return fanoutExchange;
    }

    @Bean
    public Binding binding1(){
        Binding binding=BindingBuilder.bind(myQueue1()).to(fanoutExchange());
        return binding;
    }

    @Bean
    public Binding binding2(){
        Binding binding=BindingBuilder.bind(myQueue2()).to(fanoutExchange());
        return binding;
    }

}

监听配置


@Component
public class OrgConsumer2 {

    @RabbitListener(queues = "com..updateorg.msg.2")
    public void subscribe(String msg) throws IOException {
        System.out.println("订阅者2收到消息"+ msg);
    }
}

死活收到不信息

  • 写回答

2条回答 默认 最新

  • zqbnqsdsmd 2018-10-26 07:57
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿