You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 13:45:24