本文整理汇总了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();
}
};
}
示例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++;
}
}
}
示例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();
}
};
}
示例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;
}
示例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;
}
}