-
Notifications
You must be signed in to change notification settings - Fork 1.2k
GH-11183: Fix batch mode message ID generation in KafkaMessageDrivenChannelAdapter #11184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,7 @@ | |
| * @author Anshul Mehra | ||
| * @author Jooyoung Pyoung | ||
| * @author Glenn Renfro | ||
| * @author Zernov Oleksii | ||
| * | ||
| * @since 5.4 | ||
| */ | ||
|
|
@@ -123,6 +124,8 @@ public class KafkaDslTests { | |
|
|
||
| static final String TEST_TOPIC8 = "test-topic8"; | ||
|
|
||
| static final String TEST_TOPIC10 = "test-topic10"; | ||
|
|
||
| @Autowired | ||
| @Qualifier("sendToKafkaFlow.input") | ||
| private MessageChannel sendToKafkaFlowInput; | ||
|
|
@@ -133,6 +136,9 @@ public class KafkaDslTests { | |
| @Autowired | ||
| private PollableChannel listeningFromKafkaResults2; | ||
|
|
||
| @Autowired | ||
| private PollableChannel listeningFromKafkaResults3; | ||
|
|
||
| @Autowired | ||
| @Qualifier("kafkaProducer1.handler") | ||
| private KafkaProducerMessageHandler<?, ?> kafkaProducer1; | ||
|
|
@@ -155,6 +161,9 @@ public class KafkaDslTests { | |
| @Qualifier("kafkaTemplate:" + TEST_TOPIC2) | ||
| private KafkaTemplate<?, ?> kafkaTemplateTopic2; | ||
|
|
||
| @Autowired | ||
| private KafkaTemplate<Integer, String> kafkaTemplate; | ||
|
|
||
| @Autowired | ||
| private JsonKafkaHeaderMapper mapper; | ||
|
|
||
|
|
@@ -195,6 +204,7 @@ void testKafkaAdapters() throws Exception { | |
| assertThat(headers.containsKey(KafkaHeaders.ACKNOWLEDGMENT)).isTrue(); | ||
| Acknowledgment acknowledgment = headers.get(KafkaHeaders.ACKNOWLEDGMENT, Acknowledgment.class); | ||
| acknowledgment.acknowledge(); | ||
| assertThat(headers.get(MessageHeaders.ID)).isNotNull(); | ||
| assertThat(headers.get(KafkaHeaders.RECEIVED_TOPIC)).isEqualTo(TEST_TOPIC1); | ||
| assertThat(headers.get(KafkaHeaders.RECEIVED_KEY)).isEqualTo(i + 1); | ||
| assertThat(headers.get(KafkaHeaders.RECEIVED_PARTITION)).isEqualTo(0); | ||
|
|
@@ -211,6 +221,7 @@ void testKafkaAdapters() throws Exception { | |
| assertThat(headers.containsKey(KafkaHeaders.ACKNOWLEDGMENT)).isTrue(); | ||
| Acknowledgment acknowledgment = headers.get(KafkaHeaders.ACKNOWLEDGMENT, Acknowledgment.class); | ||
| acknowledgment.acknowledge(); | ||
| assertThat(headers.get(MessageHeaders.ID)).isNotNull(); | ||
| assertThat(headers.get(KafkaHeaders.RECEIVED_TOPIC)).isEqualTo(TEST_TOPIC2); | ||
| assertThat(headers.get(KafkaHeaders.RECEIVED_KEY)).isEqualTo(i + 1); | ||
| assertThat(headers.get(KafkaHeaders.RECEIVED_PARTITION)).isEqualTo(0); | ||
|
|
@@ -269,6 +280,17 @@ void channels(@Qualifier("topic6Channel") MessageChannel topic6Channel, | |
| .isEqualTo("foo"); | ||
| } | ||
|
|
||
| @Test | ||
| void testBatchListener() { | ||
| this.kafkaTemplate.send(TEST_TOPIC10, "foo"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, don't use Thanks |
||
|
|
||
| Message<?> receive = this.listeningFromKafkaResults3.receive(20000); | ||
| assertThat(receive).isNotNull(); | ||
| assertThat(receive.getPayload()).isEqualTo("foo"); | ||
| MessageHeaders headers = receive.getHeaders(); | ||
| assertThat(headers.get(MessageHeaders.ID)).isNotNull(); | ||
| } | ||
|
|
||
| @Configuration | ||
| @EnableIntegration | ||
| @EnableKafka | ||
|
|
@@ -341,6 +363,20 @@ public IntegrationFlow topic2ListenerFromKafkaFlow() { | |
| .get(); | ||
| } | ||
|
|
||
| @Bean | ||
| public IntegrationFlow batchListenerFromKafkaFlow() { | ||
| return IntegrationFlow | ||
| .from(Kafka | ||
| .messageDrivenChannelAdapter(consumerFactory(), | ||
| KafkaMessageDrivenChannelAdapter.ListenerMode.batch, TEST_TOPIC10) | ||
| .configureListenerContainer(c -> | ||
| c.ackMode(ContainerProperties.AckMode.MANUAL) | ||
| .id("topic10ListenerContainer"))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that we need any of these customization to proof the concept. |
||
| .split() | ||
| .channel(c -> c.queue("listeningFromKafkaResults3")) | ||
| .get(); | ||
| } | ||
|
|
||
| @Bean | ||
| public ProducerFactory<Integer, String> producerFactory() { | ||
| Map<String, Object> props = KafkaTestUtils.producerProps(this.embeddedKafkaBrokers); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the international naming convention is to express first name first.
See an example of my name in this list which is Ukrainian, too.