/** * Get a new set of properties for consumers that want to talk to this server. * * @param groupId the group ID for the consumer; may not be null * @param clientId the optional identifier for the client; may be null if not needed * @param autoOffsetReset how to pick a starting offset when there is no initial offset in ZooKeeper or if an offset is * out of range; may be null for the default to be used * @return the mutable consumer properties * @see #getProducerProperties(String) */ public Properties getConsumerProperties(String groupId, String clientId, OffsetResetStrategy autoOffsetReset) { if (groupId == null) throw new IllegalArgumentException("The groupId is required"); Properties props = new Properties(); props.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, brokerList()); props.setProperty(ConsumerConfig.GROUP_ID_CONFIG, groupId); props.setProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, Boolean.FALSE.toString()); if (autoOffsetReset != null) { props.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, autoOffsetReset.toString().toLowerCase()); } if (clientId != null) props.setProperty(ConsumerConfig.CLIENT_ID_CONFIG, clientId); return props; }
Map<TopicPartition, Long> defaultOffsets; logger.info("The following partitions do not have existing offset data: {}", topicPartitionsWithUnknownOffset); if (unknownOffsetResetPosition.equals(OffsetResetStrategy.EARLIEST.toString().toLowerCase())) { logger.info("Using earliest offsets for partitions without existing offset data."); defaultOffsets = consumer.beginningOffsets(topicPartitionsWithUnknownOffset); } else if (unknownOffsetResetPosition.equals(OffsetResetStrategy.LATEST.toString().toLowerCase())) { logger.info("Using latest offsets for partitions without existing offset data."); defaultOffsets = consumer.endOffsets(topicPartitionsWithUnknownOffset); } else if (unknownOffsetResetPosition.equals(OffsetResetStrategy.NONE.toString().toLowerCase())) { logger.info("Will try to use existing consumer group offsets for partitions."); defaultOffsets = topicPartitionsWithUnknownOffset.stream() String.format("Unable to find committed offsets for consumer group for when %s=%s", ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, OffsetResetStrategy.NONE.toString().toLowerCase()));