How do I access blueprint beans from camel during bundle shutdown - apache-camel

I have a blueprint bundle containing several beans referenced by some Camel routes. When I stop the bundle (directly or by asking Karaf to terminate) the BluePrint container is destroyed almost immediately.
Meanwhile the Camel DefaultShutdownStrategy will wait for my inflight exchanges to complete. At this point any attempt to resolve a bean reference from Camel will fail (as the BlueprintContainer where the beans are registered has been destroyed), and I'll get a org.apache.camel.NoSuchBeanException.
Is there a way to keep the BluePrint registry alive until Camel has finished shutting down?
My environment is Karaf 4.1.1/Camel 2.18.3/Java 8/Windows.

Related

camel blueprint force usage of log4j

Has anyone been able to use camel-blueprint together with logback? It seems that there are dependencies in camel blueprint which forces you to use log4j even though the log4j dependencies are removed from the pom. After running the project it starts to download the slf4j-log4j12 and then then complains of multiple bindings because it finds both log4j and logback.
I did the same with a camel java project and it worked fine to switch to logback. Does camel-blueprint force you to use log4j as its logging implementation?
Answer found via nabble forum in through discussion with the camel community. For more details go here:
http://camel.465427.n5.nabble.com/camel-blueprint-force-usage-of-log4j-td5772826.html#a5772852
Essentially there are certain dependencies in the maven plugin which uses log4j. For production in JBoss Fuse or Karaf, its Pax logging.

deploying camel java-archetype projec to Fuse 6.2

I have created a java-archetype project for Camel. It is a simple REST hello world to receive a get request and return a string body. When I run this as Java application from Eclipse it works as intended.
When I take the jar and deploy it the Fuse "deploy" folder I can see in the logs that the bundle has started. The state is active and green. However the Camel tab does not appear.
The same works if I use blueprint but does not seem to do so using the java dsl. Is there an extra magic code you need to add for Fuse to pick up the camel context? Thanks
Yes for OSGi to startup you can use a spring or blueprint with a <camelContext> that starts Camel. If you use pure Java code you have to fight with OSGi and use an OSGI activator and setup all kind of OSGi stuff that gets you tiresome.
So add a blueprint xml file and add the <camelContext> and then you can refer to Java route builders, just as you can when doing spring xml: http://camel.apache.org/spring.html

How to control order of deployment (EJB first and then MBeans deployment) in Wildfly 8.2.0 AS

I am migrating an EAR application containing MBeans from JBoss 6 AS to Wildfly 8.2.0 AS. In my EAR application, MBeans depend on EJB before initialization.
In JBoss 6 AS, #DependsOn annotation used in MBean maintained the sequence of the deployment i.e. Dependent EJB gets deployed and then, MBean gets deployed.
In Wildfly 8.2.0, I am trying to implement the same and #DependsOn is not working.
I tried the below in jboss-service.xml to have MBeans deployed only after the deployment of EAR file but this did not happen.
<mbean code="sample.HelloWorldService" name="sample:service=HelloWorld,id=1">
<depends>jboss.j2ee:service=EARDeployment,url='application.ear'</depends>
</mbean>
I also tried #startup in EJB but I cannot control the sequence i.e. 1. EJB deployment 2. MBeans deployment.
Can anyone please help about how to control the order of deployment in Wildfly 8.2.0. I need to deploy EJB first and then MBeans. Many thanks.
Just a comment
About the EJB that you want to get from the MBeans, maybe you are misunderstanding the specificaction of jboss-deployment-structure.xml. It express an initialization dependency between singleton components (even if the related EJB are singleton be aware about possible problems with DependsOn like WLFY-4251).
Workaround
Due to you are working with Jboss/Wildfly Server, you have the option to use the jboss-deployment-structure.xml for specify dependency between modules.
Perhaps, as your are packing all in the same EAR application, you can separate the components into modules, let's say one MBean.sar module that contains the MBeans and other RelatedEJBs.jar module with the EJBs referenced by your MBeans.
Then you define the next dependency of MBeans.sar over RelatedEJBs.jar,
<jboss-deployment-structure>
...
<sub-deployment name="RelatedEJBs.jar">
...
</sub-deployment>
<sub-deployment name="MBeans.sar">
<dependencies>
<!-- Adds a dependency on the ejb jar. This could also be done with a Class-Path entry -->
<module name="deployment.YouApp.ear.RelatedEJBs.jar" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
Edit: A useful migration guide to Wildfly.

ServiceMix and Camel OSGi Properties Component

Is there a Camel Properties Component feature to install in ServiceMix? Because I can't find it so I can't load my OSGi bundle.
Caused by: java.lang.ClassNotFoundException:
org.apache.camel.component.properties.PropertiesComponent not found from bundle [my-camel-osgi-bundle]
How can I install the Camel Properties Component feature in Apache ServiceMix?
Thank you in advance!
Camel Properties component is came with camel-core.
I think you just need to check your camel osgi bundle sets the import packages rightly.

ServiceMix (FuseESB) fails to find Camel javascript support when jar starts up

When deploying a Camel route to FuseESB, as FuseESB tries to start up the jar file, it gives the following exception in the log:
Found initial references null for OSGi service (&(language=js)
(objectClass=org.apache.camel.spi.LanguageResolver))
This causes the bundle to enter a grace period for a few minutes, after which it times out and its status moves to failed. Note that I'm not using javascript in the application, but I assume it is loaded as part of loading Camel core.
Details of my setup:
Code in question is written using an OSGi blueprint xml file to define the beans.
Code is packaged as a jar, as opposed to an OSGi bundle.
Code is deployed by being dropped into the deploy directory so it is deployed by the FAB deployer.
I believe I have the relevant Camel features installed.
Output from features:list:
[installed ] [2.10.0.fuse-71-047] camel-script-javascript camel-2.10.0.fuse-71-047
[installed ] [2.10.0.fuse-71-047] camel-script camel-2.10.0.fuse-71-047
I have worked around this by:
reverting to a spring xml file to define the beans
packaging the code as a bundle, not a jar
I still don't understand why the Blueprint version didn't work, but the question is now less urgent than it was.
With FAB you should declare the dependencies to your Camel components in your pom.xml file, and use scope=provided.
See more details at: http://fuse.fusesource.org/bundle/overview.html

Resources