You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Enhancement]: Publishing message to Rabbitmq test-container Queue and consuming it #7452
changed the title [-][Enhancement]: Publishing message to Rabbitmq Queue and consuming it[/-][+][Enhancement]: Publishing message to Rabbitmq test-container Queue and consuming it[/+]on Aug 31, 2023
Can you elaborate on this, please? Are you talking about utility methods to use rabbimq command inside the container?
I'm trying to write integration test for my Spring Application which uses Rabbitmq as Message Broker. In order to do that I have made below mentioned changes,
Adding Rabbitmq container details to the ConnectionFactory,
@Bean
public CachingConnectionFactory connectionFactory() throws Exception {
RabbitMQContainer rabbit =
new RabbitMQContainer(DockerImageName.parse("rabbitmq:3.7.25-management-alpine"));
rabbit.start();
final RabbitConnectionFactoryBean rabbitConnectionFactoryBean =
new RabbitConnectionFactoryBean();
rabbitConnectionFactoryBean.setHost(rabbit.getHost());
rabbitConnectionFactoryBean.setPort(rabbit.getAmqpPort());
rabbitConnectionFactoryBean.setUsername(rabbit.getAdminUsername());
rabbitConnectionFactoryBean.setPassword(rabbit.getAdminPassword());
rabbitConnectionFactoryBean.setUseSSL(Boolean.parseBoolean(userSsl));
rabbitConnectionFactoryBean.setSslAlgorithm(sslVersion);
rabbitConnectionFactoryBean.setEnableHostnameVerification(false);
rabbitConnectionFactoryBean.afterPropertiesSet();
final CachingConnectionFactory connectionFactory =
new CachingConnectionFactory(rabbitConnectionFactoryBean.getObject());
return connectionFactory;
Similarly created RabbitTemplate, SimpleRabbitListenerContainerFactory and using above mentioned connection factory
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() throws Exception {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setMaxConcurrentConsumers(1);
return factory;
}
@Bean
public RabbitTemplate amqpTemplate() throws Exception {
return new RabbitTemplate(connectionFactory());
}
@Bean
public Queue abc() {
return new Queue("abc", false);
}
Next I'm creating Exchange and Routing Key binding to Queues,
@Bean
public Declarables httpBinding() {
val queue = QueueBuilder.durable("queue").build();
val declarables = new Declarables(exchange, queue,
bind(queue).to("exchange")
.with("routingKey");
return declarables;
}
Am I missing something here, as per my understanding the only change that needs to be done is that ConnectionFactory should point to Rabbitmq test container, ryt?
Also, can we do more operations with RabbitMQContainer?
Even, I have bean created for the Queue, I'm getting this error in logs
Activity
[-][Enhancement]: Publishing message to Rabbitmq Queue and consuming it[/-][+][Enhancement]: Publishing message to Rabbitmq test-container Queue and consuming it[/+]eddumelendez commentedon Aug 31, 2023
Can you elaborate on this, please? Are you talking about utility methods to use rabbimq command inside the container?
miPlodder commentedon Aug 31, 2023
I'm trying to write integration test for my Spring Application which uses Rabbitmq as Message Broker. In order to do that I have made below mentioned changes,
Similarly created RabbitTemplate, SimpleRabbitListenerContainerFactory and using above mentioned connection factory
But I don't see my Rabbitmq listener listening to this message here,
ConnectionFactoryshould point to Rabbitmq test container, ryt?RabbitMQContainer?