Exclusive Subscription

Using our sample code from StreamNative UI, let’s test out the Exclusive Subscription type. We will start multiple consumers using the same subscription on the same topic and observe that only one consumer is allowed to connect to the topic.

Notice that only one consumer per Exclusive Subscription is allowed to connect to the topic. Exclusive is the default subscription type and can be explicitly specified in the consumer configuration:

Consumer consumer = client.newConsumer()
.topic("persistent://public/default/mynewtopic")
.subscriptionName("mysubscription")
.subscriptionType(SubscriptionType.Exclusive)
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
.subscribe();

When consuming messages, the Exclusive Subscription keeps message ordering. We will revisit message ordering with the Exclusive Subscription when we increase the number of topic partitions.

Example OAuth2 CREDENTIALS_URL for reference.

Mac:
private static String CREDENTIALS_URL = "file:///Users/dustinnest/Desktop/CourseFiles/PulsarClassFiles/Developer-Training/src/main/resources/o-mj3r8-student31-05032024.json";

Windows (note that there are SIX backslashes after "file:")
private static String CREDENTIALS_URL = "file:\\\\\\Users\\dustin.nest\\CourseFiles\\PulsarClassFiles\\PulsarClassFiles\\Developer-Training\\src\\main\\resources\\o-mj3r8-student31-05032024.json";

The subscription type can also be viewed in the StreamNative UI.