Camel K 入门

Red Hat Integration 2022.Q3

开发并运行第一个 Camel K 应用程序

摘要

如何安装 Camel K,设置开发环境并运行示例应用程序。

前言

使开源包含更多

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。我们从这四个术语开始:master、slave、黑名单和白名单。由于此项工作十分艰巨,这些更改将在即将推出的几个发行版本中逐步实施。有关更多详情,请参阅我们的首席技术官 Chris Wright 提供的消息

第 1 章 Camel K 简介

本章论述了 Red Hat Integration 提供的概念、功能和云原生架构 - Camel K:

1.1. Camel K 概述

Red Hat Integration - Camel K 是一个从 Apache Camel K 构建的轻量级集成框架,它以 OpenShift 上的云原生运行。Camel K 专为无服务器和微服务架构而设计。您可以使用 Camel K 立即运行 OpenShift 中以 Camel 域特定语言(DSL)编写的集成代码。Camel K 是 Apache Camel 开源社区的子项目 :https://github.com/apache/camel-k。

Camel K 使用 Go 编程语言实施,并使用 Kubernetes Operator SDK 在云中自动部署集成。例如,这包括在 OpenShift 上自动创建服务和路由。这在部署和重新部署云中集成时速度要快,比如几秒钟或更少,而不是几分钟。

Camel K 运行时提供显著性能优化。Quarkus 云原生 Java 框架默认启用,以加快启动速度,并降低内存和 CPU 占用量。以开发人员模式运行 Camel K 时,您可以对集成 DSL 进行实时更新,并在 OpenShift 上即时查看结果,而不必等待您的集成重新部署。

将 Camel K 与 OpenShift Serverless 和 Knative Serving 搭配使用,仅在需要时创建容器,并在负载下自动缩放至零。通过消除服务器置备和维护的开销,并可让您专注于应用程序开发来降低成本。

将 Camel K 与 OpenShift Serverless 和 Knative Eventing 搭配使用,您可以管理系统中的组件在用于无服务器应用程序的事件驱动的架构中如何进行通信。这可通过使用发布订阅或事件流模型,通过分离事件生产者和消费者之间的分离关系来提供灵活性并提高了效率。

1.2. Camel K 特性

Camel K 包括以下主要平台和特性:

1.2.1. 平台和组件版本

  • OpenShift Container Platform 4.6, 4.9, 4.10, 4.11
  • OpenShift Serverless 1.24.0
  • Red Hat build of Quarkus 2.7.6
  • Red Hat Camel Extensions for Quarkus 2.7.1
  • Apache Camel K 1.8.0
  • Apache Camel 3.14.2
  • OpenJDK 11

1.2.2. Camel K 特性

  • 用于自动扩展和扩展零的 Knative Serving
  • 用于事件驱动的构架的 Knative Eventing
  • 默认使用 Quarkus 运行时的性能优化
  • 使用 Java 或 YAML DSL 编写的 Camel 集成
  • 使用 Visual Studio Code 的开发工具
  • 在 OpenShift 中使用 Prometheus 进行集成
  • Quickstarts
  • Kamelet 将连接器目录到外部系统,如 AWS、JIRA 和 Salesforce

下图显示了 Camel K 云原生架构的简化视图:

Camel K 架构

其他资源

1.2.3. Kamelets

Kamelets 可以隐藏在简单界面后面的外部系统的复杂性,包括实例化它们(即使不熟悉 Camel 的用户)需要的所有信息。

Kamelets 作为自定义资源实施,可在 OpenShift 集群上安装并在 Camel K 集成中使用。Kamelets 是路由模板,它使用 Camel 组件连接到外部系统,而无需深入了解组件。Kamelets 提取连接到外部系统的详情。您还可以组合 Kamelets 来创建复杂的 Camel 集成,就像使用标准 Camel 组件一样。

1.3. Camel K 开发工具

Camel K 为 Visual Studio(VS)Code、Red Hat CodeReady WorkSpaces 和 Eclipse Che 提供开发工具扩展。基于 Camel 的工具扩展包括自动完成 Camel DSL 代码、Camel K 模式行配置和 Camel K 特征等功能。虽然 Didact 指南工具扩展提供了 Camel K 快速启动指南命令的自动执行。

可用的 VS Code 开发工具扩展如下:

  • 红帽为 Apache Camel 的 VS Code 扩展包

    • Apache Camel K 扩展工具
    • Apache Camel 扩展的语言支持
    • Apache Camel K 的调试适配器
    • OpenShift、Java 等等的额外扩展
    • VS Code 扩展的 Didact 教程工具

有关如何为 Camel K 设置这些 VS Code 扩展的详情,请参考 设置 Camel K 开发环境

重要

注意: Camel K VS Code 扩展是社区功能。

Eclipse Che 还使用 vscode-camelk 插件提供这些功能。

有关开发支持范围的更多信息,请参阅 开发支持覆盖范围

1.4. Camel K 发行版本

表 1.1. Red Hat Integration - Camel K 发行版本

分发描述位置

Operator 镜像

Red Hat Integration 的容器镜像 - Camel K Operator: integration/camel-k-rhel8-operator

Maven 软件仓库

Red Hat Integration 的 Maven 工件 - Camel K

