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.此内容没有您所选择的语言版本。
13.4. Integration with Apache Camel
Overview 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Apache Camel provides a simple way to invoke OSGi services using the Bean language. This feature is automatically available whenever a Apache Camel application is deployed into an OSGi container and requires no special configuration.
Registry chaining 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
When a Apache Camel route is deployed into the OSGi container, the
CamelContext
automatically sets up a registry chain for resolving bean instances: the registry chain consists of the OSGi registry, followed by the blueprint (or Spring) registry. Now, if you try to reference a particular bean class or bean instance, the registry resolves the bean as follows:
- Look up the bean in the OSGi registry first. If a class name is specified, try to match this with the interface or class of an OSGi service.
- If no match is found in the OSGi registry, fall back on the blueprint registry (or the Spring registry, if you are using the Spring-DM container).
Sample OSGi service interface 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Consider the OSGi service defined by the following Java interface, which defines the single method,
getGreeting()
:
Sample service export 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
When defining the bundle that implements the
HelloBoston
OSGi service, you could use the following blueprint configuration to export the service:
Where it is assumed that the
HelloBoston
interface is implemented by the HelloBostonImpl
class (not shown).
Invoking the OSGi service from Java DSL 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
After you have deployed the bundle containing the
HelloBoston
OSGi service, you can invoke the service from a Apache Camel application using the Java DSL. In the Java DSL, you invoke the OSGi service through the Bean language, as follows:
from("timer:foo?period=5000") .bean(org.fusesource.example.hello.boston.HelloBoston.class, "getGreeting") .log("The message contains: ${body}")
from("timer:foo?period=5000")
.bean(org.fusesource.example.hello.boston.HelloBoston.class, "getGreeting")
.log("The message contains: ${body}")
In the
bean
command, the first argument is the OSGi interface or class, which must match the interface exported from the OSGi service bundle. The second argument is the name of the bean method you want to invoke. For full details of the bean
command syntax, see section "Bean Integration" in "Apache Camel Development Guide".
Note
When you use this approach, the OSGi service is implicitly imported. It is not necessary to import the OSGi service explicitly in this case.
Invoking the OSGi service from XML DSL 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
In the XML DSL, you can also use the Bean language to invoke the
HelloBoston
OSGi service, but the syntax is slightly different. In the XML DSL, you invoke the OSGi service through the Bean language, using the method
element, as follows:
Note
When you use this approach, the OSGi service is implicitly imported. It is not necessary to import the OSGi service explicitly in this case.