如何通过Pulsar Admin Rest API创建Key_Shared/Shared类型订阅
解决Apache Pulsar 2.10.1 Admin REST API设置订阅类型的问题
你的问题出在错误地将subscriptionType放在了properties对象中,Pulsar的Admin REST API并不从这个位置读取订阅类型,因此无法识别你指定的类型,默认使用了None。
正确的请求格式
创建订阅时,subscriptionType需要作为请求体的顶层字段传递,而非嵌套在properties里。同时,你可以根据需求保留或调整其他起始位置相关的字段(如ledgerId、entryId等)。
正确的Curl请求示例
创建Key_Shared类型订阅
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": false, "ledgerId": 0, "partitionIndex": 0, "subscriptionType": "Key_Shared", "properties": {} }'
创建Shared类型订阅
只需将subscriptionType的值改为"Shared"即可:
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": false, "ledgerId": 0, "partitionIndex": 0, "subscriptionType": "Shared", "properties": {} }'
验证订阅类型
你可以通过以下API查询订阅详情,确认类型是否设置成功:
curl -H "Authorization: Bearer token" "http://localhost:8080/admin/v2/persistent/public/default/test-topic/subscription/shared-test-subscription"
返回结果中会包含"subscriptionType": "Key_Shared"或"Shared"字段。
内容的提问来源于stack exchange,提问作者TitaniumDave
相关产品推荐
相关产品推荐

