* Break dependence on RabbitAutoConfiguration.
* Restore Rabbit own-connection feature
This commit is contained in:
@@ -107,12 +107,13 @@ public class RabbitSourceListenerTests {
|
||||
"${spring.rabbitmq.test.port}"
|
||||
)) {
|
||||
|
||||
final RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class);
|
||||
// Reset the boot connection factory -should not matter to container as it SHOULD be using its own connection factory
|
||||
final CachingConnectionFactory bootFactory = context.getBean(CachingConnectionFactory.class);
|
||||
rabbitTemplate.convertAndSend("scsapp-testOwnSource", "foo");
|
||||
|
||||
bootFactory.resetConnection();
|
||||
|
||||
// Send a message on a separate connection - the container should still receive it.
|
||||
sendMessageOnSeparateConnection("scsapp-testOwnSource", "foo", bootFactory);
|
||||
|
||||
OutputDestination target = context.getBean(OutputDestination.class);
|
||||
Message<byte[]> sourceMessage = target.receive(600000, "rabbitSupplier-out-0");
|
||||
|
||||
@@ -122,6 +123,32 @@ public class RabbitSourceListenerTests {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message on a separate connection.
|
||||
*
|
||||
* @param routingKey message routing key
|
||||
* @param payload message content
|
||||
* @param bootFactory the auto-configured connection factory used to get connection coordinates from
|
||||
*/
|
||||
private void sendMessageOnSeparateConnection(String routingKey, Object payload, CachingConnectionFactory bootFactory) {
|
||||
CachingConnectionFactory copiedConnectionFactory = null;
|
||||
try {
|
||||
copiedConnectionFactory = new CachingConnectionFactory(bootFactory.getHost(), bootFactory.getPort());
|
||||
copiedConnectionFactory.setUsername(bootFactory.getUsername());
|
||||
copiedConnectionFactory.setPassword(bootFactory.getRabbitConnectionFactory().getPassword());
|
||||
if (bootFactory.getVirtualHost() != null) {
|
||||
copiedConnectionFactory.setVirtualHost(bootFactory.getVirtualHost());
|
||||
}
|
||||
RabbitTemplate rabbitTemplate = new RabbitTemplate(copiedConnectionFactory);
|
||||
rabbitTemplate.convertAndSend(routingKey, payload);
|
||||
}
|
||||
finally {
|
||||
if (copiedConnectionFactory != null) {
|
||||
copiedConnectionFactory.resetConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertiesPopulated() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
|
||||
Reference in New Issue
Block a user