Rabbitmq camel spring boot auto config

I have a camel and a rabbit set up as the next one and it works. I want to improve configuration settings.

pom.xml

<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-rabbitmq-starter</artifactId> <version>2.19.1</version> </dependency> 

application.yml

 spring: rabbitmq: host: rabbithost-url port: 5672 username: my-user password: my-password 

config bean

 @Configuration public class CamelConfig { @Resource private Environment env; @Bean public ConnectionFactory rabbitConnectionFactory(){ ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setHost(env.getProperty("spring.rabbitmq.host")); connectionFactory.setPort(Integer.valueOf(env.getProperty("spring.rabbitmq.port"))); connectionFactory.setAutomaticRecoveryEnabled(true); // more config options here etc return connectionFactory; } } 

Route Example

 @Component public class MyRoute extends RouteBuilder { @Override public void configure() throws Exception { from("direct:startQueuePoint") .id("idOfQueueHere") .to("rabbitmq://rabbithost-url:5672/TEST-QUEUE.exchange?queue=TEST-QUEUE.queue&autoDelete=false&connectionFactory=#rabbitConnectionFactory") .end(); } } 

Would you like to improve the following? Or at least see if this is possible?

1) . How to use autoload spring. I feel like I'm duplicating beans by adding a custom CamelConfig> rabbitConnectionFactory? Do not use RabbitAutoconfiguration?

2) When I use the factory connection, do I double reference the rabbitmq-url url and port? Am I adding it to the rabbitConnectionFactory bean object and to the camel url? eg

 .to("rabbitmq://rabbithost-url:5672/ ..etc.. &connectionFactory=#rabbitConnectionFactory") 

Can I not just reference it once in a factory join? tried the following without a host, as it is included in connectionFactory, but it did not work.

 .to("rabbitmq://TEST-QUEUE.exchange?queue=TEST-QUEUE.queue&autoDelete=false&connectionFactory=#rabbitConnectionFactory") 

The first working example that I use is based on this. Example camel.apache.org/rabbitmq (see factory user connection)

+5
source share

Source: https://habr.com/ru/post/1269873/


All Articles