Package kafka.javaapi

Examples of kafka.javaapi.FetchResponse


        CamusJob.getKafkaFetchRequestCorrelationId(context),
        CamusJob.getKafkaClientName(context),
        CamusJob.getKafkaFetchRequestMaxWait(context),
        CamusJob.getKafkaFetchRequestMinBytes(context), fetchInfo);

    FetchResponse fetchResponse = null;
    try {
      fetchResponse = simpleConsumer.fetch(fetchRequest);
      if (fetchResponse.hasError()) {
        log.info("Error encountered during a fetch request from Kafka");
        log.info("Error Code generated : "
            + fetchResponse.errorCode(kafkaRequest.getTopic(),
                kafkaRequest.getPartition()));
        return false;
      } else {
        ByteBufferMessageSet messageBuffer = fetchResponse.messageSet(
            kafkaRequest.getTopic(), kafkaRequest.getPartition());
        lastFetchTime = (System.currentTimeMillis() - tempTime);
        log.debug("Time taken to fetch : "
            + (lastFetchTime / 1000) + " seconds");
        log.debug("The size of the ByteBufferMessageSet returned is : " + messageBuffer.sizeInBytes());
View Full Code Here


      FetchRequest req = new FetchRequestBuilder()
        .clientId(clientName)
        .addFetch(topic, partition, fetchOffset, BUFFER_SIZE_BYTES)
        .maxWait(fetchTimeoutMs)
        .build();
      FetchResponse fetchResponse = consumer.fetch(req);

      if (fetchResponse.hasError()) {
        errorCode = fetchResponse.errorCode(topic, partition);
        LOG.warn(
          String.format("Error fetching data from broker %s:%d for topic %s, partition %d. Error code: %d",
                        consumer.host(), consumer.port(), topic, partition, errorCode));
        if (errorCode == ErrorMapping.OffsetOutOfRangeCode())  {
          throw new OffsetOutOfRangeException(
            String.format("Requested offset %d is out of range for topic %s partition %d",
                          fetchOffset, topic, partition));
        }
        findLeader();
        continue;
      }

      return fetchResponse.messageSet(topic, partition);
    }
    String message = String.format("Error fetching data from broker %s:%d for topic %s, partition %d. Error code: %d",
                                   consumer.host(), consumer.port(), topic, partition, errorCode);
    LOG.error(message);
    throw new RuntimeException(message);
View Full Code Here

    FetchRequest req = new FetchRequestBuilder()
        .clientId(config.clientId)
        .addFetch(topic, partition, offset, config.fetchMaxBytes)
        .maxWait(config.fetchWaitMaxMs)
        .build();
    FetchResponse fetchResponse = null;
        try {
            fetchResponse = consumer.fetch(req);
           
        }catch (Exception e) {
          if (e instanceof ConnectException ||
                    e instanceof SocketTimeoutException ||
                    e instanceof IOException ||
                    e instanceof UnresolvedAddressException
                    ) {
                LOG.warn("Network error when fetching messages:", e);
                throw new KafkaException("Network error when fetching messages: "+e.getMessage());
            } else {
                throw new RuntimeException(e);
            }
        }
        if(fetchResponse.hasError()) {
          short code = fetchResponse.errorCode(topic, partition);
//          if(code == ErrorMapping.OffsetOutOfRangeCode() && config.resetOffsetIfOutOfRange) {
//            long startOffset = getOffset(topic, partition, config.startOffsetTime);
//            offset = startOffset;
//          }
          throw new KafkaException("fetch data from kafka topic["+topic+"] partition["+partition+"] error:" + code);
        }else {
          ByteBufferMessageSet msgs =  fetchResponse.messageSet(topic, partition);
          return msgs;
        }
  }
View Full Code Here

TOP

Related Classes of kafka.javaapi.FetchResponse

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.