This is an automated email from the ASF dual-hosted git repository. tsato pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push: new 1d2e4e566 migrate and improve knative example 1d2e4e566 is described below commit 1d2e4e566195a5c6692c5f730a25d52e652f5cd5 Author: Kuthumi Pepple <kuthumipep...@gmail.com> AuthorDate: Tue Aug 23 17:11:07 2022 +0100 migrate and improve knative example --- examples/README.md | 8 -- examples/knative/README.md | 134 --------------------------------- examples/knative/feed.groovy | 22 ------ examples/knative/messages-channel.yaml | 21 ------ examples/knative/printer.groovy | 21 ------ examples/knative/reader.groovy | 20 ----- examples/knative/splitter.groovy | 22 ------ examples/knative/words-channel.yaml | 21 ------ examples/knative/writer.groovy | 21 ------ 9 files changed, 290 deletions(-) diff --git a/examples/README.md b/examples/README.md index 7ba5a016e..341f447b1 100644 --- a/examples/README.md +++ b/examples/README.md @@ -15,14 +15,6 @@ In this section you will find the most basic examples. Useful to start learning | 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 | -|---|---|---| -| 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: diff --git a/examples/knative/README.md b/examples/knative/README.md deleted file mode 100644 index ace3fe552..000000000 --- a/examples/knative/README.md +++ /dev/null @@ -1,134 +0,0 @@ -# Knative Camel K Example -This example shows how Camel K can be used to connect Knative building blocks to create awesome applications. - -A video version of this [demo is available on YouTube](https://youtu.be/btf_e2GniXM). - -It's assumed that both Camel K and Knative are properly installed (including Knative Build, Serving and Eventing) into the cluster. -Refer to the specific documentation to install and configure all components. - -We're going to create two channels: -- messages -- words - -The first channel will contain phrases, while the second one will contains the single words contained in the phrases. - -To create the channels (they use the in-memory channel provisioner): - -``` -kubectl create -f messages-channel.yaml -kubectl create -f words-channel.yaml -``` - -We can now proceed to install all camel K integrations. - -## Install a "Printer" - -We'll install a Camel K integration that will print all words from the `words` channel. - -Writing a "function" that does this is as simple as writing: - -``` -from('knative:channel/words') - .convertBodyTo(String.class) - .to('log:info') -``` - -You can run this integration by running: - -``` -kamel run printer.groovy -``` - -Under the hood, the Camel K operator does this: -- Understands that the integration is passive, meaning that it can be activated only using an external HTTP call (the knative consumer endpoint) -- Materializes the integration as a Knative autoscaling service, integrated in the Istio service mesh -- Adds a Knative Eventing `Subscription` that points to the autoscaling service - -The resulting integration will be scaled to 0 when not used (if you wait ~5 minutes, you'll see it). - -## Install a "Splitter" - -We're now going to deploy a splitter, using the Camel core Split EIP. The splitter will take all messages from the `messages` channel, -split them and push the single words into the `words` channel. - -The integration code is super simple: - -``` -from('knative:channel/messages') - .split().tokenize(" ") - .log('sending ${body} to words channel') - .to('knative:channel/words') -``` - -Let's run it with: - -``` -kamel run splitter.groovy -``` - -This integration will be also materialized as a Knative autoscaling service, because the only entrypoint is passive (waits for a push notification). - -## Install a "Feed" - -We're going to feed this chain of functions using a timed feed like this: - -``` -from('timer:clock?period=3000') - .setBody().constant("Hello World from Camel K") - .to('knative:channel/messages') - .log('sent message to messages channel') -``` - -Every 3 seconds, the integration sends a message to the Knative `messages` channel. - -Let's run it with: - -``` -kamel run feed.groovy -``` - -This cannot be materialized into an autoscaling service, but the operator understands it automatically and maps it to a plain Kubernetes Deployment -(Istio sidecar will be injected). - -## Playing around - -If you've installed all the services, you'll find that the printer pod will print single words as they arrive from the feed (every 3 seconds, passing by the splitter function). - -If you now stop the feed integration (`kamel delete feed`) you will notice that the other services (splitter and printer) will scale down to 0 in few minutes. - -And if you reinstall the feed again (`kamel run feed.groovy`), the other integration will scale up again as soon as they receive messages (splitter first, then printer). - -## Playing harder - -You can also play with different kind of feeds. E.g. the following simple feed can be used to bind messages from Telegram to the system: - -``` -from('telegram:bots/<put-here-your-botfather-authorization>') - .convertBodyTo(String.class) - .to('log:info') - .to('knative:channel/messages') -``` - -Now just send messages to your bot with the Telegram client app to see all single words appearing in the printer service. - -You can also replace the printer with a Slack-based printer like: - -``` -from('knative:channel/words') - .log('Received: ${body}') - .to('slack:#camel-k-tests') - - -camel { - components { - slack { - webhookUrl '<put-here-your-slack-incoming-webhook-url>' - } - } -} -``` - -Now the single words will be printed in the log but also forwarded to the -slack channel named `#camel-k-tests`. - -You have infinite possibilities with Camel! diff --git a/examples/knative/feed.groovy b/examples/knative/feed.groovy deleted file mode 100644 index a456c8b78..000000000 --- a/examples/knative/feed.groovy +++ /dev/null @@ -1,22 +0,0 @@ -// camel-k: language=groovy -/* - * 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('timer:clock?period=3000') - .setBody().constant("Hello World from Camel K") - .to('knative:channel/messages') - .log('sent message to messages channel') diff --git a/examples/knative/messages-channel.yaml b/examples/knative/messages-channel.yaml deleted file mode 100644 index c67517d92..000000000 --- a/examples/knative/messages-channel.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# --------------------------------------------------------------------------- -# 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: messaging.knative.dev/v1 -kind: InMemoryChannel -metadata: - name: messages diff --git a/examples/knative/printer.groovy b/examples/knative/printer.groovy deleted file mode 100644 index fa3aa8f2d..000000000 --- a/examples/knative/printer.groovy +++ /dev/null @@ -1,21 +0,0 @@ -// camel-k: language=groovy -/* - * 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('knative:channel/words') - .convertBodyTo(String.class) - .to('log:info') diff --git a/examples/knative/reader.groovy b/examples/knative/reader.groovy deleted file mode 100644 index 2a965607c..000000000 --- a/examples/knative/reader.groovy +++ /dev/null @@ -1,20 +0,0 @@ -// camel-k: language=groovy -/* - * 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('knative:endpoint/reader') - .log('got ${body}') \ No newline at end of file diff --git a/examples/knative/splitter.groovy b/examples/knative/splitter.groovy deleted file mode 100644 index 4bde12cb7..000000000 --- a/examples/knative/splitter.groovy +++ /dev/null @@ -1,22 +0,0 @@ -// camel-k: language=groovy -/* - * 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('knative:channel/messages') - .split().tokenize(" ") - .log('sending ${body} to words channel') - .to('knative:channel/words') \ No newline at end of file diff --git a/examples/knative/words-channel.yaml b/examples/knative/words-channel.yaml deleted file mode 100644 index 2bd81ffec..000000000 --- a/examples/knative/words-channel.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# --------------------------------------------------------------------------- -# 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: messaging.knative.dev/v1 -kind: InMemoryChannel -metadata: - name: words diff --git a/examples/knative/writer.groovy b/examples/knative/writer.groovy deleted file mode 100644 index a452f4c30..000000000 --- a/examples/knative/writer.groovy +++ /dev/null @@ -1,21 +0,0 @@ -// camel-k: language=groovy -/* - * 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('timer:messages?period=10000') - .setBody().constant('the-body') - .to('knative:endpoint/reader')