org.apache.kafka.common.errors.RetriableException Java Examples

The following examples show how to use org.apache.kafka.common.errors.RetriableException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KafkaTopicClientImpl.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 6 votes vote down vote up
private static <T> T executeWithRetries(final Supplier<KafkaFuture<T>> supplier)
    throws Exception {

  int retries = 0;
  Exception lastException = null;
  while (retries < NUM_RETRIES) {
    try {
      if (retries != 0) {
        Thread.sleep(RETRY_BACKOFF_MS);
      }
      return supplier.get().get();
    } catch (ExecutionException e) {
      if (e.getCause() instanceof RetriableException) {
        retries++;
        log.info("Retrying admin request due to retriable exception. Retry no: " + retries, e);
        lastException = e;
      } else if (e.getCause() instanceof Exception) {
        throw (Exception) e.getCause();
      } else {
        throw e;
      }
    }
  }
  throw lastException;
}
 
Example #2
Source File: KafkaExceptionMapper.java    From rest-utils with Apache License 2.0 6 votes vote down vote up
private Response handleException(final Throwable exception) {
  if (exception instanceof AuthenticationException) {
    return getResponse(exception, Status.UNAUTHORIZED,
        KAFKA_AUTHENTICATION_ERROR_CODE);
  } else if (exception instanceof AuthorizationException) {
    return getResponse(exception, Status.FORBIDDEN,
        KAFKA_AUTHORIZATION_ERROR_CODE);
  } else if (HANDLED.containsKey(exception.getClass())) {
    return getResponse(exception);
  } else if (exception instanceof RetriableException) {
    log.debug("Kafka retriable exception", exception);
    return getResponse(exception, Status.INTERNAL_SERVER_ERROR,
        KAFKA_RETRIABLE_ERROR_ERROR_CODE);
  } else if (exception instanceof KafkaException) {
    log.error("Kafka exception", exception);
    return getResponse(exception, Status.INTERNAL_SERVER_ERROR,
        KAFKA_ERROR_ERROR_CODE);
  } else if (exception instanceof InvalidFormatException) {
    return getResponse(exception, Status.BAD_REQUEST,
        KAFKA_BAD_REQUEST_ERROR_CODE);
  } else {
    log.error("Unhandled exception", exception);
    return super.toResponse(exception);
  }
}
 
Example #3
Source File: KafkaMessageProducer.java    From txle with Apache License 2.0 5 votes vote down vote up
private void sendMessage(TxEvent event, List<KafkaMessage> messageList, List<Long> idList) {
    try {
        String msgJson = new GsonBuilder().create().toJson(messageList);
        ProducerRecord<String, String> record = new ProducerRecord<>(topic, msgJson);
        kafkaProducer.send(record, (metadata, exception) -> {
            if (exception == null) {
                LOG.info("Successfully to send Kafka message - globalTxId = [{}].", event.globalTxId());
                // To update message's status to 'successful'.
                kafkaMessageRepository.updateMessageStatusByIdList(idList, KafkaMessageStatus.SUCCESSFUL);
            } else {
                if (exception instanceof RetriableException) {
                    // Kafka will retry automatically for some exceptions which can possible be successful by retrying.
                    LOG.info("Unsuccessfully to send Kafka message after exhausting retries - globalTxId = [{}].", event.globalTxId(), exception);
                } else {
                    LOG.error("Unsuccessfully to send Kafka message without retries - globalTxId = [{}].", event.globalTxId(), exception);
                }
                // To report message to Accident Platform.
                JsonObject jsonParams = new JsonObject();
                jsonParams.addProperty("type", AccidentHandleType.SEND_MESSAGE_ERROR.toDescription());
                jsonParams.addProperty("globaltxid", event.globalTxId());
                jsonParams.addProperty("localtxid", event.localTxId());
                jsonParams.addProperty("instanceid", event.instanceId());
                jsonParams.addProperty("servicename", event.serviceName());
                jsonParams.addProperty("bizinfo", msgJson);
                accidentHandlingService.reportMsgToAccidentPlatform(jsonParams.toString());

                // To update message's status to 'failed'.
                kafkaMessageRepository.updateMessageStatusByIdList(idList, KafkaMessageStatus.FAILED);
            }
        });
    } catch (Exception e) {
        LOG.error("To send message to Kafka exception - globalTxId = [{}].", event.globalTxId(), e);
    }
}
 
Example #4
Source File: KafkaOpenMetadataEventProducer.java    From egeria with Apache License 2.0 5 votes vote down vote up
private boolean isExceptionRetryable( Throwable throwable)
{

    Throwable nested = null;
    while ((nested = throwable.getCause()) != null) {
         if( nested instanceof RetriableException) {
             return true;
         }
       throwable = throwable.getCause();
   }
    return false;
}