Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][client] Enhance error handling for non-exist subscription in consumer creation #23254

Conversation

Shawyeok
Copy link
Contributor

@Shawyeok Shawyeok commented Sep 4, 2024

Motivation

When allowAutoSubscriptionCreation is set to false on broker, creating a consumer for a subscription that does not exist does not throw a SubscriptionNotFoundException. Instead, it throws a PulsarClientException. This behavior complicates determining whether the subscription exists, requiring users to perform checks like getRootCause(e).getMessage().matches(".*Subscription .*does not exist.*") before #22164. Even after #22164, while the root cause becomes SubscriptionNotFoundException, additional handling is still necessary.

try {
    Consumer<byte[]> consumer = pulsarClient.newConsumer()
            .topic("public/default/subscription-auto-creation-disabled")
            .subscriptionName("test")
            .subscriptionType(SubscriptionType.Exclusive)
            .subscribe();
} catch (PulsarClientException.SubscriptionNotFoundException e) {
    // never reached here
} catch (PulsarClientException e) {
    getRootCause(e).getMessage().matches(".*Subscription .*does not exist.*");   // before #22164
    getRootCause(e) instanceof PulsarClientException.SubscriptionNotFoundException; // after #22164, there is another approach
}

Modifications

This change modifies the code to throw SubscriptionNotFoundException directly when attempting to create a consumer for a non-existent subscription. This exception is a subclass of PulsarClientException, ensuring backward compatibility and providing a clearer error handling path for users.

Verifying this change

  • Ensure that the change passes the CI checks.

This PR also updates the corresponding test in org.apache.pulsar.client.api.MultiTopicsConsumerTest#testSubscriptionNotFound.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: Shawyeok#17

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Sep 4, 2024
@lhotari lhotari added this to the 4.0.0 milestone Oct 9, 2024
Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lhotari lhotari closed this Oct 9, 2024
@lhotari lhotari reopened this Oct 9, 2024
@lhotari lhotari modified the milestones: 4.0.0, 4.1.0 Oct 11, 2024
@lhotari lhotari merged commit 7fc88d6 into apache:master Nov 29, 2024
57 of 58 checks passed
lhotari pushed a commit that referenced this pull request Nov 29, 2024
lhotari pushed a commit that referenced this pull request Nov 29, 2024
lhotari pushed a commit that referenced this pull request Nov 29, 2024
nikhil-ctds pushed a commit to datastax/pulsar that referenced this pull request Dec 6, 2024
…n consumer creation (apache#23254)

(cherry picked from commit 7fc88d6)
(cherry picked from commit 5dec2e2)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Dec 9, 2024
…n consumer creation (apache#23254)

(cherry picked from commit 7fc88d6)
(cherry picked from commit 5dec2e2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants