Details
-
Improvement
-
Status: Resolved
-
Minor
-
Resolution: Cannot Reproduce
-
None
-
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.