0

A - 案例 1:Rest DSL 示例失败

我正在尝试应用用Apache Camel Rest DSL 组件编写的示例。Camel K的相同示例的简化版本如下所示;

import org.apache.camel.builder.RouteBuilder;

public class RestRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        
        // rest endpoints
        rest("/status")
            .get("/hello").to("direct:hello");
        
        // routes
        from("direct:hello")
            .transform().constant("Hello World");
        
    }

}

然后,构建失败如下;

levent.divilioglu:camel-k-ex $ kamel run RestRoute.java --dev
integration "rest-route" created
Progress: integration "rest-route" in phase Initialization
Condition "IntegrationPlatformAvailable" is "True" for Integration rest-route: default/camel-k
Progress: integration "rest-route" in phase Building Kit
Integration rest-route in phase "Initialization"
Condition "IntegrationPlatformAvailable" is "True" for Integration rest-route: default/camel-k
Integration rest-route in phase "Building Kit"
Condition "IntegrationKitAvailable" is "False" for Integration rest-route: creating a new integration kit
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Integration Kit) changed phase to "Build Submitted"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Scheduling"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Pending"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Running"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Integration Kit) changed phase to "Build Running"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Failed"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Initialization" (recovery 1 of 5)
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Scheduling" (recovery 1 of 5)
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Pending" (recovery 1 of 5)
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Running" (recovery 1 of 5)
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Failed" (recovery 1 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Initialization" (recovery 2 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Scheduling" (recovery 2 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Pending" (recovery 2 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Running" (recovery 2 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Failed" (recovery 2 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Initialization" (recovery 3 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Scheduling" (recovery 3 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Pending" (recovery 3 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Running" (recovery 3 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Failed" (recovery 3 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Initialization" (recovery 4 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Scheduling" (recovery 4 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Pending" (recovery 4 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Running" (recovery 4 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Failed" (recovery 4 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Initialization" (recovery 5 of 5)
Progress: integration "rest-route" in phase Error
Error: integration "rest-route" deployment failed

日志停止后,我看到它挂起,如下所示;

levent.divilioglu:camel-k-ex $ kamel get
NAME        PHASE   KIT
rest-route  Error   default/kit-c2o28iiqfl2hcn198ng0

B - 案例 2:如果添加了 Json Marshalling,则 Rest DSL 示例有效

然后我通过应用删除kamel delete rest-route,然后marshal().json在直接路由的末尾添加一个单独的,开始它就kamel run RestRoute.java --dev可以了;

import org.apache.camel.builder.RouteBuilder;

public class RestRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        
        // rest endpoints
        rest("/status")
            .get("/hello").to("direct:hello");
        
        // routes
        from("direct:hello")
            .transform().constant("Hello World")
            .marshal().json();
        
    }

}

C - 案例 3:Route 与评论的 Json Marshalling 一起使用

最有趣和最奇怪的行为就是这种情况。我注释掉了这marshal().json()条线,它继续工作。但是,即使我删除了这条注释行,它也不起作用。所以工作示例如下;

import org.apache.camel.builder.RouteBuilder;

public class RestRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        
        // rest endpoints
        rest("/status")
            .get("/hello").to("direct:hello");
        
        // routes
        from("direct:hello")
            .transform().constant("Hello World");
            //.marshal().json()
        
    }

}

D - 版本

MiniKube 版本;

minikube version: v1.17.1
commit: 043bdca07e54ab6e4fc0457e3064048f34133d7e

Apache Camel K 版本;

Apache Camel K Runtime 1.7.0

Camel K 客户端版本;

Camel K Client 1.4.0

E - 调查结果和问题

我哪里做错了?我刚刚使用了官方 apache 网站上给出的示例。有趣的事情是;

  • 该示例本身不起作用,但任何休息路线都需要 JSON 编组,即使内容是简单文本。
  • 注释行似乎在集成文件中执行;
//.marshal().json()

这是一个错误,还是官方Apache Camel Rest DSL 示例中存在问题?

4

0 回答 0