@Override public ReceiverOptions<K, V> assignment(Collection<TopicPartition> partitions) { return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, keyDeserializer, valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxCommitAttempts, null, Objects.requireNonNull(partitions), null, schedulerSupplier ); }
@Override public String groupId() { return (String) consumerProperty(ConsumerConfig.GROUP_ID_CONFIG); }
@Override public Duration heartbeatInterval() { long defaultValue = 3000; // Kafka default long heartbeatIntervalMs = getLongOption(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, defaultValue); return Duration.ofMillis(heartbeatIntervalMs); }
@Override public ReceiverOptions<K, V> withKeyDeserializer(Deserializer<K> keyDeserializer) { return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, Objects.requireNonNull(keyDeserializer), valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxCommitAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }
@Override public String groupId() { return (String) consumerProperty(ConsumerConfig.GROUP_ID_CONFIG); }
@Override public Duration heartbeatInterval() { long defaultValue = 3000; // Kafka default long heartbeatIntervalMs = getLongOption(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, defaultValue); return Duration.ofMillis(heartbeatIntervalMs); }
@Override public ReceiverOptions<K, V> withValueDeserializer(Deserializer<V> valueDeserializer) { return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, keyDeserializer, Objects.requireNonNull(valueDeserializer), pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxCommitAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }
private long getLongOption(String optionName, long defaultValue) { Objects.requireNonNull(optionName); Object value = consumerProperty(optionName); long optionValue = 0; if (value != null) { if (value instanceof Long) optionValue = (Long) value; else if (value instanceof String) optionValue = Long.parseLong((String) value); else throw new ConfigException("Invalid value " + value); } else optionValue = defaultValue; return optionValue; } }
@Override public ReceiverOptions<K, V> maxCommitAttempts(int maxAttempts) { if (maxAttempts < 0) throw new IllegalArgumentException("the number of attempts must be >= 0"); return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, keyDeserializer, valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }
private long getLongOption(String optionName, long defaultValue) { Objects.requireNonNull(optionName); Object value = consumerProperty(optionName); long optionValue = 0; if (value != null) { if (value instanceof Long) optionValue = (Long) value; else if (value instanceof String) optionValue = Long.parseLong((String) value); else throw new ConfigException("Invalid value " + value); } else optionValue = defaultValue; return optionValue; } }
@Override public ReceiverOptions<K, V> withValueDeserializer(Deserializer<V> valueDeserializer) { return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, keyDeserializer, Objects.requireNonNull(valueDeserializer), pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxCommitAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }
@Override public ReceiverOptions<K, V> assignment(Collection<TopicPartition> partitions) { return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, keyDeserializer, valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxCommitAttempts, null, Objects.requireNonNull(partitions), null, schedulerSupplier ); }
@Override public ReceiverOptions<K, V> atmostOnceCommitAheadSize(int commitAheadSize) { if (commitAheadSize < 0) throw new IllegalArgumentException("Commit ahead size must be >= 0"); return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, keyDeserializer, valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, commitAheadSize, maxCommitAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }
@Override public ReceiverOptions<K, V> withKeyDeserializer(Deserializer<K> keyDeserializer) { return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, Objects.requireNonNull(keyDeserializer), valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxCommitAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }
@Override public ReceiverOptions<K, V> maxCommitAttempts(int maxAttempts) { if (maxAttempts < 0) throw new IllegalArgumentException("the number of attempts must be >= 0"); return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, keyDeserializer, valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }
@Override public ReceiverOptions<K, V> commitBatchSize(int commitBatchSize) { if (commitBatchSize < 0) throw new IllegalArgumentException("Commit batch size must be >= 0"); return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, keyDeserializer, valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxCommitAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }
@Override public ReceiverOptions<K, V> commitBatchSize(int commitBatchSize) { if (commitBatchSize < 0) throw new IllegalArgumentException("Commit batch size must be >= 0"); return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, keyDeserializer, valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxCommitAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }
@Override public ReceiverOptions<K, V> atmostOnceCommitAheadSize(int commitAheadSize) { if (commitAheadSize < 0) throw new IllegalArgumentException("Commit ahead size must be >= 0"); return new ImmutableReceiverOptions<>( properties, assignListeners, revokeListeners, keyDeserializer, valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, commitAheadSize, maxCommitAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }
@Override public ReceiverOptions<K, V> clearRevokeListeners() { return new ImmutableReceiverOptions<>( properties, assignListeners, new ArrayList<>(), keyDeserializer, valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxCommitAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }
@Override public ReceiverOptions<K, V> clearRevokeListeners() { return new ImmutableReceiverOptions<>( properties, assignListeners, new ArrayList<>(), keyDeserializer, valueDeserializer, pollTimeout, closeTimeout, commitInterval, commitBatchSize, atmostOnceCommitAheadSize, maxCommitAttempts, subscribeTopics, assignTopicPartitions, subscribePattern, schedulerSupplier ); }