AtomicBoolean keepReading = new AtomicBoolean(); OffsetCommitCallback offsetCommitCallback = null; consume(groupId, clientId, OffsetResetStrategy.EARLIEST, keyDeserializer, valueDeserializer, () -> keepReading.get(), offsetCommitCallback, completion, topicNames, record -> { consumed.add(record);
/** * Asynchronously consume all messages from the cluster. * * @param continuation the function that determines if the consumer should continue; may not be null * @param completion the function to call when all messages have been consumed; may be null * @param topics the set of topics to consume; may not be null or empty * @param consumerFunction the function to consume the messages; may not be null */ public void consumeStrings(BooleanSupplier continuation, Runnable completion, Collection<String> topics, java.util.function.Consumer<ConsumerRecord<String, String>> consumerFunction) { Deserializer<String> keyDes = new StringDeserializer(); Deserializer<String> valDes = keyDes; String randomId = UUID.randomUUID().toString(); OffsetCommitCallback offsetCommitCallback = null; consume(randomId, randomId, OffsetResetStrategy.EARLIEST, keyDes, valDes, continuation, offsetCommitCallback, completion, topics, consumerFunction); }
/** * Asynchronously consume all messages from the cluster. * * @param continuation the function that determines if the consumer should continue; may not be null * @param completion the function to call when all messages have been consumed; may be null * @param topics the set of topics to consume; may not be null or empty * @param consumerFunction the function to consume the messages; may not be null */ public void consumeDocuments(BooleanSupplier continuation, Runnable completion, Collection<String> topics, java.util.function.Consumer<ConsumerRecord<String, Document>> consumerFunction) { Deserializer<String> keyDes = new StringDeserializer(); Deserializer<Document> valDes = new DocumentSerdes(); String randomId = UUID.randomUUID().toString(); OffsetCommitCallback offsetCommitCallback = null; consume(randomId, randomId, OffsetResetStrategy.EARLIEST, keyDes, valDes, continuation, offsetCommitCallback, completion, topics, consumerFunction); }
/** * Asynchronously consume all messages from the cluster. * * @param continuation the function that determines if the consumer should continue; may not be null * @param completion the function to call when all messages have been consumed; may be null * @param topics the set of topics to consume; may not be null or empty * @param consumerFunction the function to consume the messages; may not be null */ public void consumeIntegers(BooleanSupplier continuation, Runnable completion, Collection<String> topics, java.util.function.Consumer<ConsumerRecord<String, Integer>> consumerFunction) { Deserializer<String> keyDes = new StringDeserializer(); Deserializer<Integer> valDes = new IntegerDeserializer(); String randomId = UUID.randomUUID().toString(); OffsetCommitCallback offsetCommitCallback = null; consume(randomId, randomId, OffsetResetStrategy.EARLIEST, keyDes, valDes, continuation, offsetCommitCallback, completion, topics, consumerFunction); }