We introduce the Key-Shared Subscription here for completeness. It is designed to be used with keyed messaged which will be introduced when we discuss partitioned topics. The Key-Shared Subscription allows us to scale the number of consumers for a given subscription beyond the number of topic partitions while also guaranteeing all messages with the same key are delivered to the same consumer in order.
The Key_Shared Subscription can be enabled using the following and will be demonstrated later in the course:
Consumer consumer = client.newConsumer()
.topic("persistent://public/default/mynewtopic")
.subscriptionName("mysubscription")
.subscriptionType(SubscriptionType.Key_Shared)
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
.subscribe();