当前位置: 首页>>代码示例>>Java>>正文


Java ByteBufferMessageSet.iterator方法代码示例

本文整理汇总了Java中kafka.javaapi.message.ByteBufferMessageSet.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBufferMessageSet.iterator方法的具体用法?Java ByteBufferMessageSet.iterator怎么用?Java ByteBufferMessageSet.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kafka.javaapi.message.ByteBufferMessageSet的用法示例。


在下文中一共展示了ByteBufferMessageSet.iterator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFetchedMessages

import kafka.javaapi.message.ByteBufferMessageSet; //导入方法依赖的package包/类
/**
 * Creates an Iterator of FetchedMessage based on the given message set. The iterator would also updates
 * the offset while iterating.
 */
private Iterator<FetchedMessage> createFetchedMessages(ByteBufferMessageSet messageSet, final AtomicLong offset) {
  final Iterator<MessageAndOffset> messages = messageSet.iterator();
  return new AbstractIterator<FetchedMessage>() {
    @Override
    protected FetchedMessage computeNext() {
      while (messages.hasNext()) {
        MessageAndOffset message = messages.next();
        long msgOffset = message.offset();
        if (msgOffset < offset.get()) {
          LOG.trace("Received old offset {}, expecting {} on {}. Message Ignored.",
                    msgOffset, offset.get(), topicPart);
          continue;
        }

        fetchedMessage.setPayload(message.message().payload());
        fetchedMessage.setOffset(message.offset());
        fetchedMessage.setNextOffset(message.nextOffset());

        return fetchedMessage;
      }
      return endOfData();
    }
  };
}
 
开发者ID:apache,项目名称:twill,代码行数:29,代码来源:SimpleKafkaConsumer.java

示例2: run

import kafka.javaapi.message.ByteBufferMessageSet; //导入方法依赖的package包/类
@Override
  public void run()
  {
    long offset = 0;
    while (isAlive) {
      // create a fetch request for topic “topic1”, partition 0, current offset, and fetch size of 1MB
      FetchRequest fetchRequest = new FetchRequestBuilder().clientId("default_client").addFetch("topic1", 1, offset, 1000000).build();

//      FetchRequest fetchRequest = new FetchRequest("topic1", 0, offset, 1000000);

      // get the message set from the consumer and print them out
      ByteBufferMessageSet messages = consumer.fetch(fetchRequest).messageSet("topic1", 1);
      Iterator<MessageAndOffset> itr = messages.iterator();

      while (itr.hasNext() && isAlive) {
        MessageAndOffset msg = itr.next();
        // advance the offset after consuming each message
        offset = msg.offset();
        logger.debug("consumed: {} offset: {}", byteBufferToString(msg.message().payload()).toString(), offset);
        receiveCount++;
      }
    }
  }
 
开发者ID:apache,项目名称:apex-malhar,代码行数:24,代码来源:KafkaSimpleConsumer.java

示例3: createFetchedMessages

import kafka.javaapi.message.ByteBufferMessageSet; //导入方法依赖的package包/类
/**
 * Creates an Iterator of FetchedMessage based on the given message set. The iterator would also updates
 * the offset while iterating.
 */
private Iterator<FetchedMessage> createFetchedMessages(ByteBufferMessageSet messageSet, final AtomicLong offset) {
  final Iterator<MessageAndOffset> messages = messageSet.iterator();
  return new AbstractIterator<FetchedMessage>() {
    @Override
    protected FetchedMessage computeNext() {
      while (messages.hasNext()) {
        MessageAndOffset message = messages.next();
        long msgOffset = message.offset();
        if (msgOffset < offset.get()) {
          LOG.trace("Received old offset {}, expecting {} on {}. Message Ignored.",
                    msgOffset, offset.get(), topicPart);
          continue;
        }

        offset.set(message.nextOffset());
        fetchedMessage.setPayload(message.message().payload());
        fetchedMessage.setNextOffset(offset.get());

        return fetchedMessage;
      }
      return endOfData();
    }
  };
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:29,代码来源:SimpleKafkaConsumer.java

示例4: getNext

import kafka.javaapi.message.ByteBufferMessageSet; //导入方法依赖的package包/类
public boolean getNext(KafkaETLKey key, BytesWritable value) throws IOException {
    if ( !hasMore() ) return false;
    
    boolean gotNext = get(key, value);

    if(_response != null) {

        while ( !gotNext && _respIterator.hasNext()) {
            ByteBufferMessageSet msgSet = _respIterator.next();
            if ( hasError(msgSet)) return false;
            _messageIt = msgSet.iterator();
            gotNext = get(key, value);
        }
    }
    return gotNext;
}
 
开发者ID:yanfang724,项目名称:hadoop-consumer,代码行数:17,代码来源:KafkaETLContext.java

示例5: getIteratorFromFetchResponse

import kafka.javaapi.message.ByteBufferMessageSet; //导入方法依赖的package包/类
private Iterator<MessageAndOffset> getIteratorFromFetchResponse(FetchResponse fetchResponse,
    KafkaPartition partition) {
  try {
    ByteBufferMessageSet messageBuffer = fetchResponse.messageSet(partition.getTopicName(), partition.getId());
    return messageBuffer.iterator();
  } catch (Exception e) {
    LOG.warn(String.format("Failed to retrieve next message buffer for partition %s: %s."
        + "The remainder of this partition will be skipped.", partition, e));
    return null;
  }
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:12,代码来源:KafkaWrapper.java


注:本文中的kafka.javaapi.message.ByteBufferMessageSet.iterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。