Announcement Announcement Module
Collapse
No announcement yet.
Problem consuming messages using SimpleMessageListenerContainer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem consuming messages using SimpleMessageListenerContainer

    Hi,

    I have created 2 eclipse projects to test Spring RabbitMQ. The first one produces messages using this code:

    Code:
    public class AmqProducer {
    	
    	private RabbitTemplate rabbitTemplate;
    	private RabbitAdmin rabbitAdmin;
    
    	public RabbitAdmin getRabbitAdmin() {
    		return rabbitAdmin;
    	}
    
    	public void setRabbitAdmin(RabbitAdmin rabbitAdmin) {
    		this.rabbitAdmin = rabbitAdmin;
    	}
    
    	public RabbitTemplate getRabbitTemplate() {
    		return rabbitTemplate;
    	}
    
    	public void setRabbitTemplate(RabbitTemplate rabbitTemplate) {
    		this.rabbitTemplate = rabbitTemplate;
    	}
    
    	public void send(String queueName, Object message) {
    		
    		Queue queue = new Queue(queueName);
    	  
    		rabbitAdmin.declareQueue(queue);
    		rabbitTemplate.convertAndSend(queueName, message);
    		
    	}
    
    }
    On the other side, I'm consuming messages:

    Code:
    private SingleConnectionFactory rabbitConnectionFactory;
    
    	public SingleConnectionFactory getRabbitConnectionFactory() {
    		return rabbitConnectionFactory;
    	}
    
    	public void setRabbitConnectionFactory(
    			SingleConnectionFactory rabbitConnectionFactory) {
    		this.rabbitConnectionFactory = rabbitConnectionFactory;
    	}
    
    	public void initAmqAdapters() {
    		
    		List<String> subscriptions = new ArrayList<String>();
    		
    		subscriptions.add("1");
    		subscriptions.add("2");
    		subscriptions.add("3");
    		
    		Queue[] queues = new Queue[subscriptions.size()];
    		
    		for(int q = 0; q < subscriptions.size(); q++) {
    			
    			queues[q] = new Queue(subscriptions.get(q));
    		}
    		
    		SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    		container.setConnectionFactory(rabbitConnectionFactory);
    		container.setQueues(queues);
    		container.setAutoStartup(false);
    		
    		AmqMessageListenerAdapter listener = new AmqMessageListenerAdapter();
    		container.setMessageListener(listener);
    		
    		container.start();	
    	}
    When i send a message from the producer part, it's correctly placed into RabbitMQ queue. Starting the consumer, message is correctly dequed, but the callback for my message listener isn't firing.

    Please help.

    Cheers

  • #2
    Can you try adding this call after you set all the properties but before you start your listener container?
    Code:
    container.afterPropertiesSet();

    Comment


    • #3
      Originally posted by Mark Fisher View Post
      Can you try adding this call after you set all the properties but before you start your listener container?
      Code:
      container.afterPropertiesSet();
      Well, after calling afterPropertiesSet, i'm getting exactly the same beheaviour - messages got dequed correctly but without notification in my message listener. Although, if I place message consuming code in my first eclipse project where im producing them, the callback fired.

      Thanks

      Comment


      • #4
        Can you explain what you mean in that last comment?.... What I think you are saying is that moving that exact same listener code into the same project as the producer makes it work?

        Comment


        • #5
          Originally posted by Mark Fisher View Post
          Can you explain what you mean in that last comment?.... What I think you are saying is that moving that exact same listener code into the same project as the producer makes it work?
          Yes, exactly

          Comment


          • #6
            Well, that's a bit odd. Is there anything else different between those two processes or their configurations? And are you sure that you are running exactly one instance of the consumer-side process?

            Comment


            • #7
              Yes, i'm running only one instance of the consumer-sode process.
              I'm attaching Eclipse projects (producer / consumer side), if that can help.

              Thank you.

              Comment


              • #8
                Hi,

                Any pointers about this issue?

                Comment

                Working...
                X