Search in sources :

Example 1 with ByteBufferMessageSet

use of kafka.message.ByteBufferMessageSet in project incubator-gobblin by apache.

the class MockKafkaStream method pushToStream.

public void pushToStream(String message) {
    int streamNo = (int) this.nextStream.incrementAndGet() % this.queues.size();
    AtomicLong offset = this.offsets.get(streamNo);
    BlockingQueue<FetchedDataChunk> queue = this.queues.get(streamNo);
    AtomicLong thisOffset = new AtomicLong(offset.incrementAndGet());
    List<Message> seq = Lists.newArrayList();
    seq.add(new Message(message.getBytes(Charsets.UTF_8)));
    ByteBufferMessageSet messageSet = new ByteBufferMessageSet(NoCompressionCodec$.MODULE$, offset, JavaConversions.asScalaBuffer(seq));
    FetchedDataChunk chunk = new FetchedDataChunk(messageSet, new PartitionTopicInfo("topic", streamNo, queue, thisOffset, thisOffset, new AtomicInteger(1), "clientId"), thisOffset.get());
    queue.add(chunk);
}
Also used : PartitionTopicInfo(kafka.consumer.PartitionTopicInfo) AtomicLong(java.util.concurrent.atomic.AtomicLong) Message(kafka.message.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FetchedDataChunk(kafka.consumer.FetchedDataChunk) ByteBufferMessageSet(kafka.message.ByteBufferMessageSet)

Example 2 with ByteBufferMessageSet

use of kafka.message.ByteBufferMessageSet in project graylog2-server by Graylog2.

the class KafkaJournal method flushMessages.

private long flushMessages(List<Message> messages, long payloadSize) {
    if (messages.isEmpty()) {
        LOG.debug("No messages to flush, not trying to write an empty message set.");
        return -1L;
    }
    final ByteBufferMessageSet messageSet = new ByteBufferMessageSet(JavaConversions.asScalaBuffer(messages).toSeq());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Trying to write ByteBufferMessageSet with size of {} bytes to journal", messageSet.sizeInBytes());
    }
    final LogAppendInfo appendInfo = kafkaLog.append(messageSet, true);
    long lastWriteOffset = appendInfo.lastOffset();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Wrote {} messages to journal: {} bytes (payload {} bytes), log position {} to {}", messages.size(), messageSet.sizeInBytes(), payloadSize, appendInfo.firstOffset(), lastWriteOffset);
    }
    writtenMessages.mark(messages.size());
    return lastWriteOffset;
}
Also used : LogAppendInfo(kafka.log.LogAppendInfo) ByteBufferMessageSet(kafka.message.ByteBufferMessageSet)

Aggregations

ByteBufferMessageSet (kafka.message.ByteBufferMessageSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 FetchedDataChunk (kafka.consumer.FetchedDataChunk)1 PartitionTopicInfo (kafka.consumer.PartitionTopicInfo)1 LogAppendInfo (kafka.log.LogAppendInfo)1 Message (kafka.message.Message)1