红帽提供了 Maven 存储库,以托管我们产品中的内容。这些软件仓库可从软件下载页面下载。

Red Hat Integration - Camel K 需要以下软件仓库:

  • rhi-common
  • rhi-camel-quarkus
  • rhi-camel-k

发行版本不支持安装 Red Hat Integration - Camel K 处于离线模式。

Red Hat Integration 的软件下载

源代码

Red Hat Integration 的源代码 - Camel K

Red Hat Integration 的软件下载

Quickstarts

快速开始指南:

  • 基本 Java 集成
  • 事件流集成
  • JDBC 集成
  • JMS 集成
  • Kafka 集成
  • Knative 集成
  • SaaS 集成
  • Serverless API 集成
  • 转型集成

https://github.com/openshift-integration

注意

您必须有 Red Hat Integration 订阅并登录红帽客户门户网站才能访问 Red Hat Integration - Camel K 发行版本。

第 2 章 准备 OpenShift 集群

本章介绍了如何在 OpenShift 上安装 Red Hat Integration - Camel K 和 OpenShift Serverless,以及如何在开发环境中安装所需的 Camel K 和 OpenShift Serverless 命令行工具。

2.1. 安装 Camel K

您可以从 OperatorHub 在 OpenShift 集群上安装 Red Hat Integration - Camel K Operator。OperatorHub 可通过 OpenShift Container Platform Web 控制台获得,为集群管理员提供了一个界面来发现和安装 Operator。

安装 Camel K Operator 后,您可以安装 Camel K CLI 工具以使用命令行访问所有 Camel K 功能。

先决条件

  • 您可以使用正确的访问级别访问 OpenShift 4.6(或更新版本)集群、创建项目和安装 Operator 的功能,以及在本地系统上安装 CLI 工具的功能。

    注意

    从 OpenShift OperatorHub 安装 Camel K 时,您不需要创建 pull secret。Camel K Operator 会自动重复使用 OpenShift 集群级别的身份验证,以便从 registry.redhat.io 拉取 Camel K 镜像。

  • 已安装 OpenShift CLI 工具(oc),以便您可以在命令行中与 OpenShift 集群交互。有关如何安装 OpenShift CLI 的详情,请参阅安装 OpenShift CLI

流程

  1. 在 OpenShift Container Platform web 控制台中,使用具有集群管理员权限的帐户进行登录。
  2. 创建一个新的 OpenShift 项目:

    1. 在左侧导航菜单中点击 Home > Project > Create Project
    2. 输入项目名称,如 my-camel-k-project,然后单击 Create
  3. 在左侧导航菜单中点 Operators > OperatorHub
  4. Filter by keyword 文本框中,键入 Camel K,然后单击 Red Hat Integration - Camel K Operator 卡。
  5. 阅读 Operator 的信息,然后点 Install。Operator 安装页面将打开。
  6. 选择以下订阅设置:

    • 更新频道 & gt; latest
    • Installation Mode > A specific namespace on the cluster > my-camel-k-project
    • Approval Strategy > Automatic

      注意

      如果您的环境需要,安装模式 > All namespaces on the cluster and Approval Strategy > Manual 设置也可用。

  7. 单击 Install,然后稍等片刻,直到 Camel K Operator 准备就绪。
  8. 下载并安装 Camel K CLI 工具:

    1. 从 OpenShift Web 控制台顶部的帮助菜单(?),选择 Command line tools
    2. 向下滚动到 kamel - Red Hat Integration - Camel K - 命令行界面 部分。
    3. 点击链接下载本地操作系统的二进制文件(Linux、Mac、Windows)。
    4. 在系统路径中解压缩并安装 CLI。
    5. 要验证您可以访问 Kamel K CLI,请打开命令窗口并键入以下内容:

      kamel --help

      此命令显示有关 Camel K CLI 命令的信息。

后续步骤

(可选) 指定 Camel K 资源限制

2.1.1. 指定 Camel K 资源限制

安装 Camel K 时,Camel K 的 OpenShift pod 没有为 CPU 和内存(RAM)资源设置的任何限值。如果要为 Camel K 定义资源限值,您必须编辑在安装过程中创建的 Camel K 订阅资源。

前提条件

  • 具有集群管理员访问安装 Camel K Operator 的 OpenShift 项目,如 安装 Camel K 所述。
  • 您知道要应用到 Camel K 订阅的资源限值。有关资源限值的更多信息,请参阅以下文档:

流程

  1. 登录 OpenShift Web 控制台。
  2. 选择 Operators > Installed Operators > Operator Details > Subscription
  3. 选择 Actions > Edit Subscription

    订阅的文件在 YAML 编辑器中打开。

  4. spec 部分中,添加一个 config.resources 部分,并为内存和 cpu 提供值,如下例所示:

    spec:
      channel: default
      config:
        resources:
          limits:
            memory: 512Mi
            cpu: 500m
          requests:
            cpu: 200m
            memory: 128Mi
  5. 保存您的更改。

OpenShift 更新订阅,并应用您指定的资源限值。

2.2. 安装 OpenShift Serverless

您可以从 OperatorHub 在 OpenShift 集群上安装 OpenShift Serverless Operator。OperatorHub 可通过 OpenShift Container Platform Web 控制台获得,为集群管理员提供了一个界面来发现和安装 Operator。

