Merge pull request #53 from jbonofre/K5-46 [K5-46] Upgrade to Apache Camel 3.17.0
Apache Karaf is an application runtime. Karaf is able to operate different kind of applications using application manager services.
It provides extensible launchers per application kind and out of the box services that any application running on Karaf can leverage without cost.
Apache Karaf is composed by:
Karaf) bootstraps the runtimes for your applications, the runtimes are discovered and extensibleKaraf boot can be described/configure programmatically or by a provided JSON file.
Karaf boot is the main runtime orchestrator. It basically loads Karaf Services via SPI, and it's configured via KarafConfig.
KarafConfig can be provided programmatically:
KarafConfig config = new KarafConfig(); ... Karaf karaf = Karaf.build(config); karaf.init(); karaf.start();
or loaded from an external resource like karaf.json:
{
"properties": {
"foo": "bar"
},
"applications": [
{
"url": "/path/to/my/jar"
}
]
}
Karaf Boot is looking for karaf.json file (aka Karaf Config):
-Dkaraf.config=/path/to/karaf.jsonexport KARAF_CONFIG=/path/to/karaf.jsonA Karaf Services is a class implementing the org.apache.karaf.boot.spi.Service interface, and loaded via META-INF/services/org.apache.karaf.boot.spi.Service, containing the FQDN of the implementation class.
The service doesn't have to implement any method by default. Optionally, you can define the following methods:
public class MyService implements org.apache.karaf.boot.spi.Service { @Override public String name() { // return the service name return "my-service"; } @Override public void onRegister(ServiceRegistry serviceRegistry) throws Exception { // callback method, called when the service is registered in the Karaf Service Registry // you can interact with the Karaf Service Registry `serviceRegistry` here, looking for services, etc } @Override public int priority() { // return the service priority, default is 1000. Lower priority are started before higher priority. return 1001; } }
Karaf Boot provides a runtime with:
ServiceRegistry) where all services will be locatedKarafConfigService) loads Karaf configKarafLifeCycleService) is responsible to callback start and stop methods from the servicesThen, org.apache.karaf.boot.Karaf launcher can start (Karaf.builder().build().start()) all Karaf services located in the classloader, you can repackage all dependencies (jar) in a single uber jar.
Karaf itself provides several “core” services:
classpath: protocol handlerServices can also deploy “third party” applications, for instance:
Karaf Services can be configured via the properties, using the service name as prefix.
You can configure launcher in karaf.json:
"properties": {
"osgi.storageDirectory": "/path/to/storage",
"spring-boot.cache": "/path/to/cache
},
Each service is responsible to retrieve the KarafConfig service from the service registry, and get the properties.
When you use a third party application manager service, you can define the applications you want to deploy via KarafConfig service.
For instance, you can use the following karaf.json configuration file:
{ "properties": { "osgi.storageDirectory": "path/to/store", "osgi.cache": "path/to/cache" }, "applications": [ { "url": "https://repo1.maven.org/maven2/commons-lang/commons-lang/2.6/commons-lang-2.6.jar", "type": "osgi" } ] }
Here, you can see how to configure and deploy commons-lang-2.6.jar in the OSGi application manager.
You can use Apache Karaf in your code, simply bootstrapping it and running with:
Karaf karaf = Karaf.build(karafConfig); karaf.init(); karaf.start();
or simply run with a karaf.json:
$ java -jar karaf.jar -Dkaraf.config=karaf.json
Karaf is launching all you describe in the karaf.json.