...
Else, if more customization is needed, any CamelContext
class can be used to declare a custom Camel context bean. Then, the @PostConstruct
and @PreDestroy
lifecycle callbacks can be done to do the customization, e.g.:
...
As part of the Camel bean integration, Camel comes with a set of annotations that are seamlessly supported by Camel CDI. So you can use any of these annotations in your CDI beans, e.g.:
Camel annotation | CDI equivalent | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Configuration property |
| If using DeltaSpike configuration mechanism:
See configuration properties for more details. | ||||||||||
Producer template injection (default Camel context) |
|
| ||||||||||
Endpoint injection (default Camel context) |
|
| ||||||||||
Endpoint injection (Camel context by name) |
|
| ||||||||||
Bean injection (by type) |
|
| ||||||||||
Bean injection (by name) |
|
| ||||||||||
POJO consuming |
|
...
You can refer to CDI beans, either by type or name, From from the Camel DSL, e.g. with , using the Java Camel DSL:
Code Block | ||
---|---|---|
| ||
class MyBean { //... } from("direct:inbound").bean(MyBean.class); |
...
Code Block | ||
---|---|---|
| ||
@Named("foo")
class MyNamedBean {
//...
}
from("direct:inbound")
.bean("foo"); |
Referring Beans From Endpoint URIs
When configuring endpoints using the URI syntax you can refer to beans in the Registry using the #
notation. If the URI parameter value starts with a a #
sign sign then Camel CDI will lookup for a bean of the given type by name, e.g.:
Code Block | ||
---|---|---|
| ||
from("jms:queue:{{destination}}?transacted=true&transactionManager=#jtaTransactionManager")
.to("..."); |
Having the following CDI bean qualified with @Named("jtaTransactionManager")
:
...
Code Block | ||
---|---|---|
| ||
void onExchangeCompleted(@Observes @Default ExchangeCompletedEvent event) { // Called after the exchange 'event.getExchange()' processing has completed } |
In that example, if no qualifier is specified, the @Any
qualifier is implicitly assumed, so that corresponding events for all the Camel contexts get received.
...