Rabbit MQ连接工厂通过2个节点连接到集群,但队列名称不同

时间:2019-05-31 16:52:05

标签: spring-boot rabbitmq spring-rabbitmq

下面是我的中间件团队配置的Rabbit设置。

  1. 一个具有2个节点的群集,每个节点具有1个队列,例如,Node1-> Sample.Q1和Node2-> Sample.Q2 队列配置为在兔子一侧具有50%的负载。
  2. 基本上Sample.Q1和Sample.Q2接收相同类型的消息,但是在每个主机上创建2个队列以提高弹性和高可用性。
  3. 我已请求他们在节点上保留相同的队列,但是我的中间件团队已确认他们无法在同一集群上创建重复的队列。 我的问题是spring boot如何支持创建连接工厂和Rabbit监听器。

我具有如下代码配置,但这不起作用,我知道这是不正确的。


@Bean
    public CachingConnectionFactory subscriberConnectionFactory() {
        CachingConnectionFactory subsCachingConnectionFactory = new CachingConnectionFactory();
        subsCachingConnectionFactory.setAddresses(rabbitMqConfig.getSubscriberAddresses());  // host1:port, host2:port
        subsCachingConnectionFactory.setUsername(rabbitMqConfig.getSubscriberUsername());
        subsCachingConnectionFactory.setPassword(rabbitMqConfig.getSubscriberPassword());
        subsCachingConnectionFactory.setVirtualHost(rabbitMqConfig.getVhost());
        subsCachingConnectionFactory.setConnectionNameStrategy(f -> "subscriberConnection");
        return subsCachingConnectionFactory;
    }

@RabbitListener(id="messageListener",queues = "#{rabbitMqConfig.getSubscriberQueueName()}",containerFactory="queueListenerContainer")
    public void receiveMessage(Message message, Channel channel, @Header("id") String messageId, 
            @Header("amqp_deliveryTag") Long deliveryTag) {

        LOGGER.info(" Message:"+ message.toString());
}

Queues are configured like Sample.Q1, Sample.Q2.
But this is not working.


----------
Error Log:
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'sample.q1,Hydra.clone.q2' in vhost 'Sample.services', class-id=50, method-id=10)
        at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)
        at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36)
        at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:494)
        at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:288)
        at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:138)
        ... 14 common frames omitted
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'Sample.q1,Sample.q2' in vhost 'Sample.services', class-id=50, method-id=10)
        at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:516)
        at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:346)
        at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:178)
        at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:111)
        at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:670)
        at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:48)
        at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:597)
        ... 1 common frames omitted

0 个答案:

没有答案