Open dschulten opened 5 years ago
Adding a custom CachingConnectionFactory in the test was the missing link. If that is indeed the best way to do it, I can write a PR for the readme. Or is there a better way?
@SpringBootTest
@TestPropertySource(properties = {"embedded.qpid.port=0"})
public class MessagingRabbitmqApplicationTest {
@TestConfiguration
public static class Conf {
@Bean
CachingConnectionFactory cachingConnectionFactory(EmbeddedBroker embeddedBroker) {
return new CachingConnectionFactory(embeddedBroker.getPort());
}
}
@MockBean private Runner runner;
@Autowired private RabbitTemplate rabbitTemplate;
@Autowired private Receiver receiver;
@Test
public void test() throws Exception {
rabbitTemplate.convertAndSend(MessagingRabbitmqApplication.queueName, "Hello from RabbitMQ!");
receiver.getLatch().await(10000, TimeUnit.MILLISECONDS);
}
}
I added the starter jar to the spring guide example git clone https://github.com/spring-guides/gs-messaging-rabbitmq.git and applied the property to redefine the port:
The log shows that the embedded qpid comes up at the custom port, but Spring still tries to connect on port 5672.