use of io.smallrye.reactive.messaging.kafka.companion.ConsumerTask in project smallrye-reactive-messaging by smallrye.
the class HeadersPropagationTest method testFromKafkaToAppToKafka.
@Test
void testFromKafkaToAppToKafka() {
final List<Headers> receivedContexts = new CopyOnWriteArrayList<>();
ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics("result-topic", m -> m.plug(until(10L, Duration.ofMinutes(1), null)).onItem().invoke(record -> receivedContexts.add(record.headers())));
runApplication(getKafkaSinkConfigForMyAppProcessingData(), MyApp.class);
final Headers producedheaders = new RecordHeaders();
producedheaders.add(new RecordHeader(FIRST_HEADER_TO_KEEP_KEY, FIRST_HEADER_TO_KEEP_VALUE.getBytes()));
producedheaders.add(new RecordHeader(SECOND_HEADER_TO_KEEP_KEY, SECOND_HEADER_TO_KEEP_VALUE.getBytes()));
producedheaders.add(new RecordHeader(THIRD_HEADER_TO_FILTER_KEY, THIRD_HEADER_TO_FILTER_VALUE.getBytes()));
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>("parent-topic", null, null, "a-key", i, producedheaders), 10);
await().atMost(Duration.ofMinutes(5)).until(() -> consumed.count() >= 10);
assertThat(consumed).extracting(ConsumerRecord::value).containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
assertThat(receivedContexts).hasSize(10).doesNotContainNull();
final long headerCount = receivedContexts.stream().filter(headers -> {
return containsHeaderWithValue(headers, FIRST_HEADER_TO_KEEP_KEY, FIRST_HEADER_TO_KEEP_VALUE) && containsHeaderWithValue(headers, SECOND_HEADER_TO_KEEP_KEY, SECOND_HEADER_TO_KEEP_VALUE) && !containsHeaderWithValue(headers, THIRD_HEADER_TO_FILTER_KEY, THIRD_HEADER_TO_FILTER_VALUE);
}).count();
assertEquals(10, headerCount);
}
Aggregations