void doUnsubscribe(final long requestId) { final ChannelHandlerContext ctx = cnx.ctx(); subscription.doUnsubscribe(this).thenAccept(v -> { log.info("Unsubscribed successfully from {}", subscription); cnx.removedConsumer(this); ctx.writeAndFlush(Commands.newSuccess(requestId)); }).exceptionally(exception -> { log.warn("Unsubscribe failed for {}", subscription, exception); ctx.writeAndFlush( Commands.newError(requestId, BrokerServiceException.getClientErrorCode(exception.getCause()), exception.getCause().getMessage())); return null; }); }
ctx.writeAndFlush(Commands.newSuccess(requestId)); return; } else if (producerFuture.isCompletedExceptionally()) { log.info("[{}] Closed producer {} that already failed to be created", remoteAddress, producerId); ctx.writeAndFlush(Commands.newSuccess(requestId)); return; log.info("[{}][{}] Closed producer on cnx {}", producer.getTopic(), producer.getProducerName(), remoteAddress); ctx.writeAndFlush(Commands.newSuccess(requestId)); producers.remove(producerId, producerFuture); });
ctx.writeAndFlush(Commands.newSuccess(requestId)); return; ctx.writeAndFlush(Commands.newSuccess(requestId)); return; consumer.close(); consumers.remove(consumerId, consumerFuture); ctx.writeAndFlush(Commands.newSuccess(requestId)); log.info("[{}] Closed consumer {}", remoteAddress, consumer); } catch (BrokerServiceException e) {
@Override protected void handleSeek(CommandSeek seek) { checkArgument(state == State.Connected); final long requestId = seek.getRequestId(); CompletableFuture<Consumer> consumerFuture = consumers.get(seek.getConsumerId()); // Currently only seeking on a message id is supported if (!seek.hasMessageId()) { ctx.writeAndFlush( Commands.newError(requestId, ServerError.MetadataError, "Message id was not present")); return; } if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) { Consumer consumer = consumerFuture.getNow(null); Subscription subscription = consumer.getSubscription(); MessageIdData msgIdData = seek.getMessageId(); Position position = new PositionImpl(msgIdData.getLedgerId(), msgIdData.getEntryId()); subscription.resetCursor(position).thenRun(() -> { log.info("[{}] [{}][{}] Reset subscription to message id {}", remoteAddress, subscription.getTopic().getName(), subscription.getName(), position); ctx.writeAndFlush(Commands.newSuccess(requestId)); }).exceptionally(ex -> { log.warn("[{}][{}] Failed to reset subscription: {}", remoteAddress, subscription, ex.getMessage(), ex); ctx.writeAndFlush(Commands.newError(requestId, ServerError.UnknownError, "Error when resetting subscription: " + ex.getCause().getMessage())); return null; }); } else { ctx.writeAndFlush(Commands.newError(requestId, ServerError.MetadataError, "Consumer not found")); } }
log.info("[{}] Consumer with the same id is already created: {}", remoteAddress, consumer); ctx.writeAndFlush(Commands.newSuccess(requestId)); return null; } else { log.info("[{}] Created subscription on topic {} / {}", remoteAddress, topicName, subscriptionName); ctx.writeAndFlush(Commands.newSuccess(requestId), ctx.voidPromise()); } else {