OpenShift Serverless Operator 支持 Knative Serving 和 Knative Eventing 功能。如需了解更多详细信息,请参阅安装 OpenShift Serverless Operator

先决条件

  • 具有集群管理员访问安装 Camel K Operator 的 OpenShift 项目。
  • 已安装 OpenShift CLI 工具(oc),以便您可以在命令行中与 OpenShift 集群交互。有关如何安装 OpenShift CLI 的详情,请参阅安装 OpenShift CLI

流程

  1. 在 OpenShift Container Platform web 控制台中,使用具有集群管理员权限的帐户进行登录。
  2. 在左侧导航菜单中点 Operators > OperatorHub
  3. Filter by keyword 文本框中,输入 Serverless 以查找 OpenShift Serverless Operator
  4. 阅读 Operator 信息,然后点 Install 以显示 Operator 订阅页面。
  5. 选择默认订阅设置:

    • Update Channel > 选择与 OpenShift 版本匹配的频道,如 4.10
    • Installation Mode > All namespaces on the cluster
    • Approval Strategy > Automatic

      注意

      如果您的环境需要,也可使用 Approval Strategy > Manual 设置。

  6. 单击 Install,然后稍等片刻,直到 Operator 准备就绪。
  7. 使用 OpenShift 文档中的步骤安装所需的 Knative 组件:

  8. (可选)下载并安装 OpenShift Serverless CLI 工具:

    1. 从 OpenShift Web 控制台顶部的帮助菜单(?),选择 Command line tools
    2. 向下滚动到 kn - OpenShift Serverless - Command Line Interface 部分。
    3. 点击链接下载本地操作系统的二进制文件(Linux、Mac、Windows)
    4. 在系统路径中解压缩并安装 CLI。
    5. 要验证您能否访问 kn CLI,打开命令窗口,然后键入以下内容:

      kn --help

      此命令显示有关 OpenShift Serverless CLI 命令的信息。

      如需了解更多详细信息,请参阅 OpenShift Serverless CLI 文档

2.3. 为 Camel K 配置 Maven 存储库

对于 Camel K operator,您可以在 ConfigMap 或 secret 中提供 Maven 设置。

流程

  1. 要从文件创建 ConfigMap,请运行以下命令。

    oc create configmap maven-settings --from-file=settings.xml

    然后,可在 IntegrationPlatform 资源中引用创建的 ConfigMap,来自于 spec.build.maven.settings 字段。

    示例

    apiVersion: camel.apache.org/v1
    kind: IntegrationPlatform
    metadata:
      name: camel-k
    spec:
      build:
         maven:
            settings:
               configMapKeyRef:
                    key: settings.xml
                    name: maven-settings

    或者,您可以直接编辑 IntegrationPlatform 资源来引用包含 Maven 设置的 ConfigMap:

    oc edit ip camel-k

为远程 Maven 存储库配置 CA 证书

您可以在 Secret 中提供 CA 证书,供 Maven 命令用于连接远程 Maven 存储库。

流程

  1. 使用以下命令从文件创建 Secret:

    oc create secret generic maven-ca-certs --from-file=ca.crt
  2. spec.build.maven.caSecret 字段中引用 IntegrationPlatform 资源中创建的 Secret,如下所示。

    apiVersion: camel.apache.org/v1
    kind: IntegrationPlatform
    metadata:
      name: camel-k
    spec:
      build:
          maven:
              caSecret:
                 key: tls.crt
                 name: tls-secret

第 3 章 开发和运行 Camel K 集成

本章介绍了如何设置开发环境以及如何开发和部署使用 Java 和 YAML 编写的简单 Camel K 集成。它还演示了如何使用 kamel 命令行在运行时管理 Camel K 集成。例如,这包括运行、描述、日志记录和删除集成。

3.1. 设置您的 Camel K 开发环境

您必须使用推荐的开发工具设置您的环境,然后才能自动部署 Camel K 快速启动指南。本节介绍如何安装推荐的 Visual Studio(VS)Code IDE 以及它为 Camel K 提供的扩展。

注意
  • Camel K VS Code 扩展是社区功能。
  • 建议 VS Code 易于使用和最佳开发人员体验 Camel K。这包括自动完成 Camel DSL 代码和 Camel K 特征,以及自动执行教程命令。但是,您可以使用您选择的 IDE 而不是 VS Code 手动输入您的代码和教程命令。

先决条件

流程

  1. 在开发平台上安装 VS Code。例如,在 Red Hat Enterprise Linux 中:

    1. 安装所需的密钥和存储库:

      $ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
      $ sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
    2. 更新缓存并安装 VS Code 软件包:

      $ yum check-update
      $ sudo yum install code

      有关在其他平台上安装的详情,请查看 VS Code 安装文档

  2. 输入 code 命令以启动 VS Code 编辑器。如需了解更多详细信息,请参阅 VS Code 命令行文档
  3. 安装 VS Code Camel 扩展包,其中包含 Camel K 所需的扩展。例如,在 VS Code 中:

    1. 在左侧导航栏中,单击 Extensions
    2. 在搜索框中,输入 Apache Camel
    3. 选择 RedHat Apache Camel 的 Extension Pack for Apache Camel,然后单击 Install

      选择用于 Apache Camel 的 VS Code 扩展包

      详情请查看 Red Hat Apache Camel 扩展包的说明

  4. 安装 VS Code Didact 扩展,您可以使用它通过点击教程中的链接自动运行快速启动指南命令。例如,在 VS Code 中:

    1. 在左侧导航栏中,单击 Extensions
    2. 在搜索框中输入 Didact
    3. 选择扩展名,然后单击 Install

      如需了解更多详细信息,请参阅 Did act 扩展 的说明。

