| = LambdaRouteBuilder |
| |
| The `LambdaRouteBuilder` is a functional interface which is used for creating a routing rule using the xref:dsl.adoc[DSL], |
| using Java lambda style. |
| |
| [source,java] |
| ---- |
| rb -> rb.from("timer:foo").log("Hello Lambda"); |
| ---- |
| |
| Instances of `LambdaRouteBuilder` are discovered and transformed into `RouteBuilder` instances |
| which are added to the CamelContext. |
| |
| == Usage |
| |
| To use `LambdaRouteBuilder` you need to create a method that returns `LambdaRouteBuilder` which then |
| allows to use Java lambda style to define a single route. |
| |
| In the example below the method `myRoute` is used to create a Camel route that consumes from Kafka and sends the messages to JMS. |
| |
| To make the route discoverable by Camel during startup, then the method must be annotated. |
| The method should be annotated with `@BindToRegistry` in standalone mode with `camel-main`, `@Bean` in case of Spring Boot or `@Produce` in case of Quarkus. |
| |
| [source,java] |
| ---- |
| public class MyConfiguration { |
| @BindToRegistry |
| public LambdaRouteBuilder myRoute() { |
| return rb -> rb.from("kafka:cheese").to("jms:queue:foo"); |
| } |
| } |
| ---- |
| |
| == LambdaEndpointRouteBuilder |
| |
| The xref:Endpoint-dsl.adoc[Endpoint DSL] can also be used as a lambda route builder with the |
| `org.apache.camel.builder.endpoint.LambdaEndpointRouteBuilder` class from the `camel-endpointdsl` JAR. |
| |
| [source,java] |
| ---- |
| public class MyConfiguration { |
| @BindToRegistry |
| public LambdaEndpointRouteBuilder myRoute() { |
| return rb -> rb.from(rb.kafka("cheese")).to(rb.jms("queue:foo")); |
| } |
| } |
| ---- |
| |
| The `LambdaEndpointRouteBuilder` has _type safe_ endpoint but requires to prefix with the instance name (`rb`) |
| when choosing an endpoint name. Notice above how to select the kafka endpoint |
| |
| [source,java] |
| ---- |
| rb.from(rb.kafka("cheese")) |
| ---- |
| |
| With the regular `LambdaRouteBuilder` it's just a `String` type, so the `rb` prefix is not needed anymore: |
| |
| [source,java] |
| ---- |
| rb.from("kafka:cheese") |
| ---- |