/** * Asynchronously consume all messages on the given topic from the cluster. * * @param topicName the name of the topic; may not be null * @param count the expected number of messages to read before terminating; may not be null * @param timeout the maximum time that this consumer should run before terminating; must be positive * @param unit the unit of time for the timeout; may not be null * @param completion the function to call when all messages have been consumed; may be null * @param consumer the function to consume the messages; may not be null */ public void consumeStrings(String topicName, int count, long timeout, TimeUnit unit, Runnable completion, BiPredicate<String, String> consumer) { AtomicLong readCounter = new AtomicLong(); consumeStrings(continueIfNotExpired(() -> readCounter.get() < count, timeout, unit), completion, Collections.singleton(topicName), record -> { if (consumer.test(record.key(), record.value())) readCounter.incrementAndGet(); }); }
/** * Asynchronously consume all messages on the given topic from the cluster. * * @param topicName the name of the topic; may not be null * @param count the expected number of messages to read before terminating; may not be null * @param timeout the maximum time that this consumer should run before terminating; must be positive * @param unit the unit of time for the timeout; may not be null * @param completion the function to call when all messages have been consumed; may be null * @param consumer the function to consume the messages; may not be null */ public void consumeIntegers(String topicName, int count, long timeout, TimeUnit unit, Runnable completion, BiPredicate<String, Integer> consumer) { AtomicLong readCounter = new AtomicLong(); consumeIntegers(continueIfNotExpired(() -> readCounter.get() < count, timeout, unit), completion, Collections.singleton(topicName), record -> { if (consumer.test(record.key(), record.value())) readCounter.incrementAndGet(); }); }
/** * Asynchronously consume all messages on the given topic from the cluster. * * @param topicName the name of the topic; may not be null * @param count the expected number of messages to read before terminating; may not be null * @param timeout the maximum time that this consumer should run before terminating; must be positive * @param unit the unit of time for the timeout; may not be null * @param completion the function to call when all messages have been consumed; may be null * @param consumer the function to consume the messages; may not be null */ public void consumeDocuments(String topicName, int count, long timeout, TimeUnit unit, Runnable completion, BiPredicate<String, Document> consumer) { AtomicLong readCounter = new AtomicLong(); consumeDocuments(continueIfNotExpired(() -> readCounter.get() < count, timeout, unit), completion, Collections.singleton(topicName), record -> { if (consumer.test(record.key(), record.value())) readCounter.incrementAndGet(); }); }