3.4. Starter Configuration
Clear and accessible configuration is a crucial part of any application. Camel starters fully support Spring Boot’s external configuration mechanism. You can also configure them through Spring Beans for more complex use cases.
3.4.1. Using External Configuration 링크 복사링크가 클립보드에 복사되었습니다!
Internally, every starter is configured through Spring Boot’s ConfigurationProperties. Each configuration parameter can be set in various ways (application.[properties|json|yaml] files, command line arguments, environments variables etc.). Parameters have the form of camel.[component|language|dataformat].[name].[parameter]
For example to configure the URL of the MQTT5 broker you can set:
camel.component.paho-mqtt5.broker-url=tcp://localhost:61616
Or to configure the delimeter of the CSV dataformat to be a semicolon(;) you can set:
camel.dataformat.csv.delimiter=;
Camel will use the Type Converter mechanism when setting properties to the desired type.
You can refer to beans in the Registry using the #bean:name:
camel.component.jms.transactionManager=#bean:myjtaTransactionManager
The Bean would be typically created in Java:
@Bean("myjtaTransactionManager")
public JmsTransactionManager myjtaTransactionManager(PooledConnectionFactory pool) {
JmsTransactionManager manager = new JmsTransactionManager(pool);
manager.setDefaultTimeout(45);
return manager;
}
Beans can also be created in configuration files but this is not recommended for complex use cases.
3.4.2. Using Beans 링크 복사링크가 클립보드에 복사되었습니다!
Starters can also be created and configured via Spring Beans. Before creating a starter , Camel will first lookup it up in the Registry by it’s name if it already exists. For example to configure a Kafka component:
@Bean("kafka")
public KafkaComponent kafka(KafkaConfiguration kafkaconfiguration){
return ComponentsBuilderFactory.kafka()
.brokers("{{kafka.host}}:{{kafka.port}}")
.build();
}
The Bean name has to be equal to that of the Component, Dataformat or Language that you are configuring. If the Bean name isn’t specified in the annotation it will be set to the method name.
Typical Camel Spring Boot projects will use a combination of external configuration and Beans to configure an application. For more examples on how to configure your Camel Spring Boot project, see the examples repository.