Camel 3.x: Disable automatic registration of routes - apache-camel

I have been trying to migrate from Camel 2.x to 3.x and having some issues with Spring Boot integration.
With Camel 2.x, i managed to disable auto injection of RouteBuilder instances annotated with #Component but have the other benefits, camel-spring provides. I do that since i have a prototype bean that extends from RouteBuilder and i manually add them to camel context as required.
With Camel 3.x, i can't do that. I can't remove #Component annotation from the class since i need Spring to inject other dependencies to class. Is there a way do that with Camel 3.x?

Auto-discovery and registration of RouteBuilder instances to CamelContext can be disabled with property camel.springboot.routes-collector-enabled=false.
See Camel Spring Boot docs:
camel.springboot.routes-collector-enabled
Whether the routes collector is enabled or not. When enabled Camel will auto-discover routes (RouteBuilder instances from the registry and also load additional XML routes from the file system. The routes collector is default enabled.

To disable Camel auto configuration (for example in tests)
#EnableAutoConfiguration(exclude = CamelAutoConfiguration.class)

Related

Use of #Provider and #Component in CXF

Can anyone explain about #Provider and #Component and when we need to use in Apache CXF for both Rest and Soap Implementation ?
There are two #Provider annotations, a JAX-RS standard annotation and a native CXF provider annotation. You can use them to mark a provider, it will be auto-discovered depending on the setup you use. #Component is a Spring annotation and can be used as an alternative.
If you are using a Spring Boot based setup see http://cxf.apache.org/docs/springboot.html for the different scanning options.

How to reload camel context automatically in openshift 3.x using fis-java

I have previous experience in Apache Camel and JBoss Fuse and I am new to Openshift version 3.x I am trying to deploy a camel application which is developed using java dsl and spring DI.
I am using an external properties file to load the consumer and producer endpoint in camel.In JBoss Fuse I used the configAdmin services with the update-stratergy=reload as shown below in my blueprint.xml
<!-- OSGI blueprint property placeholder -->
<cm:property-placeholder id="routesConfig" persistent-id="org.sample.camel.routes.config" update-strategy="reload"/>
The above configuration will reload the camelContext automatically when there is a change in the properties file
How can I achieve the same functionality using fis-java-openshift:1.0 template image in openshift 3.x
We wrote some docs on how to work with configuration.
Generally speaking on kubernetes the use of service discovery and kubernetes secrets avoids most of the use cases for environment specific configuration.
Ideally we would use the same Continuous Delivery pipelines to change code or configuration to ensure things are properly tested before they hit production.
However if you really really want to reload configuration on the fly in Java containers you can store configuration in a ConfigMap and mount it as a file inside the pod; then have the Java code watch the file (eg with spring boot or ConfigAdmin).

Apache Camel - CXF: general endpoint's customer configuration

I have many WSDL(>100) files in my projects (many WS java interfaces generated). I want to use general configuration for cxf endpoints, not to configure many endpoints in camel xml configuration file for each ws.
<cxf:cxfEndpoint id="orderEndpoint"
address="http://localhost:9000/order/"
serviceClass="camelinaction.order.OrderEndpoint"/>
Is it any other way to configure camel cxf endpoint without manually adding it to xml file for each ws?
Is it possible to use some camel annotations in generated interfaces (automatically)?
There is no Camel annotation to auto-discover JAX-WS interfaces in the classpath and load them as CXF endpoints. That's something too specific to your usecase.
What you can do is use programmatic Spring configuration to register the endpoints in the Spring registry which Camel then uses to resolve endpoints.
Create a class and annotate it with #Configuration and make it implement BeanDefinitionRegistryPostProcessor in order to get a callback along with a BeanDefinitionRegistry which will allow you to add new beans to the registry. Find an example here: Spring - Programmatically generate a set of beans (answer 2).
So now that you have the means to register new beans, you'll need to find the JAX-WS endpoints by searching your classpath. This SO question lists several alternatives: Find Java classes implementing an interface. Since you're using Spring, I would suggest you try out this one.
You'll need to define a technique to generate the bean name and the URL in a meaningful and predictable way, so you can access the bean from the Camel route, and the endpoint from the outside.
Don't forget enabling <context:component-scan /> in your Spring XML to instruct Spring to search Java classes for components.
P.S.: This does not require you to use the Java DSL of Camel. You're simply using Java code to introspect the classpath and dynamically inject the appropriate beans into the Spring registry.
You can use Java DSL (rather than Spring XML) to declare your endpoints programmatically. See the question Apache Camel: RouteBuilder with CxfEndpoint for an example.
Dynamically discovering all of your web services is a separate issue, with many different possible solutions (such as naming conventions, implementing a shared interface, annotation processing).

Is there a way to programmatically find the available CamelContext

I am running Camel inside PlayFramework and it all works pretty well but when the Play server is running in development mode it does dynamically class reloading but it starts a new Camel context each time.
I can hook into Play restart and shut down the Camel context by calling stop() on the CamelContext but I would prefer to be able to check if there is already a context running and if so just use that.
This must be possible as hawtio shows me a list of the camel contexts.
I don't use spring to configure camel.
You can use JMX to see what other CamelContext's are in the JVM mbean server. This is what hawtio uses to detect which Camel's are running in the JVM.
As alternative you may fiddle with Container spi to have events when a CamelContext is created. But this requires a way to hook into this: https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/spi/Container.java

How to check if a NMR endpoint exists in servicemix?

I use dynamic routing my integration project, which may be multiple camel contexts.
I can see if there is an endpoint in one camel context:
getContext.hasEndpoint("nmr:targetEndpoint")!=null
But it does not work if the endpoint is in another camel context...

Resources