本文整理汇总了Java中kafka.consumer.ConsumerIterator.nonEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java ConsumerIterator.nonEmpty方法的具体用法?Java ConsumerIterator.nonEmpty怎么用?Java ConsumerIterator.nonEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kafka.consumer.ConsumerIterator
的用法示例。
在下文中一共展示了ConsumerIterator.nonEmpty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConsumer
import kafka.consumer.ConsumerIterator; //导入方法依赖的package包/类
@Override
public Runnable getConsumer(final KafkaSynchronizedConsumerPool pool, final KafkaStream<byte[], byte[]> stream) {
return new Runnable() {
@Override
public void run() {
ConsumerIterator<byte[],byte[]> iter = stream.iterator();
// Iterate on the messages
TDeserializer deserializer = new TDeserializer(new TCompactProtocol.Factory());
KafkaOffsetCounters counters = pool.getCounters();
try {
while (iter.hasNext()) {
//
// Since the call to 'next' may block, we need to first
// check that there is a message available
//
boolean nonEmpty = iter.nonEmpty();
if (nonEmpty) {
MessageAndMetadata<byte[], byte[]> msg = iter.next();
counters.count(msg.partition(), msg.offset());
byte[] data = msg.message();
Sensision.update(SensisionConstants.CLASS_WARP_INGRESS_KAFKA_THROTTLING_IN_MESSAGES, Sensision.EMPTY_LABELS, 1);
Sensision.update(SensisionConstants.CLASS_WARP_INGRESS_KAFKA_THROTTLING_IN_BYTES, Sensision.EMPTY_LABELS, data.length);
if (null != macKey) {
data = CryptoUtils.removeMAC(macKey, data);
}
// Skip data whose MAC was not verified successfully
if (null == data) {
Sensision.update(SensisionConstants.CLASS_WARP_INGRESS_KAFKA_THROTTLING_IN_INVALIDMACS, Sensision.EMPTY_LABELS, 1);
continue;
}
//
// Update throttling manager
//
try {
ThrottlingManager.fuse(HyperLogLogPlus.fromBytes(data));
Sensision.update(SensisionConstants.CLASS_WARP_INGRESS_THROTLLING_FUSIONS, Sensision.EMPTY_LABELS, 1);
} catch (Exception e) {
Sensision.update(SensisionConstants.CLASS_WARP_INGRESS_THROTLLING_FUSIONS_FAILED, Sensision.EMPTY_LABELS, 1);
}
}
}
} catch (Throwable t) {
t.printStackTrace(System.err);
} finally {
// Set abort to true in case we exit the 'run' method
pool.getAbort().set(true);
}
}
};
}