Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-15686

Enable EndpointDSL with simple expressions within an Endpoint Builder bean

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Cannot Reproduce
    • None
    • 3.7.0
    • camel-endpointdsl
    • None
    • Experienced with 

      • Camel 3.4.4
      • Spring Boot 2.3.4
    • Unknown

    Description

      Injecting an EndpointProducerBuilder bean that uses a simple expression causes an exception.

      @Configuration
      public class MyTestRoute extends EndpointRouteBuilder {
         private static final String MY_TOPIC = "testTopic";
      
         @Autowired
         private EndpointProducerBuilder myKafkaBean;
      
         @Override
         public void configure() {
            from(timer("myTimer").repeatCount(1))
                  .setBody(constant("THIS IS A TEST MESSAGE"))
                  .setProperty("destination2", constant(MY_TOPIC))
                  .to("direct:publish-to-kafka2")
            ;
      
            from("direct:publish-to-kafka2")
                  .toD(myKafkaBean)
            ;
      
            from(kafka(MY_TOPIC))
                  .log("Received: ${body}")
            ;
         }
      
         @Bean
         public EndpointProducerBuilder myKafkaBean() {
            return kafka("${exchangeProperty.destination2}");
         }
      }

      Exception from org.apache.kafka.clients.Metadata:

      Metadata response reported invalid topics [${exchangeProperty.destination}]

      I don't have to use the bean for the error to manifest, it's enough to @Autowire it.

       

      It does work for static endpoints:

          return kafka("myTopic"); // This works fine from an EndpointProducerBuilder bean

      And it does work for dynamic endpoints in URI form:

          return "kafka:${exchangeProperty.destination}"; // This works fine but you lose type safety

       

      Creating beans like this is useful for unit testing as they can be overridden to return mock/direct/whatever-is-useful, without first creating the original endpoint, which can significantly reduce execution time.

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            FrankyG Franky Georg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: