Announcement Announcement Module
Collapse
No announcement yet.
Expose the queue name associated with a received message Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Expose the queue name associated with a received message

    I am trying to use Spring AMQP with RabbitMQ for processing messages within my notification application. I have a fanout exchange, which sends messages to two queues. The problem is, when the message is consumed, I need to know what queue the message came from. Is there a way to expose the queue name to my MessageListener? I have been unable to find out how to access the queue name from anywhere in the stack, given the configuration below. I'd be fine with having to use AOP to somehow inject the name back into message, if that is even possible.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:rabbit="http://www.springframework.org/schema/rabbit"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                               http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.1.xsd">
        
        <rabbit:connection-factory
            id="connectionFactory" 
            host="some.host.com" 
            port="5762" 
            username="exampleUsername" 
            password="examplePassword" 
            channel-cache-size="20" />
    
        <rabbit:listener-container connection-factory="connectionFactory" 
                                   concurrency="5"       
                                   acknowledge="auto"
                                   auto-startup="true">
            <rabbit:listener queue-names="comment_action,like_action,follow_action,cache_management,user_management,error_action,facebook_action" 
                             ref="amqpMessageListener"/>
        </rabbit:listener-container>
    Any help would be greatly appreciated!

  • #2
    Messages are sent to an exchange; queues are bound to exchanges. There is nothing in a message about the queue it was received from.

    The only way (I know of) to do what you want is to use a different listener for each queue (and inject the queue name into the listener).

    Comment


    • #3
      Originally posted by Gary Russell View Post
      Messages are sent to an exchange; queues are bound to exchanges. There is nothing in a message about the queue it was received from.

      The only way (I know of) to do what you want is to use a different listener for each queue (and inject the queue name into the listener).
      From an AMQP perspective, that makes complete sense. After seeing I could simply setup a listener for multiple queues, I was trying to avoid needing multiple listeners unnecessarily. I should be able to inject an identifier as a property and only need one listener class.

      Thanks for the help.

      Comment

      Working...
      X