public static void main(String[] args) {
final ApplicationContext rabbitConfig = new AnnotationConfigApplicationContext(RabbitConfiguration.class);
final ConnectionFactory rabbitConnectionFactory = rabbitConfig.getBean(ConnectionFactory.class);
final Queue rabbitQueue = rabbitConfig.getBean(Queue.class);
final MessageConverter messageConverter = new SimpleMessageConverter();
// create a listener container, which is required for asynchronous message consumption.
// AmqpTemplate cannot be used in this case
final SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
listenerContainer.setConnectionFactory(rabbitConnectionFactory);
listenerContainer.setQueueNames(rabbitQueue.getName());
// set the callback for message handling
listenerContainer.setMessageListener(new MessageListener() {
public void onMessage(Message message) {
final BigOperation bigOp = (BigOperation) messageConverter.fromMessage(message);
// simply printing out the operation, but expensive computation could happen here
System.out.println("Received from RabbitMQ: " + bigOp);
}
});