Micronaut: How to create queues in ChannelPoolListener when multiple connections exist

345 Views Asked by At

Micronaut 3.0.2 with io.micronaut.rabbitmq:micronaut-rabbitmq dependency.

I would like to use multiple connections and then use the proposed ChannelPoolListener based on io.micronaut.rabbitmq.connect.ChannelInitializer to create queues/exchanges using a specific connection named configbus.

micronaut:
  application:
    name: micronautRabbitmq
rabbitmq:
  servers:
    configbus:
      uri: amqp://localhost:5672
      username: micronautRabbitmq
      password: micronautRabbitmq
    eventbus:
      uri: amqp://localhost:5671
      username: micronautRabbitmq
      password: micronautRabbitmq

How do I do this?

2

There are 2 best solutions below

0
On BEST ANSWER

As of micronaut-rabbitmq:3.1.0 the ChannelInitializer gets the name of the connection. So, whenever the initialize method is called for the desired connection, you can use the channel to create queues, exchanges, bindings, etc.

https://micronaut-projects.github.io/micronaut-rabbitmq/latest/guide/#initialization

1
On

You might be just missing the host and port keys there.

See the connections section here: https://micronaut-projects.github.io/micronaut-rabbitmq/latest/guide/#config