GenServer, subscribed to multiple RabbitMQ queues [SOLVED]

Hi, I want to handle messages from multiple RabbitMQ queues in one GenServer. So with following code:

def init(_) do
  AMQP.Queue.declare(channel, "q1")
  AMQP.Queue.declare(channel, "q2")
  AMQP.Basic.consume(channel, "q", nilm no_ack: true)
  AMQP.Basic.consume(channel, "q", nilm no_ack: true)

def handle_info({:basic_deliver, payload, _meta}, state) do
  {:noreplay, state}

Is where any way to detect inside handle_info from wich queue message received?


Try to inspect the meta parameter.

Thank you!

IO.inspect(meta) in my case gives me:

   app_id: :undefined,
   cluster_id: :undefined,
   consumer_tag: "amq.ctag-BFsF3LZZU_oFnf15FdzgFw",
   content_encoding: :undefined,
   content_type: :undefined,
   correlation_id: :undefined,
   delivery_tag: 1,
   exchange: "",
   expiration: :undefined,
   headers: :undefined,
   message_id: :undefined,
   persistent: false,
   priority: :undefined,
   redelivered: false,
   reply_to: :undefined,
   routing_key: "hello",
   timestamp: :undefined,
   type: :undefined,
   user_id: :undefined

I think, I can use consumer_tag for this purposes.


1 Like