本文整理汇总了Java中org.apache.kafka.clients.consumer.ConsumerRebalanceListener类的典型用法代码示例。如果您正苦于以下问题:Java ConsumerRebalanceListener类的具体用法?Java ConsumerRebalanceListener怎么用?Java ConsumerRebalanceListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConsumerRebalanceListener类属于org.apache.kafka.clients.consumer包,在下文中一共展示了ConsumerRebalanceListener类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subscribe
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
@Override
public void subscribe(Collection<String> topics, ConsumerRebalanceListener listener) {
super.subscribe(topics, listener);
Map<TopicPartition, Long> offsets = topics
.stream()
.flatMap(
topic -> IntStream
.range(0, KafkaMockFactory.NUMBER_OF_PARTITIONS)
.mapToObj(i -> new TopicPartition(topic, i)))
.collect(Collectors.toMap(Function.identity(), topicPartition -> 0L));
rebalance(offsets.keySet());
updateBeginningOffsets(offsets);
updateEndOffsets(offsets);
}
示例2: subscribe
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
@Override
public void subscribe(final Collection<String> topics, final ConsumerRebalanceListener callback) {
Retries.tryMe(new Runnable() {
@Override
public void run() {
inner.subscribe(topics, callback);
}
}, strategy());
}
示例3: subscribe
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
@Override public void subscribe(Collection<String> topics, ConsumerRebalanceListener listener) {
super.subscribe(topics, listener);
Map<TopicPartition, Long> offsets = new HashMap<>();
for (String topic : topics) {
TopicPartition partition1 = new TopicPartition(topic, 0);
offsets.put(partition1, 0L);
TopicPartition partition2 = new TopicPartition(topic, 1);
offsets.put(partition2, 0L);
}
rebalance(offsets.keySet());
updateBeginningOffsets(offsets);
updateEndOffsets(offsets);
}
示例4: subscribe
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
public void subscribe(Pattern pattern, ConsumerRebalanceListener listener) {
if (listener == null)
throw new IllegalArgumentException("RebalanceListener cannot be null");
setSubscriptionType(SubscriptionType.AUTO_PATTERN);
this.listener = listener;
this.subscribedPattern = pattern;
}
示例5: subscribe
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
@Override
public void subscribe(Collection<String> topics, ConsumerRebalanceListener callback) {
Set<String> newSubscription = new HashSet<>(topics);
// TODO: This is a hot fix for KAFKA-3664 and should be removed after the issue is fixed.
commitSync();
for (TopicPartition tp : _kafkaConsumer.assignment()) {
if (!newSubscription.contains(tp.topic())) {
_consumerRecordsProcessor.clear(tp);
}
}
_consumerRebalanceListener.setUserListener(callback);
_kafkaConsumer.subscribe(new ArrayList<>(topics), _consumerRebalanceListener);
}
示例6: subscribe
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
public void subscribe(Collection<String> topics, ConsumerRebalanceListener listener) {
if (listener == null)
throw new IllegalArgumentException("RebalanceListener cannot be null");
if (!this.userAssignment.isEmpty() || this.subscribedPattern != null)
throw new IllegalStateException(SUBSCRIPTION_EXCEPTION_MESSAGE);
this.listener = listener;
changeSubscription(topics);
}
示例7: subscribe
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
@Override
public void subscribe(Collection<String> topics, ConsumerRebalanceListener listener) {
consumer.subscribe(topics, listener);
}
示例8: subscribe
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
@Override public void subscribe(Collection<String> topics, ConsumerRebalanceListener callback) {
activeConsumer().subscribe(topics, callback);
}
示例9: subscribe
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
@Override public void subscribe(Collection<String> topics, ConsumerRebalanceListener callback) {
}
示例10: listener
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
public ConsumerRebalanceListener listener() {
return listener;
}
示例11: getRebalanceListener
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
public ConsumerRebalanceListener getRebalanceListener() {
return rebalanceListener;
}
示例12: setUserListener
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
public void setUserListener(ConsumerRebalanceListener userListener) {
_userListener = userListener;
}
示例13: subscribe
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener; //导入依赖的package包/类
/**
* Subscribe to the given list of topics to get dynamically
* assigned partitions. <b>Topic subscriptions are not incremental. This list will replace the current
* assignment (if there is one).</b> Note that it is not possible to combine topic subscription with group management
* with manual partition assignment through {@link #assign(Collection)}.
* <p>
* If the given list of topics is empty, it is treated the same as {@link #unsubscribe()}.
* <p>
* As part of group management, the consumer will keep track of the list of consumers that belong to a particular
* group and will trigger a rebalance operation if one of the following events trigger -
* <ul>
* <li>Number of partitions change for any of the subscribed list of topics
* <li>Topic is created or deleted
* <li>An existing member of the consumer group dies
* <li>A new member is added to an existing consumer group via the join API
* </ul>
* <p>
* When any of these events are triggered, the provided listener will be invoked first to indicate that
* the consumer's assignment has been revoked, and then again when the new assignment has been received.
* Note that this listener will immediately override any listener set in a previous call to subscribe.
* It is guaranteed, however, that the partitions revoked/assigned through this interface are from topics
* subscribed in this call. See {@link ConsumerRebalanceListener} for more details.
* <p>
* In order to support large message, the consumer tracks all the consumed messages for each partition. When the
* user no longer subscribes to a new set of topics, the consumer will discard all the tracked messages of the
* partitions of that topic.
*
* @param topics The list of topics to subscribe to
* @param callback Non-null listener instance to get notifications on partition assignment/revocation for the
* subscribed topics
*/
@InterfaceOrigin.ApacheKafka
void subscribe(Collection<String> topics, ConsumerRebalanceListener callback);