Skip to content

Commit

Permalink
Make consumer groups unique to instance
Browse files Browse the repository at this point in the history
  • Loading branch information
iyourshaw committed Dec 19, 2024
1 parent 1c8fc66 commit 84f77e9
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ private Map<String, Object> commonProps(final String id) {

props.put(ConsumerConfig.CLIENT_ID_CONFIG, id);

// Make the consumer group id be unique to the instance to prevent consumers forming into groups
// if running more than one instance
String groupIdSuffix;
try {
groupIdSuffix = InetAddress.getLocalHost().toString();
Expand All @@ -109,6 +111,8 @@ private Map<String, Object> commonProps(final String id) {
}
final String groupId = id + "_" + groupIdSuffix;
props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
log.info("Consumer group ID = {}", groupId);

props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
props.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, 100);
Expand Down

0 comments on commit 84f77e9

Please sign in to comment.