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 终止终端中的日志记录。

其他资源

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.