This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-kamelets-examples.git
The following commit(s) were added to refs/heads/main by this push: new e775b5c Add Knative broker example (#56) e775b5c is described below commit e775b5c0e21902a0f12da13deeaaa63fd445547b Author: Christoph Deppisch <cdeppi...@redhat.com> AuthorDate: Tue Feb 13 14:21:41 2024 +0100 Add Knative broker example (#56) Shows Kamelets connecting to a Knative eventing message broker as event source and sink --- jbang/knative/README.adoc | 83 ++++++++++++++++++++++++++++++ jbang/knative/application.properties | 20 +++++++ jbang/knative/knative.json | 35 +++++++++++++ jbang/knative/log-sink.yaml | 28 ++++++++++ jbang/knative/pipes/log-sink-pipe.yaml | 41 +++++++++++++++ jbang/knative/pipes/timer-source-pipe.yaml | 50 ++++++++++++++++++ jbang/knative/timer-source.yaml | 35 +++++++++++++ 7 files changed, 292 insertions(+) diff --git a/jbang/knative/README.adoc b/jbang/knative/README.adoc new file mode 100644 index 0000000..5b652be --- /dev/null +++ b/jbang/knative/README.adoc @@ -0,0 +1,83 @@ +== Knative + +This example connects to Knative eventing message broker using Apache Camel Kamelets as event sources and sinks. + +=== Install JBang + +First install JBang according to https://www.jbang.dev + +When JBang is installed then you should be able to run from a shell: + +[source,sh] +---- +$ jbang --version +---- + +This will output the version of JBang. + +To run this example you can either install Camel on JBang via: + +[source,sh] +---- +$ jbang app install camel@apache/camel +---- + +Which allows to run CamelJBang with `camel` as shown below. + +=== How to run + +The sample provides multiple routes that interact with each other. +The timer-source route produces events periodically and the log-sink route is there to consume events printing its data to the log output. + +The `knative.json` configuration provides the Knative broker endpoint URL for both routes. +In a local JBang environment we will not use a Knative broker but connect the routes directly where the source sends its events to the Http endpoint provided by the sink. + +Then you can run this example using: + +[source,sh] +---- +$ camel run log-sink.yaml +$ camel run timer-source.yaml +---- + +Pleas make sure to run the routes in separate terminals so you can see the individual log output with the events being exchanged. + +=== Live reload + +You can run the example in dev mode which allows you to edit the example, +and hot-reload when the file is saved. + +[source,sh] +---- +$ camel run log-sink.yaml --dev +---- + +=== Run directly from github + +The example can also be run directly by referring to the github URL as shown: + +[source,sh] +---- +$ camel runhttps://github.com/apache/camel-kamelets-examples/tree/main/jbang/knative +---- + +=== Developer Web Console + +You can enable the developer console via `--console` flag as show: + +[source,sh] +---- +$ camel run log-sink.yaml --console +---- + +Then you can browse: http://localhost:8080/q/dev to introspect the running Camel application. + +=== Help and contributions + +If you hit any problem using Camel or have some feedback, then please +https://camel.apache.org/community/support/[let us know]. + +We also love contributors, so +https://camel.apache.org/community/contributing/[get involved] :-) + +The Camel riders! diff --git a/jbang/knative/application.properties b/jbang/knative/application.properties new file mode 100644 index 0000000..3fa35e5 --- /dev/null +++ b/jbang/knative/application.properties @@ -0,0 +1,20 @@ +# +# 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.component.knative.environmentPath=file:knative.json + +camel.jbang.dependencies=camel:knative,camel:knative-http,camel:platform-http diff --git a/jbang/knative/knative.json b/jbang/knative/knative.json new file mode 100644 index 0000000..b2d0005 --- /dev/null +++ b/jbang/knative/knative.json @@ -0,0 +1,35 @@ +{ + "services": [ + { + "type": "event", + "name": "default", + "url": "http://localhost:8080/events/org.apache.camel.event.messages", + "endpointKind": "sink", + "objectApiVersion": "eventing.knative.dev/v1", + "objectKind": "Broker", + "objectName": "default", + "metadata": { + "camel.endpoint.kind": "sink", + "knative.apiVersion": "eventing.knative.dev/v1", + "knative.kind": "Broker", + "knative.name": "example-broker" + } + }, + { + "type": "event", + "name": "org.apache.camel.event.messages", + "endpointKind": "source", + "path": "/events/org.apache.camel.event.messages", + "objectApiVersion": "eventing.knative.dev/v1", + "objectKind": "Broker", + "objectName": "default", + "metadata": { + "camel.endpoint.kind": "source", + "knative.apiVersion": "eventing.knative.dev/v1", + "knative.kind": "Broker", + "knative.name": "default", + "knative.reply": "false" + } + } + ] +} diff --git a/jbang/knative/log-sink.yaml b/jbang/knative/log-sink.yaml new file mode 100644 index 0000000..6a8fff1 --- /dev/null +++ b/jbang/knative/log-sink.yaml @@ -0,0 +1,28 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +- route: + from: + uri: "knative:event/org.apache.camel.event.messages" + parameters: + kind: Broker + name: default + steps: + - to: + uri: "kamelet:log-sink" + parameters: + showHeaders: true diff --git a/jbang/knative/pipes/log-sink-pipe.yaml b/jbang/knative/pipes/log-sink-pipe.yaml new file mode 100644 index 0000000..ad20ed5 --- /dev/null +++ b/jbang/knative/pipes/log-sink-pipe.yaml @@ -0,0 +1,41 @@ +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- + +apiVersion: camel.apache.org/v1 +kind: Pipe +metadata: + name: log-sink-pipe + labels: + app.openshift.io/runtime: camel +spec: + source: + ref: + kind: Broker + apiVersion: eventing.knative.dev/v1 + name: default + properties: + type: org.apache.camel.event.messages + sink: + ref: + kind: Kamelet + apiVersion: camel.apache.org/v1 + name: log-sink + properties: + multiline: true + showHeaders: true + showBodyType: false + showExchangePattern: false diff --git a/jbang/knative/pipes/timer-source-pipe.yaml b/jbang/knative/pipes/timer-source-pipe.yaml new file mode 100644 index 0000000..3ad5d32 --- /dev/null +++ b/jbang/knative/pipes/timer-source-pipe.yaml @@ -0,0 +1,50 @@ +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- + +apiVersion: camel.apache.org/v1 +kind: Pipe +metadata: + name: timer-source-pipe +spec: + source: + ref: + kind: Kamelet + apiVersion: camel.apache.org/v1 + name: timer-source + properties: + period: 5000 + contentType: application/json + message: | + { "client": "timer-pipe", "message": "Camel rocks!" } + steps: + - ref: + kind: Kamelet + apiVersion: camel.apache.org/v1 + name: log-action + properties: + showHeaders: true + sink: + dataTypes: + in: + scheme: http + format: application-cloudevents + ref: + kind: Broker + apiVersion: eventing.knative.dev/v1 + name: default + properties: + type: org.apache.camel.event.messages diff --git a/jbang/knative/timer-source.yaml b/jbang/knative/timer-source.yaml new file mode 100644 index 0000000..c9ec4fb --- /dev/null +++ b/jbang/knative/timer-source.yaml @@ -0,0 +1,35 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +- route: + from: + uri: "kamelet:timer-source" + parameters: + period: 5000 + contentType: application/json + message: | + { "client": "timer-pipe", "message": "Camel rocks!" } + steps: + - transform: + toType: http:application-cloudevents + - log: + message: "${body}" + - to: + uri: "knative:event/org.apache.camel.event.messages" + parameters: + kind: Broker + name: default