Skip to content

Commit 9f56b5d

Browse files
committed
Request/Reply Doc Polishing
1 parent 4b91ea6 commit 9f56b5d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/reference/asciidoc/kafka.adoc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,29 @@ In this case, all instances receive each reply, but only the instance that sent
656656
This may be useful for auto-scaling, but with the overhead of additional network traffic and the small cost of discarding each unwanted reply.
657657
When you use this setting, we recommend that you set the template's `sharedReplyTopic` to `true`, which reduces the logging level of unexpected replies to DEBUG instead of the default ERROR.
658658

659+
The following is an example of configuring the reply container to use the same shared reply topic:
660+
661+
====
662+
[source, java]
663+
----
664+
@Bean
665+
public ConcurrentMessageListenerContainer<String, String> replyContainer(
666+
ConcurrentKafkaListenerContainerFactory<String, String> containerFactory) {
667+
668+
ConcurrentMessageListenerContainer<String, String> container = containerFactory.createContainer("topic2");
669+
container.getContainerProperties().setGroupId(UUID.randomUUID().toString()); // unique
670+
Properties props = new Properties();
671+
props.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest"); // so the new group doesn't get old replies
672+
container.getContainerProperties().setKafkaConsumerProperties(props);
673+
return container;
674+
}
675+
----
676+
====
677+
659678
IMPORTANT: If you have multiple client instances and you do not configure them as discussed in the preceding paragraph, each instance needs a dedicated reply topic.
660679
An alternative is to set the `KafkaHeaders.REPLY_PARTITION` and use a dedicated partition for each instance.
661680
The `Header` contains a four-byte int (big-endian).
662-
The server must use this header to route the reply to the correct topic (`@KafkaListener` does this).
681+
The server must use this header to route the reply to the correct partition (`@KafkaListener` does this).
663682
In this case, though, the reply container must not use Kafka's group management feature and must be configured to listen on a fixed partition (by using a `TopicPartitionOffset` in its `ContainerProperties` constructor).
664683

665684
NOTE: The `DefaultKafkaHeaderMapper` requires Jackson to be on the classpath (for the `@KafkaListener`).

0 commit comments

Comments
 (0)