美文网首页
springboot+RabbitMQ 问题 RabbitLis

springboot+RabbitMQ 问题 RabbitLis

作者: 乔_a988 | 来源:发表于2019-05-29 17:49 被阅读0次

    因为多机环境fanout广播模式,每台机器需要使用自己的队列接受消息
    所以尝试使用以下的方案

        private static final String QUEUE_NAME="foo."+IPUtils.getLocalhostIp();
        @RabbitListener(queues = QUEUE_NAME)
        public void process(String command){
            ...
        }
    

    but...果断报错:Attribute value must be constant

    解决方案----Spring SPEL表达式闪亮登场(网上都是什么乱七八糟复杂又不好用的)

        private static final String QUEUE_NAME="foo."+IPUtils.getLocalhostIp();
    
        @Bean
        public Queue queue(){
            return new Queue(QUEUE_NAME,true);
        }
        @RabbitListener(queues = "#{queue.name}")
        public void process(String command){
            ...
        }
    

    以上

    相关文章

      网友评论

          本文标题:springboot+RabbitMQ 问题 RabbitLis

          本文链接:https://www.haomeiwen.com/subject/xjqutctx.html