[英]How to test if channel and queue are created and bind to the exchange in rabbitMq using rabbitMq TestContainer in Micronaut
在应用程序开始时,我正在创建以下通道和关联的队列
@Singleton
public class ChannelPoolListener extends ChannelInitializer {
@Override
public void initialize(Channel channel) throws IOException {
channel.exchangeDeclare("micronaut", BuiltinExchangeType.DIRECT, true);
channel.queueDeclare("inventory", true, false, false, null);
channel.queueBind("inventory", "micronaut", "books.inventory");
channel.queueDeclare("catalogue", true, false, false, null);
channel.queueBind("catalogue", "micronaut", "books.catalogue");
}
}
我想编写 JUnit 5 测试来检查队列是否创建并使用 rabbitMq 测试容器绑定到交换。
从 RabbitMq java API,我知道我们有一个频道的方法。 但不确定如何在 JUnit 5 中注入通道
GetResponse response = rabbitChannel.basicGet(QUEUE_NAME, BOOLEAN_NOACK);
只需通过 Micronaut 注释或 java 客户端 API 直接将队列与测试客户端/订阅者一起使用。
任何人都在寻找这种结果
@BeforeAll
@DisplayName("Initial setup")
void initialSetup() {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
try (Connection connection = factory.newConnection();
Channel channel = connection.createChannel()) {
new ChannelPoolListener().initialize(channel);
AMQP.Queue.DeclareOk response = channel.queueDeclarePassive("Hello world");
Assertions.assertTrue(application.isRunning());
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.