Results 1 to 8 of 8

Thread: Problem consuming messages using SimpleMessageListenerContainer

Hybrid View

  1. #1
    Join Date
    Jan 2011
    Location
    Spain
    Posts
    14

    Default 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. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

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

  3. #3
    Join Date
    Jan 2011
    Location
    Spain
    Posts
    14

    Default

    Quote 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

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

    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?

  5. #5
    Join Date
    Jan 2011
    Location
    Spain
    Posts
    14

    Default

    Quote 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

  6. #6
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •