Moving Camel Application Between OSGi and JavaEE Containers in Fuse
Here's a method for moving applications from OSGi to JavaEE containers and vice versa.
Join the DZone community and get the full member experience.Join For Free
Now that JBoss Fuse supports both OSGi Karaf and JavaEE JBoss EAP container. When should you use each? Is there any best practice for which container to use? It depends .... Situations vary between cases. Here are my point of view, you many like it or disagree, but I am happy to hear more of your thoughts.
I think it is BEST if you stick with Karaf containers if possible, for now. It is more lightweight, which means you can deploy applications much quicker and scale faster horizontally with applications distributed everywhere. OSGi manages the lifecycle of the services and allows you to dynamically deploy and undeploy services without affecting the others services in the same container. That is very important in for mission critical services. So if you can choose, go with Karaf.
I also think that an enterprise should not be restricted to using a single kind of container. Different container frameworks exist for a reason. Especially if you are providing a web application with EJB, JARs, and complex application glue to serve as the core business for the web application. Maybe it's a legacy application that has everything done in the Application server. Or it simply has too many non-OSGi compatible libraries to work with. Then I would go for the JBoss EAP scenario.
So how do you move from OSGi to JavaEE containers or vice versa? Moving a bundle from OSGi to JavaEE is dead simple. But please note, use the Spring framework instead of Blueprint if you are using OSGi, I would first convert it to Spring then work with it.
In this case, I will be using a WAR application, since most people use this format in JavaEE and it is supported in Karaf as well.
So there are few ground rules if you want to switch back and forth between the containers:
- Use Spring Framework
- Make sure your Camel route is placed under META-INF under webapp and named *-camel-context.xml
- Set your plugins to generate the metadata needed for OSGi containers.
- Add maven-bundle-plugin
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.3.7</version> <extensions>true</extensions> <executions> <execution> <id>bundle-manifest</id> <phase>process-classes</phase> <goals> <goal>manifest</goal> </goals> </execution> </executions> <configuration> <supportedProjectTypes> <supportedProjectType>jar</supportedProjectType> <supportedProjectType>bundle</supportedProjectType> <supportedProjectType>war</supportedProjectType> </supportedProjectTypes> <instructions> <Bundle-SymbolicName>camel-blueprint</Bundle-SymbolicName> <Private-Package>com.redhat.springtest</Private-Package> <Import-Package>*</Import-Package> </instructions> </configuration> </plugin>
By sticking with these rules, it will allow you to create a project that can deploy on both containers.
In the JBoss Fuse Karaf Container,
- Install with Profile or using an OSGi command
- Make sure to have feature-fabric-web profile in your container
Running JBoss EAP Container with Fuse application.
- Deploy and install by
- Drag and dropping the WAR file under the deployment folder
- Using Console/CLI deployment
- Make sure the Fuse subsystem is installed and activated.
- Remember to disable ContextLoaderListener in web.xml
Here is a video showing how to move an application between containers.
Published at DZone with permission of Christina Lin, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.