Question

I want to send and consume the custom object as below using Spring AMQP.

Producer code

Record record = new Record("message1", new Date());
rabbitTemplate.convertAndSend(record);

Can anyone provide spring amqp @configuration settings for sending and consuming messages as above. Thanks!!!

Was it helpful?

Solution

You should take a look at the Sample Applications; some of them use @Configuration.

But, essentially, you need...

@Bean
public SimpleMessageListenerContainer container() {
    SimpleMessageListenerContainer container =
            new SimpleMessageListenerContainer(connectionFactory());
    MessageListenerAdapter adapter = new MessageListenerAdapter(myListener());
    container.setMessageListener(adapter);
    container.setQueues(foo());
    return container;
}

@Bean
public Object myListener() {
    return new Foo();
}

and the listener can be a POJO...

public class Foo {

    public void handleMessage(Record foo) {
        System.out.println(foo);
    }
}  

EDIT:

I added a Gist here for XML version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top