3.2. 在 Java 中开发 Camel K 集成

本节演示了如何在 Java DSL 中开发简单的 Camel K 集成。在 Java 中编写集成以使用 Camel K 部署,这与在 Camel 中定义路由规则。但是,在使用 Camel K 时,您不需要构建集成并将其打包为 JAR。

您可以在集成路由中直接使用任何 Camel 组件。Camel K 自动处理依赖关系管理,并使用代码检查从 Camel 目录导入所有所需的库。

流程

  1. 输入 kamel init 命令来生成简单的 Java 集成文件。例如:

    $ kamel init HelloCamelK.java
  2. 在 IDE 中打开生成的集成文件,并根据需要编辑。例如,HelloCamelK.java 集成会自动包含 Camel 计时器 和日志 组件,以帮助您入门:

    // camel-k: language=java
    
    import org.apache.camel.builder.RouteBuilder;
    
    public class HelloCamelK extends RouteBuilder {
      @Override
      public void configure() throws Exception {
    
          // Write your routes here, for example:
          from("timer:java?period=1s")
            .routeId("java")
            .setBody()
              .simple("Hello Camel K from ${routeId}")
            .to("log:info");
    
      }
    }

后续步骤

3.3. 在 YAML 中开发 Camel K 集成

本节介绍如何在 YAML DSL 中开发简单的 Camel K 集成。在 YAML 中编写集成以使用 Camel K 部署,这与在 Camel 中定义路由规则。

您可以在集成路由中直接使用任何 Camel 组件。Camel K 自动处理依赖关系管理,并使用代码检查从 Camel 目录导入所有所需的库。

流程

  1. 输入 kamel init 命令来生成一个简单的 YAML 集成文件。例如:

    $ kamel init hello.camelk.yaml
  2. 在 IDE 中打开生成的集成文件,并根据需要编辑。例如,hello.camelk.yaml 集成会自动包含 Camel 计时器 和日志 组件,以帮助您入门:

    # Write your routes here, for example:
    - from:
        uri: "timer:yaml"
        parameters:
          period: "1s"
        steps:
          - set-body:
              constant: "Hello Camel K from yaml"
          - to: "log:info"

3.4. 运行 Camel K 集成

您可以使用 kamel run 命令从命令行运行 Camel K 集成。

先决条件

