Skip to content

GH-11183: Fix batch mode message ID generation in KafkaMessageDrivenChannelAdapter#11184

Merged
artembilan merged 3 commits into
spring-projects:mainfrom
Zernov-A:GH-11183
Jul 15, 2026
Merged

GH-11183: Fix batch mode message ID generation in KafkaMessageDrivenChannelAdapter#11184
artembilan merged 3 commits into
spring-projects:mainfrom
Zernov-A:GH-11183

Conversation

@Zernov-A

Copy link
Copy Markdown
Contributor

Fixes #11183

When using Kafka.messageDrivenChannelAdapter with ListenerMode.batch followed by a .split(), the splitter fails because the batch message doesn't have a message ID generated. This is required by the splitter to properly set correlation headers on split messages.

The root cause was that the constructor was setting the same MessagingMessageConverter (intended for record mode) on the batch listener instead of creating a proper BatchMessagingMessageConverter with message ID generation enabled.

This fix ensures that when in batch mode, a BatchMessagingMessageConverter is created with setGenerateMessageId(true) and setGenerateTimestamp(true), similar to how it's done for record mode.

Changes

  • Modified KafkaMessageDrivenChannelAdapter constructor to properly configure BatchMessagingMessageConverter for batch mode
  • Added test case testBatchListener() in KafkaDslTests to verify the fix
  • Added assertions for message ID in existing tests to ensure consistency

…aMessageDrivenChannelAdapter

Fixes: spring-projectsgh-11183
Signed-off-by: zernov-a <zernov.a.i.90@gmail.com>

@artembilan artembilan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add your name to the @author list of the affected classes.

Looking good!

Thank you!

@@ -153,7 +153,13 @@ else if (JacksonPresent.isJackson2Present()) {
.toArray(new String[0]));
messageConverter.setHeaderMapper(headerMapper);
this.recordListener.setMessageConverter(messageConverter);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the this.recordListener.setMessageConverter() should go outside of the if..else, too.

…nChannelAdapter

Signed-off-by: zernov-a <zernov.a.i.90@gmail.com>
@Zernov-A

Zernov-A commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Please, add your name to the @author list of the affected classes.

Looking good!

Thank you!

Thank you for the review! I've added the @author tag and moved setMessageConverter() outside the if..else blocks as requested.

@artembilan artembilan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.
Just couple minors.
Thanks

* @author Artem Bilan
* @author Urs Keller
* @author Jooyoung Pyoung
* @author Zernov Oleksii

Copy link
Copy Markdown
Member

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.


@Test
void testBatchListener() {
this.kafkaTemplate.send(TEST_TOPIC10, "foo");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, don't use foo/bar language in the code.
I know we have a lot of them already there, but we prefer to get rid of it eventually.

Thanks

KafkaMessageDrivenChannelAdapter.ListenerMode.batch, TEST_TOPIC10)
.configureListenerContainer(c ->
c.ackMode(ContainerProperties.AckMode.MANUAL)
.id("topic10ListenerContainer")))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.
I mean the goal of this specific test to make sure splitter doesn't fail.
So, what container id or what mode, doesn't matter.
Therefore redundant from the readability perspective.
Less code in the test - less chance of bugs in tests 😄

Signed-off-by: zernov-a <zernov.a.i.90@gmail.com>
@artembilan
artembilan enabled auto-merge (squash) July 15, 2026 19:55
@artembilan
artembilan merged commit 57006c2 into spring-projects:main Jul 15, 2026
3 checks passed

@artembilan artembilan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Will be merged automatically when PR build is green.

Thank you for contribution; looking forward for more!

For the future: all the info you have included into PR description, could simply go to the first commit - and it becomes that PR description.
Now I had to add it to the final commit manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KafkaMessageDrivenChannelAdapter in batch mode doesn't generate message ID, causing splitter to fail

2 participants