Skip to content

Commit

Permalink
(apache#56) Update generic advanced usage examples for kamelets
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiesler committed Jun 5, 2024
1 parent eceb122 commit cbd23f9
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 108 deletions.
28 changes: 15 additions & 13 deletions generic-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ This folder contains various examples of `Camel K` integrations. You can use the

## Basic usage examples

In this section you will find the most basic examples. Useful to start learning about Camel K and how to run. You can use many supported languages and learn about the most basic features:
In this section you will find the most basic examples. Useful to start learning about Camel K and how to run.
You can use many supported languages and learn about the most basic features:

| Type | Description | Link |
|-------------------|---------------------------------------------------------------------------------------------------|--------------------------------|
Expand All @@ -21,7 +22,8 @@ In this section you will find the most basic examples. Useful to start learning

## Component usage examples

In this section you can find a few examples of certain [`Camel` components](https://camel.apache.org/components/latest/index.html). This is a limited number of the wide variety of components supported by Apache Camel. You can also find useful examples [in this repository](https://github.com/apache/camel-k-examples).
In this section you can find a few examples of certain [`Camel` components](https://camel.apache.org/components/latest/index.html). This is a limited number of the wide variety of components supported by Apache Camel.
You can also find useful examples [in this repository](https://github.com/apache/camel-k-examples).

| Type | Description | Link |
|------------|-----------------|------------------------------|
Expand All @@ -35,17 +37,17 @@ In this section you can find a few examples of certain [`Camel` components](http

## Advanced usage examples

As soon as you will learn the basic stuff, you will like to try the new advanced feature offered by Camel K. Here a few examples:

| Type | Description | Link |
|----------|-----------------------------------------------------------------------------------------|-----------------------------|
| Kamelets | How to use [`Kamelet`s](https://camel.apache.org/camel-k/latest/kamelets/kamelets.html) | [see examples](./kamelets/) |
| Master | Master support example | [see examples](./master/) |
| OLM | OPERATOR Lifecycle manager installation example | [see examples](./olm/) |
| Polyglot | Polyglot integration examples | [see examples](./polyglot/) |
| Pulsar | Pulsar usage | [see examples](./pulsar/) |
| Saga | Saga pattern example | [see examples](./saga/) |
| Tekton | Tekton tutorial | [see examples](./tekton/) |
When you feel comfortable with basic stuff, you may want to try the more advanced features offered by Camel K. Here a few examples:

| Type | Description | Link |
|----------|---------------------------------------------------------------------------------------|-----------------------------|
| Kamelets | How to use [Kamelets](https://camel.apache.org/camel-k/latest/kamelets/kamelets.html) | [see examples](./kamelets/) |
| Master | Master support example | [see examples](./master/) |
| OLM | OPERATOR Lifecycle manager installation example | [see examples](./olm/) |
| Polyglot | Polyglot integration examples | [see examples](./polyglot/) |
| Pulsar | Pulsar usage | [see examples](./pulsar/) |
| Saga | Saga pattern example | [see examples](./saga/) |
| Tekton | Tekton tutorial | [see examples](./tekton/) |

## Traits usage examples

Expand Down
2 changes: 1 addition & 1 deletion generic-examples/amqp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cluster before starting the example.

- [`AmqpConnectionBeanProducer.java`](./AmqpConnectionBeanProducer.java) defines a route that generates a message every second and sends it to an amqp queue.
- [`AmqpConnectionBeanConsumer.java`](./AmqpConnectionBeanConsumer.java) consumes messages from the amqp queue, logs them to the logger using the info level
- [`amqp.groovy`](./amqp.groovy) generates a message every second and sends to amqp topic
- [`amqp.yaml`](./amqp.yaml) generates a message every second and sends to amqp topic
- [`amqp.properties`](./amqp.properties) holds required credentials to connect to broker.

## Running the Example
Expand Down
2 changes: 1 addition & 1 deletion generic-examples/cron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ In order to follow this example:
## Understanding the Example
This example uses the cron component to trigger a route at a specific time interval specified in a cron expression. The route transforms data from the cron source and sends it to the logger.

The integration is all contained in a single file named `cron.groovy`
The integration is all contained in a single file named `cron.yaml`

## Running the Example

Expand Down
19 changes: 0 additions & 19 deletions generic-examples/kamelets/chuck-norris/chuck.xml

This file was deleted.

23 changes: 23 additions & 0 deletions generic-examples/kamelets/chuck-norris/chuck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# camel-k: language=yaml

# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF 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.
# ---------------------------------------------------------------------------

- from:
uri: "kamelet:chuck-norris-source"
steps:
- to: "log:info"
5 changes: 3 additions & 2 deletions generic-examples/kamelets/chuck-norris/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ This example shows how you can use an out of the box Kamelet with your Camel app

This example uses the Chuck Norris Kamelet that periodically gets a joke from the Chuck Norris internet database.

A Camel routes is _coded_ in the `chuck.xml` file using the XML DSL that uses the Kamelet,
A Camel routes is _coded_ in the `chuck.yaml` file using the XML DSL that uses the Kamelet,
and log the result from the Kamelet to the console.

## Running the example

Just run the integration via:
```
$ kamel run chuck.xml
$ kamel run chuck.yaml
```

You should be able to see the new integration running after some time:
```
$ kamel get
Expand Down
26 changes: 15 additions & 11 deletions generic-examples/kamelets/kameletbindings/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# KameletBindings examples
# Kamelet Pipe examples

Find useful examples about how to use KameletBindings.
Find useful examples about how to use Pipes.

## Understanding the examples
- [env-var-writer.kamelet.yaml](./env-var-writer.kamelet.yaml): sink kamelet, logs specified env variables.
- [kb-env-vars.yaml](./kb-env-vars.yaml): kamelet binding, connects the _env-var-writer_ kamelet directly to a Camel URI, adds env variables to the integration container using the `environment` trait.
- [kb-log-trait-annotation.yaml](./kb-log-trait-annotation.yaml): kamelet binding, connects two Camel URIs, uses the `logging` trait to customize the integration behaviour.
- [kamelet-pipe-env-vars.yaml](./kamelet-pipe-env-vars.yaml): kamelet pipe, connects the _env-var-writer_ kamelet directly to a Camel URI, adds env variables to the integration container using the `environment` trait.
- [kamelet-pipe-log-trait-annotation.yaml](./kamelet-pipe-log-trait-annotation.yaml): kamelet pipe, connects two Camel URIs, uses the `logging` trait to customize the integration behaviour.

## Running the examples
### Timer-to-Log kamelet binding
First, we apply the kamelet used in this binding:

### Timer-to-Log kamelet pipe

First, we apply the sink kamelet used in this example:
```
kubectl apply -f env-var-writer.kamelet.yaml
```

Next, we apply the kamelet binding
Next, we apply the source kamelet that connects to the sink via a pipe
```
kubectl apply -f kb-env-vars.yaml
kubectl apply -f kamelet-pipe-env-vars.yaml
```
A _timer-to-log_ integration is created that implements the binding. To view the logs, run:
A _timer-to-log_ integration is created. To view the logs, run:
```
kamel log timer-to-log
...
Expand All @@ -27,11 +29,13 @@ kamel log timer-to-log
...
```

### Timer-2-Log-Annotation kamelet binding
### Timer-2-Log-Annotation kamelet pipe

Apply the kamelet binding:
```
kubectl apply -f kb-log-trait-annotation.yaml
kubectl apply -f kamelet-pipe-log-trait-annotation.yaml
```

A _timer-2-log-annotation_ integration is created that implements the binding. You should see information logged at the `DEBUG` level. The messages should NOT use color. To view the logs:
```
kamel log timer-2-log-annotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
# ---------------------------------------------------------------------------

apiVersion: camel.apache.org/v1alpha1
apiVersion: camel.apache.org/v1
kind: Kamelet
metadata:
name: env-var-writer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
# Apply kamelet binding
# kubectl apply -f kb-env-vars.yaml
#
apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: timer-to-log
annotations:
Expand All @@ -33,5 +33,5 @@ spec:
sink:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
apiVersion: camel.apache.org/v1
name: env-var-writer
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# limitations under the License.
# ---------------------------------------------------------------------------

apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: timer-2-log-annotation
annotations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
# ---------------------------------------------------------------------------

apiVersion: camel.apache.org/v1alpha1
apiVersion: camel.apache.org/v1
kind: Kamelet
metadata:
name: log-sink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# limitations under the License.
# ---------------------------------------------------------------------------

apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: log-event-sink
spec:
Expand All @@ -28,5 +28,5 @@ spec:
sink:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
apiVersion: camel.apache.org/v1
name: log-sink
17 changes: 9 additions & 8 deletions generic-examples/kamelets/timer-source-log-sink/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This example shows how to create a simple timer `event source` and a log `event sink`. The timer events emitted are consumed by a simple logging connector which will print out those events.

## Additional requirement for running this example

- You should have Knative properly installed on your cluster ([see installation guide](https://knative.dev/docs/install/))

## Create events source and sink
Expand All @@ -15,11 +16,11 @@ $ kubectl apply -f log-sink.kamelet.yaml

You can check the newly created `kamelet`s in the list.
```
$ kubectl get kamelets
$ kubectl get kamelets timer-source log-sink
NAME PHASE
log-sink Ready
timer-source Ready
log-sink Ready
```

## Create channel destination
Expand All @@ -31,17 +32,17 @@ $ kubectl apply -f timer-events.yaml

## Binding events

We can now bind the timer event source to produce events on the destination with the `timer-source.binding.yaml` configuration.
We can now bind the timer event source to produce events on the destination with the `timer-source.pipe.yaml` configuration.
```
$ kubectl apply -f timer-source.binding.yaml
$ kubectl apply -f timer-source.pipe.yaml
```
In a similar fashion you can bind to the log sink in order to consume those events with the `log-sink.binding.yaml` configuration.
In a similar fashion you can bind to the log sink in order to consume those events with the `log-sink.pipe.yaml` configuration.
```
$ kubectl apply -f log-sink.binding.yaml
$ kubectl apply -f log-sink.pipe.yaml
```
You can check the newly created bindings listing the `KameletBidings`.
You can check the newly created bindings listing the `Pipes`.
```
$ kubectl get KameletBindings
$ kubectl get Pipes
NAME PHASE
log-event-sink Ready
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
# ---------------------------------------------------------------------------

apiVersion: camel.apache.org/v1alpha1
apiVersion: camel.apache.org/v1
kind: Kamelet
metadata:
name: timer-source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# limitations under the License.
# ---------------------------------------------------------------------------

apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: timer-event-source
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
apiVersion: camel.apache.org/v1
name: timer-source
properties:
message: "Hello world!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# limitations under the License.
# ---------------------------------------------------------------------------

apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: timer-source
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
apiVersion: camel.apache.org/v1
name: timer-source
properties:
message: "Hello world!"
Expand Down
Loading

0 comments on commit cbd23f9

Please sign in to comment.