Skip to content

Commit

Permalink
(apache#56) Update generic - basic usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiesler committed May 23, 2024
1 parent d3046ab commit 338429d
Show file tree
Hide file tree
Showing 76 changed files with 931 additions and 1,130 deletions.
72 changes: 36 additions & 36 deletions generic-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,54 @@ This folder contains various examples of `Camel K` integrations. You can use the

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 |
|---|---|---|
| Languages | Simple integrations developed in various supported languages | [see examples](./languages/)|
| Env | Set and use env variables in an integration | [see examples](./env/)|
| Cron | How to create a `cron` integration | [see examples](./cron/)|
| User Config | Explore how to include a `property`, `secret`, `configmap` or file `resource` in your integration | [see examples](./user-config/)|
| User Dependencies | Explore how to include a local dependency in your integration with Jitpack | [see examples](./jitpack/)|
| Processor | Show how to include `Processor`s logic | [see examples](./processor/)|
| Open API | `Open API` support | [see examples](./openapi/)|
| Rest | Produce/Consume `REST`ful services | [see examples](./rest/)|
| Modeline | [Camel K modeline support](https://camel.apache.org/camel-k/latest/cli/modeline.html) | [see examples](./modeline/)|
| Volumes | Produce/Consume files attached to a `PVC` | [see examples](./volumes/)|
| Type | Description | Link |
|-------------------|---------------------------------------------------------------------------------------------------|--------------------------------|
| Languages | Simple integrations developed in various supported languages | [see examples](./languages/) |
| Env | Set and use env variables in an integration | [see examples](./env/) |
| Cron | How to create a `cron` integration | [see examples](./cron/) |
| User Config | Explore how to include a `property`, `secret`, `configmap` or file `resource` in your integration | [see examples](./user-config/) |
| User Dependencies | Explore how to include a local dependency in your integration with Jitpack | [see examples](./jitpack/) |
| Processor | Show how to include `Processor`s logic | [see examples](./processor/) |
| Open API | `Open API` support | [see examples](./openapi/) |
| Rest | Produce/Consume `REST`ful services | [see examples](./rest/) |
| Modeline | [Camel K modeline support](https://camel.apache.org/camel-k/latest/cli/modeline.html) | [see examples](./modeline/) |
| Volumes | Produce/Consume files attached to a `PVC` | [see examples](./volumes/) |

## 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).

| Type | Description | Link |
|---|---|---|
| AMQP | Component usage | [see examples](./amqp/)|
| Caffeine | Component usage | [see examples](./caffeine/)|
| Databases | Component usage | [see examples](./databases/)|
| DNS | Component usage | [see examples](./dns/)|
| HTTP/HTTPS | Component usage | [see examples](./http/)|
| Kafka | Component usage | [see examples](./kafka/)|
| Knative | Component usage | [see examples](./knative/)|
| Type | Description | Link |
|------------|-----------------|------------------------------|
| AMQP | Component usage | [see examples](./amqp/) |
| Caffeine | Component usage | [see examples](./caffeine/) |
| Databases | Component usage | [see examples](./databases/) |
| DNS | Component usage | [see examples](./dns/) |
| HTTP/HTTPS | Component usage | [see examples](./http/) |
| Kafka | Component usage | [see examples](./kafka/) |
| Knative | Component usage | [see examples](./knative/) |

## 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/)|
| 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/) |

## Traits usage examples

Traits configuration will be very helpful to fine tune your `Integration`. Here a few examples:

| Type | Description | Link |
|---|---|---|
| Container | How to customize with `container` trait| [see examples](./traits/container/)|
| Health | How to customize with `health` trait| [see examples](./traits/health/)|
| JVM | How to use `jvm` trait| [see examples](./traits/jvm/)|
| Tracing (opentracing) | How to use `tracing` trait| [see examples](./traits/tracing/)|
| Type | Description | Link |
|-----------------------|-----------------------------------------|-------------------------------------|
| Container | How to customize with `container` trait | [see examples](./traits/container/) |
| Health | How to customize with `health` trait | [see examples](./traits/health/) |
| JVM | How to use `jvm` trait | [see examples](./traits/jvm/) |
| Tracing (opentracing) | How to use `tracing` trait | [see examples](./traits/tracing/) |
40 changes: 9 additions & 31 deletions generic-examples/cron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ This example demonstrates how you can create cron routes in Camel K.

You can find more information about Apache Camel and Apache Camel K on the [official Camel website](https://camel.apache.org).


## Requirements for running this example

**Kubectl CLI**
Expand All @@ -16,19 +15,10 @@ You need to connect to a Kubernetes cluster in order to run the example.
**Apache Camel K CLI ("kamel")**
You need the Apache Camel K CLI ("kamel") in order to access all Camel K features.

### Optional Requirements

The following requirements are optional. They don't prevent the execution of the demo, but may make it easier to follow.

**VS Code Extension Pack for Apache Camel**
The [VS Code Extension Pack for Apache Camel](https://marketplace.visualstudio.com/items?itemName=redhat.apache-camel-extension-pack) provides a collection of useful tools for Apache Camel K developers,
such as code completion and integrated lifecycle management. They are **recommended** for the tutorial, but they are **not**
required.
You can install it from the VS Code Extensions marketplace.

## Preparing the cluster

In order to follow this example:
- Create a namespace called `camel-cron` and set that namespace as default.
- Create a namespace called `kubectl create ns camel-cron` and set that namespace as default `kubectl config set-context --current --namespace=camel-cron`.
- Install the Camel K operator in that namespace. In most cases, running `kamel install` should be enough. If not, you can read the [installation instructions for your specific cluster here](https://camel.apache.org/camel-k/latest/installation/installation.html).

## Understanding the Example
Expand All @@ -43,19 +33,10 @@ This example is a Camel K integration that is scheduled to run periodically, pri
Use the following command to run it:

```
kamel run cron.groovy
```

The build phase may take some seconds to complete. When it finishes, if everything is okay, the integration should be running periodically every minute. \
To view the logs of the running integration, run the command:

```
kamel log cron
kamel run --dev cron.yaml
```

You should see the Camel K integration start, print "Hello Camel K using CronJob" and shutdown periodically every minute in the terminal window.

You can terminate the log stream with `Ctrl+C`
The build phase may take some seconds to complete. When it finishes, if everything is okay, the integration should be running periodically every minute.

To confirm that the integration is being run as a Kubernetes Cronjob, run:

Expand All @@ -74,23 +55,18 @@ Hit `Ctrl+C` to exit

## Modifying the Cron expression

Run the integration in "dev mode" in order to see the logs in the terminal:
```
kamel run cron.groovy --dev
```

Since the integration is running in dev mode, you can change the integration code and Camel K will redeploy the changes automatically.

Change the cron expression: \
[open the `cron.groovy` file](./cron.groovy)
[open the `cron.yaml` file](./cron.yaml)
and change the first endpoint from `cron:tab?schedule=*+*+*+*+?` to `cron:tab?schedule=*/2+*+*+*+?`, then save the file.

You should see the new integration starting up in the terminal window and replacing the old one.
It should print "Hello Camel K using CronJob" once every 2 minutes in the terminal window. \
**Note:** *Cron only allows for a minimum of 1 minute apart between jobs*

Change the cron expression again: \
[open the `cron.groovy` file](./cron.groovy)
[open the `cron.yaml` file](./cron.yaml)
and change the first endpoint to `cron:tab?schedule=*/3+*+*+*+?`, then save the file.

Now, after a few seconds, it should print "Hello Camel K using CronJob" once every 3 minutes in the terminal.
Expand All @@ -99,7 +75,9 @@ Hit `Ctrl+C` to exit dev mode and terminate execution

## Uninstall

To cleanup everything, execute the following command:
To clean up everything, execute the following command:

```
kubectl config set-context --current --namespace=default
kubectl delete namespace camel-cron
```
22 changes: 0 additions & 22 deletions generic-examples/cron/cron.groovy

This file was deleted.

25 changes: 25 additions & 0 deletions generic-examples/cron/cron.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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: "cron:tab?schedule=*+*+*+*+?"
steps:
- setBody:
simple: "Hello Camel K using CronJob"
- to: "log:info?showAll=false"
2 changes: 1 addition & 1 deletion generic-examples/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ cluster before starting the example.

To both set the `MY_ENV_VAR` env variable to `hello world` and run the integration, execute the following:
```
kamel run --env MY_ENV_VAR="hello world" Env.java --dev
kamel run --dev --env MY_ENV_VAR="hello world" Env.java
```
You should see `hello world` logged to the terminal every second
6 changes: 3 additions & 3 deletions generic-examples/jitpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Once done, you just reference the project (dependency) in `kamel run -d` option,

You can choose to use the default dependency without specifying a tag or branch. That will fetch the source code on `main` branch:
```
kamel run Jitpack.java --dev -d github:squakez/samplejp
kamel run --dev -d github:squakez/samplejp Jitpack.java
```
Running the above command, should log `HELLO` to the terminal every 2 seconds:
```
Expand All @@ -54,7 +54,7 @@ Running the above command, should log `HELLO` to the terminal every 2 seconds:

You can choose to compile the source code stored on a given branch, ie, on `1.0.0` branch:
```
kamel run Jitpack.java --dev -d github:squakez/samplejp:1.0.0-SNAPSHOT
kamel run --dev -d github:squakez/samplejp:1.0.0-SNAPSHOT Jitpack.java
```
Executing the above command, should log `v1.0.0-SNAPSHOT:HELLO` to the terminal every 2 seconds:

Expand All @@ -67,7 +67,7 @@ Executing the above command, should log `v1.0.0-SNAPSHOT:HELLO` to the terminal

You can also choose to package the source code released with a `tag`, ie `v1.0`:
```
kamel run Jitpack.java --dev -d github:squakez/samplejp:v1.0
kamel run --dev -d github:squakez/samplejp:v1.0 Jitpack.java
```
Running the command above should log `v1.0.0:HELLO` to the terminal every 2 seconds:
```
Expand Down
20 changes: 19 additions & 1 deletion generic-examples/modeline/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Modeline Camel K examples

Find useful examples about how to use Modeline in a Camel K integration.
Find useful examples about how to use Modeline in a Camel K integration.

```
kamel run --dev modeline-build-property-route.yaml
kamel run --dev modeline-build-property-file-route.yaml
kamel run --dev modeline-property-route.yaml
kamel run --dev modeline-property-file-route.yaml
kubectl create secret generic my-sec --from-literal=my-secret-key="very top secret"
kamel run --dev modeline-config-secret-route.yaml
kubectl create configmap my-cm-file --from-file=resources-data.txt
kamel run --dev modeline-config-file-route.yaml
kamel run --dev modeline-resource-file-route.yaml
```
4 changes: 3 additions & 1 deletion generic-examples/modeline/SampleModeline.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// camel-k: dependency=mvn:com.google.guava:guava:28.0-jre
// camel-k: language=java

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand All @@ -17,6 +17,8 @@
* limitations under the License.
*/

// camel-k: dependency=mvn:com.google.guava:guava:28.0-jre

import org.apache.camel.builder.RouteBuilder;

public class SampleModeline extends RouteBuilder {
Expand Down

This file was deleted.

27 changes: 27 additions & 0 deletions generic-examples/modeline/modeline-build-property-file-route.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.
# ---------------------------------------------------------------------------

# camel-k: build-property=file:quarkus.properties

- from:
uri: "timer:build-property"
steps:
- setBody:
simple: "The application name: {{quarkus.application.name}}"
- to: "log:info"
Loading

0 comments on commit 338429d

Please sign in to comment.