public String getEncodedLocalName() { return Codec.encode(localName); }
public String getEncodedLocalName() { return Codec.encode(localName); }
private CompletableFuture<Subscription> getDurableSubscription(String subscriptionName, InitialPosition initialPosition) { CompletableFuture<Subscription> subscriptionFuture = new CompletableFuture<>(); ledger.asyncOpenCursor(Codec.encode(subscriptionName), initialPosition, new OpenCursorCallback() { @Override public void openCursorComplete(ManagedCursor cursor, Object ctx) { if (log.isDebugEnabled()) { log.debug("[{}][{}] Opened cursor", topic, subscriptionName); } subscriptionFuture.complete(subscriptions.computeIfAbsent(subscriptionName, name -> createPersistentSubscription(subscriptionName, cursor))); } @Override public void openCursorFailed(ManagedLedgerException exception, Object ctx) { log.warn("[{}] Failed to create subscription for {}: {}", topic, subscriptionName, exception.getMessage()); USAGE_COUNT_UPDATER.decrementAndGet(PersistentTopic.this); subscriptionFuture.completeExceptionally(new PersistenceException(exception)); if (exception instanceof ManagedLedgerFencedException) { // If the managed ledger has been fenced, we cannot continue using it. We need to close and reopen close(); } } }, null); return subscriptionFuture; }
CompletableFuture<Void> unsubscribeFuture = new CompletableFuture<>(); ledger.asyncDeleteCursor(Codec.encode(subscriptionName), new DeleteCursorCallback() { @Override public void deleteCursorComplete(Object ctx) {
@Override public CompletableFuture<Void> expireMessagesAsync(String topic, String subName, long expireTimeInSeconds) { TopicName tn = validateTopic(topic); String encodedSubName = Codec.encode(subName); WebTarget path = topicPath(tn, "subscription", encodedSubName, "expireMessages", String.valueOf(expireTimeInSeconds)); return asyncPostRequest(path, Entity.entity("", MediaType.APPLICATION_JSON)); }
@Override public CompletableFuture<Void> resetCursorAsync(String topic, String subName, long timestamp) { TopicName tn = validateTopic(topic); String encodedSubName = Codec.encode(subName); WebTarget path = topicPath(tn, "subscription", encodedSubName, "resetcursor", String.valueOf(timestamp)); return asyncPostRequest(path, Entity.entity("", MediaType.APPLICATION_JSON)); }
@Override public CompletableFuture<Void> skipMessagesAsync(String topic, String subName, long numMessages) { TopicName tn = validateTopic(topic); String encodedSubName = Codec.encode(subName); WebTarget path = topicPath(tn, "subscription", encodedSubName, "skip", String.valueOf(numMessages)); return asyncPostRequest(path, Entity.entity("", MediaType.APPLICATION_JSON)); }
@Override public CompletableFuture<Void> skipAllMessagesAsync(String topic, String subName) { TopicName tn = validateTopic(topic); String encodedSubName = Codec.encode(subName); WebTarget path = topicPath(tn, "subscription", encodedSubName, "skip_all"); return asyncPostRequest(path, Entity.entity("", MediaType.APPLICATION_JSON)); }
@Override public CompletableFuture<Void> resetCursorAsync(String topic, String subName, MessageId messageId) { TopicName tn = validateTopic(topic); String encodedSubName = Codec.encode(subName); final WebTarget path = topicPath(tn, "subscription", encodedSubName, "resetcursor"); return asyncPostRequest(path, Entity.entity(messageId, MediaType.APPLICATION_JSON)); }
@Override public void resetCursor(String topic, String subName, long timestamp) throws PulsarAdminException { try { TopicName tn = validateTopic(topic); String encodedSubName = Codec.encode(subName); WebTarget path = topicPath(tn, "subscription", encodedSubName, "resetcursor", String.valueOf(timestamp)); request(path).post(Entity.entity("", MediaType.APPLICATION_JSON), ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
@Override public CompletableFuture<Void> createSubscriptionAsync(String topic, String subscriptionName, MessageId messageId) { TopicName tn = validateTopic(topic); String encodedSubName = Codec.encode(subscriptionName); WebTarget path = topicPath(tn, "subscription", encodedSubName); return asyncPutRequest(path, Entity.entity(messageId, MediaType.APPLICATION_JSON)); }
@Override public void resetCursor(String topic, String subName, MessageId messageId) throws PulsarAdminException { try { TopicName tn = validateTopic(topic); String encodedSubName = Codec.encode(subName); WebTarget path = topicPath(tn, "subscription", encodedSubName, "resetcursor"); request(path).post(Entity.entity(messageId, MediaType.APPLICATION_JSON), ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
private CompletableFuture<List<Message<byte[]>>> peekNthMessage(String topic, String subName, int messagePosition) { TopicName tn = validateTopic(topic); String encodedSubName = Codec.encode(subName); WebTarget path = topicPath(tn, "subscription", encodedSubName, "position", String.valueOf(messagePosition)); final CompletableFuture<List<Message<byte[]>>> future = new CompletableFuture<>(); asyncGetRequest(path, new InvocationCallback<Response>() { @Override public void completed(Response response) { try { future.complete(getMessageFromHttpResponse(tn.toString(), response)); } catch (Exception e) { future.completeExceptionally(getApiException(e)); } } @Override public void failed(Throwable throwable) { future.completeExceptionally(getApiException(throwable.getCause())); } }); return future; }
@Override public CompletableFuture<Void> deleteSubscriptionAsync(String topic, String subName) { TopicName tn = validateTopic(topic); String encodedSubName = Codec.encode(subName); WebTarget path = topicPath(tn, "subscription", encodedSubName); return asyncDeleteRequest(path); }
@Override public void createSubscription(String topic, String subscriptionName, MessageId messageId) throws PulsarAdminException { try { TopicName tn = validateTopic(topic); String encodedSubName = Codec.encode(subscriptionName); WebTarget path = topicPath(tn, "subscription", encodedSubName); request(path).put(Entity.entity(messageId, MediaType.APPLICATION_JSON), ErrorData.class); } catch (Exception e) { throw getApiException(e); } }