Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSFUSE-296: Provide example usage of properties from ConfigMap in Karaf quickstart #46

Merged
merged 1 commit into from Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions README.md
@@ -1,16 +1,25 @@
# Karaf Camel Log QuickStart

This quickstart shows a simple Apache Camel application that logs a message to the server log every 5th second.

This example is implemented using solely the XML DSL (there is no Java code). The source code is provided in the following XML file `src/main/resources/OSGI-INF/blueprint/camel-log.xml`.
This quickstart shows a simple Apache Camel application that logs a message taken from a Kubernetes ConfigMap to the server log every 5th second.
It also shows how Karaf assembly files can be overriden using resources from `src/main/resources/assembly/`. The included sample log file `etc/org.ops4j.pax.logging.cfg` sets the log level to DEBUG.

Before running the example you should create a ConfigMap named camel-log in Kubernetes with at least a single key named message.

* Kubernetes:
```
kubectl create configmap camel-log --from-literal=message=Hello
```

* OpenShift:
```
oc create configmap camel-log --from-literal=message=Hello
```

### Building

The example can be built with

mvn clean install
mvn clean install -Ddocker.skip


### Running the example in fabric8
Expand Down
13 changes: 1 addition & 12 deletions pom.xml
Expand Up @@ -33,9 +33,8 @@
<!-- configure the versions you want to use here -->
<camel.version>2.17.3</camel.version>
<karaf.version>2.4.4</karaf.version>
<karaf.plugin.version>4.0.5</karaf.plugin.version>
<karaf.plugin.version>4.0.6</karaf.plugin.version>
<fabric8.version>2.2.161</fabric8.version>
<kubernetes-client.version>1.3.72</kubernetes-client.version>

<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version>
Expand Down Expand Up @@ -115,13 +114,6 @@
<classifier>features</classifier>
<type>xml</type>
</dependency>
<dependency>
<groupId>io.fabric8.kubernetes</groupId>
<artifactId>kubernetes-karaf</artifactId>
<version>${kubernetes-client.version}</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-karaf-features</artifactId>
Expand Down Expand Up @@ -206,8 +198,6 @@
<feature>jaas</feature>
<feature>aries-blueprint</feature>
<feature>camel-blueprint</feature>
<feature>kubernetes-client</feature>
<feature>openshift-client</feature>
<feature>fabric8-karaf-blueprint</feature>
</startupFeatures>
<startupBundles>
Expand All @@ -220,7 +210,6 @@
-->
<feature>static</feature>
</blacklistedFeatures>
<blacklistPolicy>Discard</blacklistPolicy>
<libraries>
<library>
mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.boot/${karaf.version};type:=boot;export:=true;delegate:=true
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/io/fabric8/quickstarts/camel/log/MyBean.java
@@ -0,0 +1,28 @@
/**
* Copyright 2005-2016 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version
* 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package io.fabric8.quickstarts.camel.log;

public class MyBean {
private final String message;

public MyBean(String message) {
this.message = message;
}

public String getMessage() {
return message;
}
}
68 changes: 40 additions & 28 deletions src/main/resources/OSGI-INF/blueprint/camel-log.xml
Expand Up @@ -23,34 +23,46 @@
The root element for any OSGi Blueprint file is 'blueprint' - you also see the namespace definitions for both the Blueprint
and the Camel namespaces.
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

<!--
The namespace for the camelContext element in Blueprint is 'http://camel.apache.org/schema/blueprint'.

While it is not required to assign id's to the <camelContext/> and <route/> elements, it is a good idea
to set those for runtime management purposes (logging, JMX MBeans, ...)
-->
<camelContext id="log-example-context" xmlns="http://camel.apache.org/schema/blueprint" >

<!--
A very simple Camel route, that uses a timer to trigger a message every 5 second.

The <setBody> sets a body into the Camel Message.

The <log/> elements are used to add human-friendly business logging statements. They make it easier to see what the
route is doing.
-->
<route id="log-route">
<from uri="timer:foo?period=1s"/>
<setBody>
<simple>Hello from Camel!</simple>
</setBody>
<log message=">>> ${body} : ${id}"/>
</route>
</camelContext>
http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint
http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.3.0
http://aries.apache.org/schemas/blueprint-ext/blueprint-ext-1.3.xsd">

<ext:property-placeholder evaluator="fabric8" placeholder-prefix="$[" placeholder-suffix="]"/>

<bean id="myBean" class="io.fabric8.quickstarts.camel.log.MyBean">
<argument value="$[k8s:map:camel-log/message]"/>
</bean>

<!--
The namespace for the camelContext element in Blueprint is 'http://camel.apache.org/schema/blueprint'.

While it is not required to assign id's to the <camelContext/> and <route/> elements, it is a good idea
to set those for runtime management purposes (logging, JMX MBeans, ...)
-->
<camelContext id="log-example-context" xmlns="http://camel.apache.org/schema/blueprint" >

<!--
A very simple Camel route, that uses a timer to trigger a message every 5 second.

The <setBody> sets a body into the Camel Message.

The <log/> elements are used to add human-friendly business logging statements. They make it easier to see what the
route is doing.
-->
<route id="log-route">
<from uri="timer:foo?period=1s"/>
<setBody>
<method ref="myBean" method="message"/>
</setBody>
<log message=">>> ${body} : ${id}"/>
</route>
</camelContext>

</blueprint>