这是我的@Configuration
@豆 public AmqpAdmin amqpAdmin() { RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory());
DirectExchange dirExchange = new …
你用的是什么版本?
我刚刚复制了你的容器工厂,它对我来说很好(2.1.3)......
BTW,从2.0版开始,你可以添加 concurrency 到了 @RabbitListener 它将覆盖容器工厂中的任何值。
concurrency
@RabbitListener
/** * Set the concurrency of the listener container for this listener. Overrides the * default set by the listener container factory. Maps to the concurrency setting of * the container type. * <p>For a * {@link org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer * SimpleMessageListenerContainer} if this value is a simple integer, it sets a fixed * number of consumers in the {@code concurrentConsumers} property. If it is a string * with the form {@code "m-n"}, the {@code concurrentConsumers} is set to {@code m} * and the {@code maxConcurrentConsumers} is set to {@code n}. * <p>For a * {@link org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer * DirectMessageListenerContainer} it sets the {@code consumersPerQueue} property. * @return the concurrency. * @since 2.0 */ String concurrency() default "";
另外,不相关,但你不应该这样做 rabbitAdmin.declareExchange(dirExchange) 在bean声明中 - 在应用程序上下文生命周期中连接到RabbitMQ还为时过早。添加交换,队列和绑定为 @Bean s和管理员将自动查找并声明它们。
rabbitAdmin.declareExchange(dirExchange)
@Bean