简体   繁体   English

Apache Camel Endpoint-dsl 自定义组件名称

[英]Apache Camel Endpoint-dsl custom component names

I am trying to use the Apache Camel 3 Endpoint DSL .我正在尝试使用 Apache Camel 3 Endpoint DSL This is my code so far.到目前为止,这是我的代码。 It works OK.它工作正常。 It is a test, so it is really simple.这是一个测试,所以它真的很简单。 It reads from a directory and log the file content.它从目录中读取并记录文件内容。

@Component
public class TestRoute extends EndpointRouteBuilder{
    final String componentName = "file";
    final String path = "/in/";
    
    @Override
    public void configure() throws Exception {      
        FileEndpointBuilder srcFileEndpoint = file(componentName, path);        
        from( srcFileEndpoint ).log(LoggingLevel.INFO, "body, ${body}");
    }//configure    
}//TestRoute

But when I try to change the name of the component.但是当我尝试更改组件的名称时。 For instance final String componentName = "myCustomFileComponent";例如 final String componentName = "myCustomFileComponent";

I get the following error in the console我在控制台中收到以下错误

Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: myCustomFileComponent:///in/ due to: No component found with scheme: myCustomFileComponent

From here , I understand I can provide custom names for the endpoints, myWMQ and myAMQ in the example.这里,我知道我可以为示例中的端点myWMQmyAMQ提供自定义名称。 For instance the route reads from a directory and writes to another, and I would like each component to be configured in different ways.例如,路由从一个目录读取并写入另一个目录,我希望每个组件都以不同的方式进行配置。 But if I specify a custom componentName, I get the error.但是,如果我指定一个自定义组件名称,我会收到错误消息。 Because it does not find the custonName component.因为它没有找到 custonName 组件。

I do not know if it is relevant, but the code is inside a Spring Boot project我不知道它是否相关,但代码在 Spring 引导项目中

  • Apache Camel version 3.4.0 Spring Boot version 2.3.1 Apache 骆驼版 3.4.0 Spring 引导版 2.3.1

It seems you are missing the point.看来你没有抓住重点。 That section explains if "multiple Camel components of the same type registered with different names".该部分解释了“相同类型的多个 Camel 组件以不同的名称注册”。 Those are camel components which are registered not the the uri of the endpoints.这些是注册的骆驼组件,而不是端点的 uri。

You cannot have dynamic route endpoints in apache camel as far as I know since the routes are created at start and those endpoint won't change at runtime.据我所知,您不能在 apache 骆驼中拥有动态路由端点,因为路由是在开始时创建的,并且这些端点在运行时不会改变。

If you need to have a route that reads from different endpoint what you can do is that having route for them and route those to same endpoint like:如果您需要一个从不同端点读取的路由,您可以做的是为它们设置路由并将它们路由到相同的端点,例如:

public class TestRoute extends RouteBuilder {

    @Override
    public void configure() {

        from(component1)
            .to("direct:myroute")

        from(component2)
            .to("direct:myroute")

        from(component3)
            .to("direct:myroute")

        from("direct:myroute")
            .log(LoggingLevel.INFO, "body, ${body}");
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM