// Create a connection factory
ConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
// Create a listener container
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
listenerContainer.setConnectionFactory(connectionFactory);
listenerContainer.setQueueNames("myQueue");
// Set up a message listener
listenerContainer.setMessageListener(message -> {
System.out.println("Received message: " + message.getBody());
});
// Start the listener container
listenerContainer.start();