Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Chapter 12. Service Component Runtime
Abstract Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Service Component Runtime (SCR) is an implementation of OSGi Declarative Services specification. It enables any plain old Java object to expose and use OSGi services with no boilerplate code.
Working with Camel and SCR Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Apache Camel SCR component provides an integration of Camel with the OSGi Service Component Runtime.
OSGi framework has ability to know the object by looking at SCR descriptor file in its bundle which are generated from Java annotations by a plugin such as
org.apache.felix:maven-scr-plugin
. Using SCR, the bundle remains completely in Java world. There is no need to edit XML
or properties file. It offers you full control over the project.
Creating a Service Component Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Following are the steps to create a service component out of your java class.
- Add the required
org.apache.felix.scr.annotations
at class level. For example,Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Implement the
getRouteBuilders()
method that returns the Camel route you want to run. For example,Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Finally, enter the default configuration in annotations.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Example of a Service Component class Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The following example illustrates the use of
camel-archetype-scr
to generate a complete service component class:
Example of a RouteBuilder class Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The following example illustrates the use of
camel-archetype-scr
to generate a RouteBuilder
class:
Using Apache Camel SCR bundle as a template Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
If you have a Camel SCR bundle that implements an integration pattern that you use frequently, then, probably there is no need to create a separate bundle for every instance.
The following example illustrates how to use a Camel SCR bundle as a template. It includes the following steps:
- Create a configuration PID for your service component and add a tail with a dash.
- Camel SCR will use the configuration to create a new instance of your component.
- Finally, you can start a new
CamelContext
with your overridden properties.Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteMake sure that your service component does not start with the default configuration. To prevent this, addpolicy = ConfigurationPolicy.REQUIRE
to the class level at component annotation.
Using Apache camel-archetype-scr Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
With the help of Apache
camel-archetype-scr
and maven, you can easily create Apache Camel SCR bundle project. It includes the following steps:
- Run the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Run Apache Maven.NoteFor details on setting up Apache Maven to work with Red Hat JBoss Fuse, see Building with Maven in Red Hat JBoss Fuse Deploying into the Container on the Red Hat Customer Portal
- You can now deploy the bundle. To deploy the bundle on Apache Karaf, perform the following steps on Karaf command line:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - By default, the Service Component's configuration PID equals the fully qualified name of its class. You can change the properties of a bundle with Apache Karaf's config.* commands:You can also change the configuration by editing the property file in Apache Karaf's
Override the messageOk property
# Override the messageOk property karaf@root> config:propset -p example.CamelScrExample messageOk "This is better logging".
Copy to Clipboard Copied! Toggle word wrap Toggle overflow etc
directory.