...
Code Block |
---|
|
class MyRouteBean extends RoutesBuilder {
@Override
public void configure() {
from("direct:inbound")
jms:invoices").to("file:/invoices");
}
} |
Note that you can declare as many RoutesBuilder
beans as you want. Besides, RouteContainer
beans are also automatically collected, instantiated and added to the CamelContext
bean instance managed by Camel CDI when the container initialises.
Custom Camel context customisation
If you just want to change the name of the default CamelContext
bean, you can used the @ContextName
qualifier provided by Camel CDI, e.g.:
Code Block |
---|
|
@ContextName("camel-context")
class MyRouteBean extends RoutesBuilder {
@Override
public void configure() {
from("jms:invoices").to("file:/invoices");
}
} |
Else, if more customisation 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 customisation, e.g.:
Code Block |
---|
|
@ApplicationScoped
class CustomCamelContext extends DefaultCamelContext {
@PostConstruct
void customize() {
// Set the Camel context name
setName("custom");
// Disable JMX
disableJMX();
}
@PreDestroy
void cleanUp() {
// ...
}
} |
Producer and disposer methods can also be used as well to customize the Camel context bean, e.g.:
Code Block |
---|
|
class CamelContextFactory {
@Produces
@ApplicationScoped
CamelContext customize() {
DefaultCamelContext context = new DefaultCamelContext();
context.setName("custom");
return context;
}
void cleanUp(@Disposes CamelContext context) {
// ...
}
} |
Similarly, producer fields can be used, e.g.:
Code Block |
---|
|
@Produces
@ApplicationScoped
CamelContext context = new CustomCamelContext();
class CustomCamelContext extends DefaultCamelContext {
CustomCamelContext() {
setName("custom");
}
} |
This pattern can be used for example to avoid having the Camel context routes started automatically when the container initialises by calling the setAutoStartup
method, e.g.:
Code Block |
---|
|
@ApplicationScoped
class ManualStartupCamelContext extends DefaultCamelContext {
@PostConstruct
void manual() {
.to("mock:outbound"setAutoStartup(false);
}
} |
Custom Camel context customisation
...
Multiple Camel contexts support
...