You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2022/09/03 12:16:00 UTC
[jira] [Resolved] (CAMEL-17880) Testing facilities does not work as expected for dynamic Kafka endpoint
[ https://issues.apache.org/jira/browse/CAMEL-17880?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Claus Ibsen resolved CAMEL-17880.
---------------------------------
Resolution: Not A Bug
> Testing facilities does not work as expected for dynamic Kafka endpoint
> -----------------------------------------------------------------------
>
> Key: CAMEL-17880
> URL: https://issues.apache.org/jira/browse/CAMEL-17880
> Project: Camel
> Issue Type: Improvement
> Components: camel-kafka
> Affects Versions: 3.14.2
> Reporter: Roman Sydorov
> Priority: Minor
>
> Kafka Camel endpoint has optimization inside that makes Camel testing facilities not work as expected if dynamic endpoint used:
>
> {code:java}
> private static final String OUTPUT_TOPIC = "OutputTopic";
> ...
> private void setOutputTopic(Exchange exchange) {
> //some other code
> exchange.setProperty(OUTPUT_TOPIC,"MyKafkaTopic");
> }
> ...
> @Override
> public void configure() {
> from("direct:someEndpoint")
> .process(this::setOutputTopic)
> ...
> .toD("kafka:${exchangeProperty." + OUTPUT_TOPIC + "}");
> } {code}
>
> In this case, [KafkaSendDynamicAware|https://github.com/apache/camel/blob/main/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaSendDynamicAware.java#L70] will create an endpoint with URI \{{kafka:$%7BexchangeProperty.OutputTopic%7D}} and will put resolved Kafka topic name to \{{KafkaConstants.OVERRIDE_TOPIC}} header that will be used in [KafkaProducer|https://github.com/apache/camel/blob/main/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaProducer.java#L288] during message sending. This makes @MockEndpointsAndSkip, and @EndpointInject work not as expected. You would need to do something like:
>
> {code:java}
> @MockEndpointsAndSkip("kafka://$%7BexchangeProperty.OutputTopic%7D")
> ...
> @EndpointInject("mock:kafka:$%7BexchangeProperty.OutputTopic%7D")
> private MockEndpoint pasciAccountStatementsTopic; {code}
> to be able to assert endpoint.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)