简体   繁体   English

具有多个 lambda 端点的 Spring Boot + Apache Camel + AWS Lambda

[英]Spring Boot + Apache Camel + AWS Lambda with multiple lambda endpoints

I am learning Apache Camel and how to use it with Spring Boot.我正在学习 Apache Camel 以及如何在 Spring Boot 中使用它。 I have been able to successfully hit one lambda function using Camel and Spring and so far it works great.我已经能够使用 Camel 和 Spring 成功命中一个 lambda 函数,到目前为止效果很好。 However I'm having trouble when I try to add a second function that I want to hit using a different route.但是,当我尝试添加我想使用不同路线点击的第二个功能时遇到了问题。

At a core, the problem I'm having is that it seems Camel requires that the property camel.component.aws-lambda.configuration.function is defined in order to create an endpoint.在核心,我遇到的问题是,似乎 Camel 需要定义属性camel.component.aws-lambda.configuration.function以创建端点。 But obviously I don't want to define that property because I need to have multiple functions, not just a single one.但显然我不想定义那个属性,因为我需要有多个功能,而不仅仅是一个。

Current code that works:当前有效的代码:

application.yaml:应用程序.yaml:

camel:
  component:
    aws-lambda:
      configuration:
        access-key: myAccessKey
        secret-key: mySecretKey
        region: MY_REGION
        function: myFunction
        operation: invokeFunction

My route:我的路线:

@Component
public class MessageTestInvocationRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("somewhere").routeId("lambda")
                .to("aws-lambda://myFunction");
    }
}

Now how can I add a second route?现在如何添加第二条路线? As soon as I comment out the camel.component.aws-lambda.configuration.function property, my existing route breaks due to an NPE.一旦我注释掉camel.component.aws-lambda.configuration.function属性,我现有的路由就会由于NPE 而中断。 But if I leave that property defined, then it seems all AWS calls will be tied to that one function.但是,如果我保留该属性的定义,那么似乎所有 AWS 调用都将绑定到该函数。

I have tried looking into making custom LambdaComponent s, I have tried looking into making custom AWSLambdaClient s, none of these did anything useful - it all falls apart as soon as I comment out that property.我尝试过制作自定义LambdaComponent s,我尝试过制作自定义AWSLambdaClient s,但这些都没有做任何有用的事情 - 一旦我注释掉该属性,它就会崩溃。

I figured it out.我想到了。 The reason I was getting an NPE is because I did not have an operation defined.我获得 NPE 的原因是我没有定义操作。 When the function and operation are defined in application.yaml , then Spring attempts to use that one, which is why commenting out those properties caused that issue.当在application.yaml中定义函数和操作时,Spring 会尝试使用该函数和操作,这就是注释掉这些属性会导致该问题的原因。 The solution was to comment out the function and operation properties, and then change my route code to:解决办法是把functionoperation属性注释掉,然后把我的路由代码改成:

@Component
public class MessageTestInvocationRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("somewhere").routeId("lambda")
                .to("aws-lambda://myFunction?operation=invokeFunction");
    }
}

Now I am able to create multiple routes that all function just fine in parallel.现在我可以创建多个并行运行的路由。

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

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