Examples of ByteBufferMessageSet


Examples of kafka.javaapi.message.ByteBufferMessageSet

            String instanceId = (String) meta.get("instanceId");
            if(!_config.forceFromStart || instanceId.equals(_topologyInstanceId)) {
                SimpleConsumer consumer = _connections.getConsumer(partition);
                long offset = (Long) meta.get("offset");
                long nextOffset = (Long) meta.get("nextOffset");
                ByteBufferMessageSet msgs = consumer.fetch(new FetchRequest(_config.topic, partition % partitionsPerHost, offset, _config.fetchSizeBytes));
                for(MessageAndOffset msg: msgs) {
                    if(offset == nextOffset) break;
                    if(offset > nextOffset) {
                        throw new RuntimeException("Error when re-emitting batch. overshot the end offset");
                    }
View Full Code Here

Examples of kafka.javaapi.message.ByteBufferMessageSet

         } else {
             long startTime = -1;
             if(config.forceFromStart) startTime = config.startOffsetTime;
             offset = consumer.getOffsetsBefore(config.topic, partition % hosts.partitionsPerHost, startTime, 1)[0];
         }
         ByteBufferMessageSet msgs;
         try {
            msgs = consumer.fetch(new FetchRequest(config.topic, partition % hosts.partitionsPerHost, offset, config.fetchSizeBytes));
         } catch(Exception e) {
             if(e instanceof ConnectException) {
                 throw new FailedFetchException(e);
View Full Code Here

Examples of kafka.javaapi.message.ByteBufferMessageSet

        boolean gotNext = get(key, value);

        if(_response != null) {
            Iterator<ByteBufferMessageSet> iter = _response.iterator();
            while ( !gotNext && iter.hasNext()) {
                ByteBufferMessageSet msgSet = iter.next();
                if ( hasError(msgSet)) return false;
                _messageIt =  (Iterator<MessageAndOffset>) msgSet.iterator();
                gotNext = get(key, value);
            }
        }
        return gotNext;
    }
View Full Code Here

Examples of kafka.javaapi.message.ByteBufferMessageSet

                                                       KafkaProperties.connectionTimeOut,
                                                       KafkaProperties.kafkaProducerBufferSize);

    System.out.println("Testing single fetch");
    FetchRequest req = new FetchRequest(KafkaProperties.topic2, 0, 0L, 100);
    ByteBufferMessageSet messageSet = simpleConsumer.fetch(req);
    printMessages(messageSet);

    System.out.println("Testing single multi-fetch");
    req = new FetchRequest(KafkaProperties.topic2, 0, 0L, 100);
    List<FetchRequest> list = new ArrayList<FetchRequest>();
View Full Code Here

Examples of kafka.javaapi.message.ByteBufferMessageSet

      Message message = new Message(bytes);
      list.add(message);
    }
    // send events
    System.out.println(" send " + list.size() + " " + _topic + " count events to " + _uri);
    _producer.send(_topic, new ByteBufferMessageSet(kafka.message.NoCompressionCodec$.MODULE$, list));

    // close the producer
    _producer.close();
   
    // generate offset files
View Full Code Here

Examples of kafka.message.ByteBufferMessageSet

      list.add(message);
    }
    // send events
    System.out.println(" send " + list.size() + " " + _topic
        + " count events to " + producerId);
    producer.send(_topic, new ByteBufferMessageSet(list));

    // close all producers
    for (SimpleProducer p : _producers) {
      p.close();
    }
View Full Code Here

Examples of kafka.message.ByteBufferMessageSet

      for(int i = 0; i < batchSize; i++)
      {
        Message message = new Message(new byte[messageSize]);
        messageList.add(message);
      }
      ByteBufferMessageSet set = new ByteBufferMessageSet(messageList);
      producer.send(topic, random.nextInt(numParts), set);
      bytesSent.getAndAdd(batchSize * messageSize);
      messagesSent.getAndAdd(messageList.size());
    }
  }
View Full Code Here

Examples of kafka.message.ByteBufferMessageSet

        list.add(req);
      }
      MultiFetchResponse response = simpleConsumer.multifetch(list);
      if(response.hasNext())
      {
        ByteBufferMessageSet messages = response.next();
        offset+= messages.validBytes();
        bytesRec.getAndAdd(messages.sizeInBytes());
       
        Iterator<Message> it =  messages.iterator();
        while(it.hasNext())
        {
          it.next();
          messagesRec.getAndIncrement();
        }
View Full Code Here

Examples of kafka.message.ByteBufferMessageSet

      tempTime = System.currentTimeMillis();
      MultiFetchResponse response = _consumer.multifetch(array);
      requestTime += (System.currentTimeMillis() - tempTime);

      while (response.hasNext()) {
        ByteBufferMessageSet messages = response.next();

        // check error codes
        _toContinue = checkErrorCode(messages, input);
        if (!_toContinue)
          break;

        Iterator<Message> iter = (Iterator<Message>) messages
            .iterator();
        long messageOffset = 0;
        while (iter.hasNext()) {
          Message message = iter.next();

          messageOffset += MessageSet.entrySize(message);
          reporter.incrCounter("topic-counters", _topic, 1);
          _count++;

          try {
            tempTime = System.currentTimeMillis();
            _timestamp = getTimestamp(message);
            decodeTime += (System.currentTimeMillis() - tempTime);

          } catch (IOException e) {
            System.err.println("SetOffset=" + _offset
                + "messageOffset=" + messageOffset
                + ": ignore message with exception: ");

            if (_ignoreErrors) {
              reporter.incrCounter(_topic, _topic
                  + "_PARSING_ERROR", 1);
              continue;
            } else {
              e.printStackTrace(System.err);
              throw e;
            }
          }

          // determine whether to stop
          Status status = getStatus(message, reporter);

          // generate output
          switch (status) {
          case OUTPUT_AND_CONTINUE:
          case OUTPUT_AND_BREAK:
            tempTime = System.currentTimeMillis();
            ByteBuffer buffer = message.payload();
            byte[] bytes = new byte[buffer.remaining()];
            buffer.get(bytes, buffer.position(), bytes.length);
            collector.collect(new KafkaETLKey(_timestamp,
                _granularity), new BytesWritable(bytes));
            outputTime += (System.currentTimeMillis() - tempTime);

          }

          // report progress
          float percentage = getProgress();
          reporter.setStatus("collected " + percentage + "%");

          switch (status) {
          case OUTPUT_AND_BREAK:
          case BREAK:
            break;
          }

        }

        _offset += messages.validBytes();
      }
    }
    _consumer.close();
    long endTime = System.currentTimeMillis();
View Full Code Here

Examples of kafka.message.ByteBufferMessageSet

                                                       KafkaProperties.connectionTimeOut,
                                                       KafkaProperties.kafkaProducerBufferSize);

    System.out.println("Testing single fetch");
    FetchRequest req = new FetchRequest(KafkaProperties.topic2, 0, 0L, 100);
    ByteBufferMessageSet messageSet = simpleConsumer.fetch(req);
    printMessages(messageSet);

    System.out.println("Testing single multi-fetch");
    req = new FetchRequest(KafkaProperties.topic2, 0, 0L, 100);
    List<FetchRequest> list = new ArrayList<FetchRequest>();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.