Search in sources :

Example 1 with CommandCloseConsumer

use of org.apache.pulsar.common.api.proto.CommandCloseConsumer in project pulsar by apache.

the class ServerCnx method handleCloseConsumer.

@Override
protected void handleCloseConsumer(CommandCloseConsumer closeConsumer) {
    checkArgument(state == State.Connected);
    log.info("[{}] Closing consumer: consumerId={}", remoteAddress, closeConsumer.getConsumerId());
    long requestId = closeConsumer.getRequestId();
    long consumerId = closeConsumer.getConsumerId();
    CompletableFuture<Consumer> consumerFuture = consumers.get(consumerId);
    if (consumerFuture == null) {
        log.info("[{}] Consumer was not registered on the connection: {}", consumerId, remoteAddress);
        ctx.writeAndFlush(Commands.newSuccess(requestId));
        return;
    }
    if (!consumerFuture.isDone() && consumerFuture.completeExceptionally(new IllegalStateException("Closed consumer before creation was complete"))) {
        // We have received a request to close the consumer before it was actually completed, we have marked the
        // consumer future as failed and we can tell the client the close operation was successful. When the actual
        // create operation will complete, the new consumer will be discarded.
        log.info("[{}] Closed consumer before its creation was completed. consumerId={}", remoteAddress, consumerId);
        commandSender.sendSuccessResponse(requestId);
        return;
    }
    if (consumerFuture.isCompletedExceptionally()) {
        log.info("[{}] Closed consumer that already failed to be created. consumerId={}", remoteAddress, consumerId);
        commandSender.sendSuccessResponse(requestId);
        return;
    }
    // Proceed with normal consumer close
    Consumer consumer = consumerFuture.getNow(null);
    try {
        consumer.close();
        consumers.remove(consumerId, consumerFuture);
        commandSender.sendSuccessResponse(requestId);
        log.info("[{}] Closed consumer, consumerId={}", remoteAddress, consumerId);
    } catch (BrokerServiceException e) {
        log.warn("[{]] Error closing consumer {} : {}", remoteAddress, consumer, e);
        commandSender.sendErrorResponse(requestId, BrokerServiceException.getClientErrorCode(e), e.getMessage());
    }
}
Also used : CommandCloseConsumer(org.apache.pulsar.common.api.proto.CommandCloseConsumer)

Example 2 with CommandCloseConsumer

use of org.apache.pulsar.common.api.proto.CommandCloseConsumer in project pulsar by yahoo.

the class ServerCnx method handleCloseConsumer.

@Override
protected void handleCloseConsumer(CommandCloseConsumer closeConsumer) {
    checkArgument(state == State.Connected);
    log.info("[{}] Closing consumer: consumerId={}", remoteAddress, closeConsumer.getConsumerId());
    long requestId = closeConsumer.getRequestId();
    long consumerId = closeConsumer.getConsumerId();
    CompletableFuture<Consumer> consumerFuture = consumers.get(consumerId);
    if (consumerFuture == null) {
        log.info("[{}] Consumer was not registered on the connection: {}", consumerId, remoteAddress);
        ctx.writeAndFlush(Commands.newSuccess(requestId));
        return;
    }
    if (!consumerFuture.isDone() && consumerFuture.completeExceptionally(new IllegalStateException("Closed consumer before creation was complete"))) {
        // We have received a request to close the consumer before it was actually completed, we have marked the
        // consumer future as failed and we can tell the client the close operation was successful. When the actual
        // create operation will complete, the new consumer will be discarded.
        log.info("[{}] Closed consumer before its creation was completed. consumerId={}", remoteAddress, consumerId);
        commandSender.sendSuccessResponse(requestId);
        return;
    }
    if (consumerFuture.isCompletedExceptionally()) {
        log.info("[{}] Closed consumer that already failed to be created. consumerId={}", remoteAddress, consumerId);
        commandSender.sendSuccessResponse(requestId);
        return;
    }
    // Proceed with normal consumer close
    Consumer consumer = consumerFuture.getNow(null);
    try {
        consumer.close();
        consumers.remove(consumerId, consumerFuture);
        commandSender.sendSuccessResponse(requestId);
        log.info("[{}] Closed consumer, consumerId={}", remoteAddress, consumerId);
    } catch (BrokerServiceException e) {
        log.warn("[{]] Error closing consumer {} : {}", remoteAddress, consumer, e);
        commandSender.sendErrorResponse(requestId, BrokerServiceException.getClientErrorCode(e), e.getMessage());
    }
}
Also used : CommandCloseConsumer(org.apache.pulsar.common.api.proto.CommandCloseConsumer)

Example 3 with CommandCloseConsumer

use of org.apache.pulsar.common.api.proto.CommandCloseConsumer in project incubator-pulsar by apache.

the class ServerCnx method handleCloseConsumer.

@Override
protected void handleCloseConsumer(CommandCloseConsumer closeConsumer) {
    checkArgument(state == State.Connected);
    log.info("[{}] Closing consumer: consumerId={}", remoteAddress, closeConsumer.getConsumerId());
    long requestId = closeConsumer.getRequestId();
    long consumerId = closeConsumer.getConsumerId();
    CompletableFuture<Consumer> consumerFuture = consumers.get(consumerId);
    if (consumerFuture == null) {
        log.info("[{}] Consumer was not registered on the connection: {}", consumerId, remoteAddress);
        ctx.writeAndFlush(Commands.newSuccess(requestId));
        return;
    }
    if (!consumerFuture.isDone() && consumerFuture.completeExceptionally(new IllegalStateException("Closed consumer before creation was complete"))) {
        // We have received a request to close the consumer before it was actually completed, we have marked the
        // consumer future as failed and we can tell the client the close operation was successful. When the actual
        // create operation will complete, the new consumer will be discarded.
        log.info("[{}] Closed consumer before its creation was completed. consumerId={}", remoteAddress, consumerId);
        commandSender.sendSuccessResponse(requestId);
        return;
    }
    if (consumerFuture.isCompletedExceptionally()) {
        log.info("[{}] Closed consumer that already failed to be created. consumerId={}", remoteAddress, consumerId);
        commandSender.sendSuccessResponse(requestId);
        return;
    }
    // Proceed with normal consumer close
    Consumer consumer = consumerFuture.getNow(null);
    try {
        consumer.close();
        consumers.remove(consumerId, consumerFuture);
        commandSender.sendSuccessResponse(requestId);
        log.info("[{}] Closed consumer, consumerId={}", remoteAddress, consumerId);
    } catch (BrokerServiceException e) {
        log.warn("[{]] Error closing consumer {} : {}", remoteAddress, consumer, e);
        commandSender.sendErrorResponse(requestId, BrokerServiceException.getClientErrorCode(e), e.getMessage());
    }
}
Also used : CommandCloseConsumer(org.apache.pulsar.common.api.proto.CommandCloseConsumer)

Aggregations

CommandCloseConsumer (org.apache.pulsar.common.api.proto.CommandCloseConsumer)3