...
Maven users will need to add the following dependency to their pom.xml
for in order to use this component:
Code Block | ||||
---|---|---|---|---|
| ||||
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring-boot</artifactId> <version>${camel.version}</version> <!-- use the same version as your Camel core version --> </dependency> |
...
Apache Camel ships a Spring Boot Starter module that allows you to develop Spring Boot applications using starter'sstarters. There is a sample application in the source code also.
...
The most important piece of functionality provided by the Camel auto-configuration is CamelContext
instance. Camel auto-configuration creates a SpringCamelContext
for you and takes care of the proper initialization and shutdown of that context. The created Camel context is also registered in the Spring application context (under camelContext
bean name), so you can access it just as any other Spring bean.
...
Camel auto-configuration collects all the RouteBuilder
instances from the Spring context and automatically injects them into the provided CamelContext
. It That means that creating new Camel route with the Spring Boot starter is as simple as adding the @Component
annotated class into to your classpath:
Code Block | ||
---|---|---|
| ||
@Component public class MyRouter extends RouteBuilder { @Override public void configure() throws Exception { from("jms:invoices").to("file:/invoices"); } } |
...
Camel auto-configuration provides a pre-configured ConsumerTemplate
and ProducerTemplate
instances. You can simply inject them into your Spring-managed beans:
Code Block | ||
---|---|---|
| ||
@Component public class InvoiceProcessor { @Autowired private ProducerTemplate producerTemplate; @Autowired private ConsumerTemplate consumerTemplate; public void processNextInvoice() { Invoice invoice = consumerTemplate.receiveBody("jms:invoices", Invoice.class); ... producerTemplate.sendBody("netty-http:http://invoicing.com/received/" + invoice.id()); } } |
By default consumer templates and producer templates comes come with the endpoint cache sizes equal set to 1000. You can change those values via the following Spring properties:
...
Auto-configured TypeConverter
Camel auto-configuration registers registers a TypeConverter
instance named typeConverter
in the Spring context.
...
Spring comes with the powerful type conversion API. Spring API happens not to be much different from very similar to the Camel type converter API. As those APIs are so similar, Camel Spring Boot automatically registers a bridge converter (SpringTypeConverter
) that delegates to the Spring conversion API. It basically That means that out-of-the-box Camel will treat Spring Converters as like Camel ones. With this approach you can enjoy both Camel and Spring converters accessed via Camel TypeConverter
API:
...
The easiest way to create a Camel-aware Spring Boot fat jar/war is to extend the org.apache.camel.spring.boot.F
class...atJarRouter
...