I have camel and rabbitmq configured like the following and it is working. I am looking to improve the config setup.
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 like to improve the following? Or at least see if its possible?
1) How do I leverage spring boot autowiring. I feel like im duplicating beans by added the custom CamelConfig > rabbitConnectionFactory? Its not using the RabbitAutoconfiguration?
2) When I am using the connection factory I am referencing the rabbitmq-url and port twice? I am adding it in the rabbitConnectionFactory bean object and in the camel url? e.g.
.to("rabbitmq://rabbithost-url:5672/ ..etc.. &connectionFactory=#rabbitConnectionFactory")
can I not just reference it once in the connection factory? tried the following without the host as its included in connectionFactory but it did not work.
.to("rabbitmq://TEST-QUEUE.exchange?queue=TEST-QUEUE.queue&autoDelete=false&connectionFactory=#rabbitConnectionFactory")
The 1st working example I am using is based off this. camel.apache.org/rabbitmq example (see Custom connection factory )