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);
}
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();
}
}
Aggregations