Search code examples
apache-pulsar

How to create an subscription with the Pulsar Admin Rest API with subscriptionType Key_Shared


Im trying to make a Subscription on an Apache Pulsar (2.10.1) Topic using the Admin Rest API and I would like to create it as the Type: Key_Shared or Shared.

Making an subscription to an existing topic can be done like below. But it doesn't seem to get the correct subscriptionType. Is it, and how, possible to create an subscription on a pre-exsiting topic with an subscriptionType using Admin Rest API?

I've tried to send this request and would've expected the subscription to become Shared/Key_Shared but it becomes None.

curl -L -X PUT "http://localhost:8080/admin/v2/persistent/public/default/test-topic/subscription/shared-test-subscription"
-H "Content-Type: application/json"
-H "Authorization: Bearer token"
--data-raw "{   "batchIndex": 0,   "entryId": 0,   "excluded": true,   "ledgerId": 0,   "partitionIndex": 0,   "properties": {     "subscriptionType": "Key_Shared"   } }"


Solution

  • The subscription type is determined when the first consumer connects. Pulsar will not persist the subscription type to the metadata store, so Pulsar doesn't have APIs to create a subscription with the subscription type (The created subscription is maintained in the metadata store).

    And if the subsequent consumers are using different subscription types, they will fail when they subscribe to the topic. After all consumers disconnect, the subscription will change to "No subscription type" state, so the subscription gets a chance to switch to a different subscription type as before.