Search in sources :

Example 1 with CommandToBeReprocessedException

use of org.eclipse.hono.client.command.CommandToBeReprocessedException in project hono by eclipse.

the class KafkaCommandProcessingQueue method applySendCommandAction.

/**
 * Either invokes the given sendAction directly if it is next-in-line or makes sure the action is
 * invoked at a later point in time according to the order in which commands were originally received.
 *
 * @param commandContext The context of the command to apply the given sendAction for.
 * @param sendActionSupplier The Supplier for the action to send the given command to the internal Command and
 *                           Control API endpoint provided by protocol adapters.
 * @return A future indicating the outcome of sending the command message. If the given command is
 *         not in the corresponding queue, a failed future will be returned and the command context is released.
 * @throws NullPointerException if any of the parameters is {@code null}.
 */
public Future<Void> applySendCommandAction(final KafkaBasedCommandContext commandContext, final Supplier<Future<Void>> sendActionSupplier) {
    final TopicPartition topicPartition = new TopicPartition(commandContext.getCommand().getRecord().topic(), commandContext.getCommand().getRecord().partition());
    final TopicPartitionCommandQueue commandQueue = commandQueues.get(topicPartition);
    if (commandQueue == null) {
        LOG.info("command won't be sent - commands received from partition [{}] aren't handled by this consumer anymore [{}]", topicPartition, commandContext.getCommand());
        TracingHelper.logError(commandContext.getTracingSpan(), String.format("command won't be sent - commands received from partition [%s] aren't handled by this consumer anymore", topicPartition));
        final ServerErrorException error = new CommandToBeReprocessedException();
        commandContext.release(error);
        return Future.failedFuture(error);
    }
    return commandQueue.applySendCommandAction(commandContext, sendActionSupplier);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) CommandToBeReprocessedException(org.eclipse.hono.client.command.CommandToBeReprocessedException) ServerErrorException(org.eclipse.hono.client.ServerErrorException)

Example 2 with CommandToBeReprocessedException

use of org.eclipse.hono.client.command.CommandToBeReprocessedException in project hono by eclipse.

the class KafkaBasedCommandContext method release.

@Override
public final void release(final Throwable error) {
    Objects.requireNonNull(error);
    if (!setCompleted("released")) {
        return;
    }
    final Span span = getTracingSpan();
    TracingHelper.logError(span, "command could not be delivered or processed", error);
    final ServiceInvocationException mappedError = StatusCodeMapper.toServerError(error);
    final int status = mappedError.getErrorCode();
    Tags.HTTP_STATUS.set(span, status);
    if (isRequestResponseCommand() && !(error instanceof CommandAlreadyProcessedException) && !(error instanceof CommandToBeReprocessedException)) {
        final String errorMessage = Optional.ofNullable(ServiceInvocationException.getErrorMessageForExternalClient(mappedError)).orElse("Temporarily unavailable");
        sendDeliveryFailureCommandResponseMessage(status, errorMessage, span, error).onComplete(v -> span.finish());
    } else {
        span.finish();
    }
}
Also used : CommandAlreadyProcessedException(org.eclipse.hono.client.command.CommandAlreadyProcessedException) CommandToBeReprocessedException(org.eclipse.hono.client.command.CommandToBeReprocessedException) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Span(io.opentracing.Span)

Aggregations

CommandToBeReprocessedException (org.eclipse.hono.client.command.CommandToBeReprocessedException)2 Span (io.opentracing.Span)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 ServerErrorException (org.eclipse.hono.client.ServerErrorException)1 ServiceInvocationException (org.eclipse.hono.client.ServiceInvocationException)1 CommandAlreadyProcessedException (org.eclipse.hono.client.command.CommandAlreadyProcessedException)1