Package kafka.message

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


      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

        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

      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

                                                       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

    {
      String messageStr = new String("Message_" + messageNo);
      Message message = new Message(messageStr.getBytes());
      List<Message> messageList = new ArrayList<Message>();
      messageList.add(message);
      ByteBufferMessageSet set = new ByteBufferMessageSet(messageList);
      producer.send(topic, set);
      messageNo++;
    }
  }
View Full Code Here

TOP

Related Classes of kafka.message.ByteBufferMessageSet

Copyright © 2018 www.massapicom. 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.