流程

  1. 使用 oc 客户端工具登录到 OpenShift 集群,例如:

    $ oc login --token=my-token --server=https://my-cluster.example.com:6443
  2. 确保 Camel K Operator 正在运行,例如:

    $ oc get pod
    NAME                               READY   STATUS    RESTARTS   AGE
    camel-k-operator-86b8d94b4-pk7d6   1/1     Running   0          6m28s
  3. 输入 kamel run 命令,在 OpenShift 上的云中运行您的集成。例如:

    Java 示例

    $ kamel run HelloCamelK.java
    integration "hello-camel-k" created

    YAML 示例

    $ kamel run hello.camelk.yaml
    integration "hello" created

  4. 输入 kamel get 命令检查集成状态:

    $ kamel get
    NAME       PHASE           KIT
    hello      Building Kit    myproject/kit-bq666mjej725sk8sn12g

    当集成首次运行时,Camel K 会为容器镜像构建集成套件,它会下载所有需要的 Camel 模块并将它们添加到镜像类路径中。

  5. 再次输入 kamel get 来验证集成是否正在运行:

    $ kamel get
    NAME       PHASE   KIT
    hello      Running myproject/kit-bq666mjej725sk8sn12g
  6. 输入 kamel log 命令,将日志打印到 stdout

    $ kamel log hello
    [1] 2021-08-11 17:58:40,573 INFO  [org.apa.cam.k.Runtime] (main) Apache Camel K Runtime 1.7.1.fuse-800025-redhat-00001
    [1] 2021-08-11 17:58:40,653 INFO  [org.apa.cam.qua.cor.CamelBootstrapRecorder] (main) bootstrap runtime: org.apache.camel.quarkus.main.CamelMainRuntime
    [1] 2021-08-11 17:58:40,844 INFO  [org.apa.cam.k.lis.SourcesConfigurer] (main) Loading routes from: SourceDefinition{name='camel-k-embedded-flow', language='yaml', location='file:/etc/camel/sources/camel-k-embedded-flow.yaml', }
    [1] 2021-08-11 17:58:41,216 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes startup summary (total:1 started:1)
    [1] 2021-08-11 17:58:41,217 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main)     Started route1 (timer://yaml)
    [1] 2021-08-11 17:58:41,217 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 3.10.0.fuse-800010-redhat-00001 (camel-1) started in 136ms (build:0ms init:100ms start:36ms)
    [1] 2021-08-11 17:58:41,268 INFO  [io.quarkus] (main) camel-k-integration 1.6.6 on JVM (powered by Quarkus 1.11.7.Final-redhat-00009) started in 2.064s.
    [1] 2021-08-11 17:58:41,269 INFO  [io.quarkus] (main) Profile prod activated.
    [1] 2021-08-11 17:58:41,269 INFO  [io.quarkus] (main) Installed features: [camel-bean, camel-core, camel-k-core, camel-k-runtime, camel-log, camel-support-common, camel-timer, camel-yaml-dsl, cdi]
    [1] 2021-08-11 17:58:42,423 INFO  [info] (Camel (camel-1) thread #0 - timer://yaml) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K from yaml]
    ...
  7. Ctrl-C 在终端中终止登录。

其他资源

3.5. 在开发模式下运行 Camel K 集成

您可以从命令行在 OpenShift 集群上以开发模式运行 Camel K 集成。使用开发模式,您可以迭代开发中的集成并快速获得代码的反馈。

当您使用 --dev 选项指定 kamel run 命令时,这将立即在云中部署集成,并在终端中显示集成日志。然后,您可以更改代码,并查看更改会自动应用到 OpenShift 上的远程集成 Pod。终端会自动显示云中远程集成的所有重新部署。

注意

Camel K 在开发模式中生成的工件与您在生产环境中运行的工件相同。开发模式的目的是加快开发速度。

先决条件

流程

  1. 使用 oc 客户端工具登录到 OpenShift 集群,例如:

    $ oc login --token=my-token --server=https://my-cluster.example.com:6443
  2. 确保 Camel K Operator 正在运行,例如:

    $ oc get pod
    NAME                               READY   STATUS    RESTARTS   AGE
    camel-k-operator-86b8d94b4-pk7d6   1/1     Running   0          6m28s
  3. 使用 --dev 进入 kamel run 命令,以在云中在 OpenShift 上的开发模式下运行集成。以下是一个简单的 Java 示例:

    $ kamel run HelloCamelK.java --dev
    Condition "IntegrationPlatformAvailable" is "True" for Integration hello-camel-k: test/camel-k
    Integration hello-camel-k in phase "Initialization"
    Integration hello-camel-k in phase "Building Kit"
    Condition "IntegrationKitAvailable" is "True" for Integration hello-camel-k: kit-c49sqn4apkb4qgn55ak0
    Integration hello-camel-k in phase "Deploying"
    Progress: integration "hello-camel-k" in phase Initialization
    Progress: integration "hello-camel-k" in phase Building Kit
    Progress: integration "hello-camel-k" in phase Deploying
    Integration hello-camel-k in phase "Running"
    Condition "DeploymentAvailable" is "True" for Integration hello-camel-k: deployment name is hello-camel-k
    Progress: integration "hello-camel-k" in phase Running
    Condition "CronJobAvailable" is "False" for Integration hello-camel-k: different controller strategy used (deployment)
    Condition "KnativeServiceAvailable" is "False" for Integration hello-camel-k: different controller strategy used (deployment)
    Condition "Ready" is "False" for Integration hello-camel-k
    Condition "Ready" is "True" for Integration hello-camel-k
    [1] Monitoring pod hello-camel-k-7f85df47b8-js7cb
    ...
    ...
    [1] 2021-08-11 18:34:44,069 INFO  [org.apa.cam.k.Runtime] (main) Apache Camel K Runtime 1.7.1.fuse-800025-redhat-00001
    [1] 2021-08-11 18:34:44,167 INFO  [org.apa.cam.qua.cor.CamelBootstrapRecorder] (main) bootstrap runtime: org.apache.camel.quarkus.main.CamelMainRuntime
    [1] 2021-08-11 18:34:44,362 INFO  [org.apa.cam.k.lis.SourcesConfigurer] (main) Loading routes from: SourceDefinition{name='HelloCamelK', language='java', location='file:/etc/camel/sources/HelloCamelK.java', }
    [1] 2021-08-11 18:34:46,180 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes startup summary (total:1 started:1)
    [1] 2021-08-11 18:34:46,180 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main)     Started java (timer://java)
    [1] 2021-08-11 18:34:46,180 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 3.10.0.fuse-800010-redhat-00001 (camel-1) started in 243ms (build:0ms init:213ms start:30ms)
    [1] 2021-08-11 18:34:46,190 INFO  [io.quarkus] (main) camel-k-integration 1.6.6 on JVM (powered by Quarkus 1.11.7.Final-redhat-00009) started in 3.457s.
    [1] 2021-08-11 18:34:46,190 INFO  [io.quarkus] (main) Profile prod activated.
    [1] 2021-08-11 18:34:46,191 INFO  [io.quarkus] (main) Installed features: [camel-bean, camel-core, camel-java-joor-dsl, camel-k-core, camel-k-runtime, camel-log, camel-support-common, camel-timer, cdi]
    [1] 2021-08-11 18:34:47,200 INFO  [info] (Camel (camel-1) thread #0 - timer://java) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K from java]
    [1] 2021-08-11 18:34:48,180 INFO  [info] (Camel (camel-1) thread #0 - timer://java) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K from java]
    [1] 2021-08-11 18:34:49,180 INFO  [info] (Camel (camel-1) thread #0 - timer://java) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K from java]
    ...
  4. 编辑集成 DSL 文件的内容,保存更改,并在终端中查看立即显示的更改。例如:

    ...
    integration "hello-camel-k" updated
    ...
    [2] 2021-08-11 18:40:54,173 INFO  [org.apa.cam.k.Runtime] (main) Apache Camel K Runtime 1.7.1.fuse-800025-redhat-00001
    [2] 2021-08-11 18:40:54,209 INFO  [org.apa.cam.qua.cor.CamelBootstrapRecorder] (main) bootstrap runtime: org.apache.camel.quarkus.main.CamelMainRuntime
    [2] 2021-08-11 18:40:54,301 INFO  [org.apa.cam.k.lis.SourcesConfigurer] (main) Loading routes from: SourceDefinition{name='HelloCamelK', language='java', location='file:/etc/camel/sources/HelloCamelK.java', }
    [2] 2021-08-11 18:40:55,796 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes startup summary (total:1 started:1)
    [2] 2021-08-11 18:40:55,796 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main)     Started java (timer://java)
    [2] 2021-08-11 18:40:55,797 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 3.10.0.fuse-800010-redhat-00001 (camel-1) started in 174ms (build:0ms init:147ms start:27ms)
    [2] 2021-08-11 18:40:55,803 INFO  [io.quarkus] (main) camel-k-integration 1.6.6 on JVM (powered by Quarkus 1.11.7.Final-redhat-00009) started in 3.025s.
    [2] 2021-08-11 18:40:55,808 INFO  [io.quarkus] (main) Profile prod activated.
    [2] 2021-08-11 18:40:55,809 INFO  [io.quarkus] (main) Installed features: [camel-bean, camel-core, camel-java-joor-dsl, camel-k-core, camel-k-runtime, camel-log, camel-support-common, camel-timer, cdi]
    [2] 2021-08-11 18:40:56,810 INFO  [info] (Camel (camel-1) thread #0 - timer://java) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K from java]
    [2] 2021-08-11 18:40:57,793 INFO  [info] (Camel (camel-1) thread #0 - timer://java) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K from java]
    ...
  5. Ctrl-C 在终端中终止登录。

其他资源

3.6. 使用模式线运行 Camel K 集成

您可以使用 Camel K 模式行在 Camel K 集成源文件中指定多个配置选项,这些文件在运行时执行。这样可以节省重新输入多个命令行选项的时间,并帮助防止输入错误。

以下示例显示了 Java 集成文件中的模式行条目,它可启用 3scale 并限制集成容器内存。

先决条件

流程

  1. 在您的集成文件中添加 Camel K 模式行条目。例如:

    ThreeScaleRest.java

    // camel-k: trait=3scale.enabled=true trait=container.limit-memory=256Mi 1
    import org.apache.camel.builder.RouteBuilder;
    
    public class ThreeScaleRest extends RouteBuilder {
    
      @Override
      public void configure() throws Exception {
          rest().get("/")
            .route()
            .setBody().constant("Hello");
      }
    }

    1
    启用容器和 3scale 特征,以通过 3scale 公开路由,并限制容器内存。
  2. 运行集成,例如:

    kamel run ThreeScaleRest.java

    kamel run 命令输出集成中指定的所有模式命令行选项,例如:

    Modeline options have been loaded from source files
    Full command: kamel run ThreeScaleRest.java --trait=3scale.enabled=true --trait=container.limit-memory=256Mi

其他资源

第 4 章 升级 Camel K

您可以自动升级已安装的 Camel K operator,但不自动升级 Camel K 集成。您必须手动触发 Camel K 集成升级。本章介绍了如何升级 Camel K operator 和 Camel K 集成。

4.1. 升级 Camel K operator

已安装的 Camel K operator 的订阅指定一个更新频道,例如 1.6.0 频道,用于跟踪和接收 Operator 的更新。要升级 Operator 以开始跟踪并从更新频道接收更新,您可以更改订阅中的更新频道。如需有关更改 已安装 Operator 的更新频道的更多信息,请参阅升级 安装的 Operator。

注意
  • 安装的 Operator 无法变为比当前频道旧的频道。

如果订阅中的批准策略被设置为 Automatic,则升级过程会在所选频道中提供新的 Operator 版本时立即启动。如果批准策略设为 Manual,则必须手动批准待处理的升级。

先决条件

  • Camel K Operator 使用 Operator Lifecycle Manager(OLM)安装。

流程

  1. 在 OpenShift Container Platform web 控制台的 Administrator 视角中,进入 OperatorsInstalled Operators
  2. Camel K Operator
  3. Subscription 标签页。
  4. Channel 中的更新频道的名称。
  5. 点您要更改的更新频道。例如,latest。点击 Save。这将开始升级到最新的 Camel K 版本。

对于带有 自动批准策略 的订阅,升级会自动开始。返回到 OperatorsInstalled Operators 页面,以监控升级的进度。完成后,状态会变为 Succeeded 和 Up to date。

对于采用手动批准策略的订阅,您可以使用 Subscription 选项卡手动批准升级。

4.2. 升级 Camel K 集成

当您为 Camel K operator 触发升级时,Operator 会准备要升级的集成,但不为每个用户触发升级,以避免服务中断。当升级 Operator 时,集成自定义资源不会自动升级到较新的版本,例如,Operator 可能为 1.6.0 版本,而 integrations 则报告之前版本 1.4.1 的自定义资源的 status.version 字段。

先决条件

使用 Operator Lifecycle Manager(OLM)安装并升级 Camel K Operator。

流程

  • 打开终端,再运行以下命令来升级 Camel K 交集。
kamel rebuild myintegration

这将清除集成资源的状态,Operator 将使用升级版本的工件(如版本 1.6.0 )开始部署集成。

4.3. 降级 Camel K

您可以通过安装之前的 Operator 版本来降级到较旧版本的 Camel K operator。这需要使用 OC CLI 手动触发。有关使用 CLI 安装 Operator 特定版本的更多信息,请参阅安装 Operator 的特定版本

重要

您必须删除现有 Camel K operator,然后 OLM 不支持将 Operator 的 specifc 版本安装为降级。

安装旧版本的 operator 后,使用 kamel rebuild 命令将集成降级到 operator 版本。例如,

kamel rebuild myintegration

第 5 章 Camel K 快速入门开发人员指南

Red Hat Integration - Camel K 根据 https://github.com/openshift-integration 提供的集成用例提供快速启动开发人员指南。本章详细介绍了如何设置和部署以下教程:

5.1. 部署基本 Camel K Java 集成

本教程演示了如何在 OpenShift 上运行简单的 Java 集成,对集成应用配置和路由,以及如何作为 Kubernetes CronJob 来运行集成。

先决条件

流程

  1. 克隆教程 Git 存储库:

    $ git clone git@github.com:openshift-integration/camel-k-example-basic.git
  2. 在 VS Code 中,选择 FileOpen Foldercamel-k-example-basic
  3. 在 VS Code 导航树中,右键单击 readme.didact.md 文件,再选择 Didact: Start Didact Tutorial from File。例如:

    启动 Camel K Quickstart 指南

    这会在 VS Code 中打开一个新的 Didact 选项卡,以显示教程说明。

  4. 按照教程说明,点提供的链接自动运行命令。

    或者,如果您没有使用 Didact 扩展安装 VS Code,您可以从 https://github.com/openshift-integration/camel-k-example-basic 手动输入命令。

5.2. 部署 Camel K Serverless 与 Knative 集成

本教程介绍了如何在事件驱动的构架中使用 OpenShift Serverless 部署 Camel K 集成。本教程使用 Knative Eventing 代理在 Bitcoin 交易演示中使用事件发布订阅模式进行通信。

本教程还介绍如何使用 Camel K 集成与多个外部系统连接到 Knative 事件网格。Camel K 集成也使用 Knative Serving 根据需要自动扩展和缩减为零。

先决条件

流程

  1. 克隆教程 Git 存储库:

    $ git clone git@github.com:openshift-integration/camel-k-example-knative.git
  2. 在 VS Code 中,选择 FileOpen Foldercamel-k-example-knative
  3. 在 VS Code 导航树中,右键单击 readme.didact.md 文件,再选择 Didact: Start Didact Tutorial from File。这会在 VS Code 中打开一个新的 Didact 选项卡,以显示教程说明。
  4. 按照教程说明,点提供的链接自动运行命令。

    或者,如果您没有使用 Didact 扩展安装 VS Code,您可以从 https://github.com/openshift-integration/camel-k-example-knative 手动输入命令。

5.3. 部署 Camel K 转换集成

本教程介绍了如何在 OpenShift 上运行 Camel K Java 集成,该集成将 XML 等数据转换为 JSON,并将其存储在 PostgreSQL 等数据库中。

教程示例使用 CSV 文件查询 XML API,并使用收集的数据来构建有效的 GeoJSON 文件,该文件存储在 PostgreSQL 数据库中。

先决条件

流程

  1. 克隆教程 Git 存储库:

    $ git clone git@github.com:openshift-integration/camel-k-example-transformations.git
  2. 在 VS Code 中,选择 FileOpen Foldercamel-k-example-transformations
  3. 在 VS Code 导航树中,右键单击 readme.didact.md 文件,再选择 Didact: Start Didact Tutorial from File。这会在 VS Code 中打开一个新的 Didact 选项卡,以显示教程说明。
  4. 按照教程说明,点提供的链接自动运行命令。

    或者,如果您没有使用 Didact 扩展安装 VS Code,您可以从 https://github.com/openshift-integration/camel-k-example-transformations 手动输入命令。

5.4. 部署 Camel K Serverless 事件流集成

本教程演示了在事件驱动的构架中使用 Camel K 和 OpenShift Serverless。

本教程介绍了如何使用 AMQ Broker 集群在 AMQ Streams 集群中安装 Camel K 和 Serverless,以及如何部署事件流项目来运行全局 hazard 警报演示应用程序。

先决条件

流程

  1. 克隆教程 Git 存储库:

    $ git clone git@github.com:openshift-integration/camel-k-example-event-streaming.git
  2. 在 VS Code 中,选择 FileOpen Foldercamel-k-example-event-streaming
  3. 在 VS Code 导航树中,右键单击 readme.didact.md 文件,再选择 Didact: Start Didact Tutorial from File。这会在 VS Code 中打开一个新的 Didact 选项卡,以显示教程说明。
  4. 按照教程说明,点提供的链接自动运行命令。

    或者,如果您没有使用 Didact 扩展安装 VS Code,您可以从 https://github.com/openshift-integration/camel-k-example-event-streaming 手动输入命令。

5.5. 部署基于 Camel K Serverless API 的集成

本教程演示了使用 Camel K 和 OpenShift Serverless 的 Knative Serving 进行基于 API 的集成,并管理 OpenShift 中使用 3scale API Management 的 API。

教程演示了如何配置基于 Amazon S3 的存储,设计 OpenAPI 定义,并运行调用演示 API 端点的集成。

先决条件

流程

  1. 克隆教程 Git 存储库:

    $ git clone git@github.com:openshift-integration/camel-k-example-api.git
  2. 在 VS Code 中,选择 FileOpen Foldercamel-k-example-api
  3. 在 VS Code 导航树中,右键单击 readme.didact.md 文件,再选择 Didact: Start Didact Tutorial from File。这会在 VS Code 中打开一个新的 Didact 选项卡,以显示教程说明。
  4. 按照教程说明,点提供的链接自动运行命令。

    或者,如果您没有使用 Didact 扩展安装 VS Code,您可以从 https://github.com/openshift-integration/camel-k-example-api 手动输入命令。

5.6. 部署 Camel K SaaS 集成

本教程介绍了如何在 OpenShift 上运行 Camel K Java 集成,它连接两个广泛用作服务(SaaS)供应商。

教程示例演示了如何使用基于 REST 的 Camel 组件集成 Salesforce 和 ServiceNow SaaS 供应商。在这个简单例子中,每个新的 Salesforce 问题单都会复制到包括 Salesforce 问题单号的相应 ServiceNow Incident。

先决条件

流程

  1. 克隆教程 Git 存储库:

    $ git clone git@github.com:openshift-integration/camel-k-example-saas.git
  2. 在 VS Code 中,选择 FileOpen Foldercamel-k-example-saas
  3. 在 VS Code 导航树中,右键单击 readme.didact.md 文件,再选择 Didact: Start Didact Tutorial from File。这会在 VS Code 中打开一个新的 Didact 选项卡,以显示教程说明。
  4. 按照教程说明,点提供的链接自动运行命令。

    或者,如果您没有使用 Didact 扩展安装 VS Code,您可以从 https://github.com/openshift-integration/camel-k-example-saas 手动输入命令。

5.7. 部署 Camel K JDBC 集成

本教程介绍了如何通过 JDBC 驱动程序开始使用 Camel K 和 SQL 数据库。本教程介绍了如何设置集成生成到 Postgres 数据库(您可以使用您选择的任何相关数据库)以及如何从同一数据库读取数据。

先决条件

流程

  1. 克隆教程 Git 存储库:

    $ git clone git@github.com:openshift-integration/camel-k-example-jdbc.git
  2. 在 VS Code 中,选择 FileOpen Foldercamel-k-example-jdbc
  3. 在 VS Code 导航树中,右键单击 readme.didact.md 文件,再选择 Didact: Start Didact Tutorial from File。这会在 VS Code 中打开一个新的 Didact 选项卡,以显示教程说明。
  4. 按照教程说明,点提供的链接自动运行命令。

    或者,如果您没有使用 Didact 扩展安装 VS Code,您可以从 https://github.com/openshift-integration/camel-k-example-jdbc 手动输入命令。

5.8. 部署 Camel K JMS 集成

本教程演示如何使用 JMS 连接到消息代理,以便使用和生成消息。有两个示例:

  • JMS Sink:本教程演示如何向 JMS 代理生成消息。
  • JMS Source:本教程演示如何使用来自 JMS 代理的消息。

先决条件

流程

  1. 克隆教程 Git 存储库:

    $ git clone git@github.com:openshift-integration/camel-k-example-jms.git
  2. 在 VS Code 中,选择 FileOpen Foldercamel-k-example-jms
  3. 在 VS Code 导航树中,右键单击 readme.didact.md 文件,再选择 Didact: Start Didact Tutorial from File。这会在 VS Code 中打开一个新的 Didact 选项卡,以显示教程说明。
  4. 按照教程说明,点提供的链接自动运行命令。

    或者,如果您没有使用 Didact 扩展安装 VS Code,您可以从 https://github.com/openshift-integration/camel-k-example-jms 手动输入命令。

其他资源

5.9. 部署 Camel K Kafka 集成

本教程介绍了如何在 Apache Kafka 中使用 Camel K。本教程介绍了如何为 Apache Kafka 设置 Kafka 主题,并使用它与 Camel K 结合使用。

先决条件

流程

  1. 克隆教程 Git 存储库:

    $ git clone git@github.com:openshift-integration/camel-k-example-kafka.git
  2. 在 VS Code 中,选择 FileOpen Foldercamel-k-example-kafka
  3. 在 VS Code 导航树中,右键单击 readme.didact.md 文件,再选择 Didact: Start Didact Tutorial from File。这会在 VS Code 中打开一个新的 Didact 选项卡,以显示教程说明。
  4. 按照教程说明,点提供的链接自动运行命令。

    或者,如果您没有使用 Didact 扩展安装 VS Code,您可以从 https://github.com/openshift-integration/camel-k-example-kafka 手动输入命令。