Rest API 是 broker 提供的關聯 API,Java admin API 和 pulsar-admin CLI 底層都是使用的 Rest API;本文主要介紹其基本使用,文中所使用到的軟體版本:Pulsar 3.3.0。
1、Admin
1.1、BOOKIES
1.1.1、列出所有 bookie
curl http://10.49.196.30:8080/admin/v2/bookies/all
1.2、BROKERS
1.2.1、列出本叢集的所有 broker
curl http://10.49.196.30:8080/admin/v2/brokers
1.2.2、列出所有可動態修改配置項名稱
curl http://10.49.196.30:8080/admin/v2/brokers/configuration
1.2.3、列出所有執行時配置
curl http://10.49.196.30:8080/admin/v2/brokers/configuration/runtime
1.2.4、列出已經更新過的動態配置
curl http://10.49.196.30:8080/admin/v2/brokers/configuration/values
1.2.5、更新動態配置
POST /admin/v2/brokers/configuration/{configName}/{configValue}
如:
curl -X POST http://10.49.196.30:8080/admin/v2/brokers/configuration/allowAutoTopicCreation/true
1.2.6、健康檢查
curl http://10.49.196.30:8080/admin/v2/brokers/health
1.2.7、獲取內部配置資訊
curl http://10.49.196.30:8080/admin/v2/brokers/internal-configuration
1.2.8、獲取 leader broker
curl http://10.49.196.30:8080/admin/v2/brokers/leaderBroker
1.2.9、檢查 broker 是否完全初始化了
curl http://10.49.196.30:8080/admin/v2/brokers/ready
1.2.10、獲取當前 broker 的版本
curl http://10.49.196.30:8080/admin/v2/brokers/version
1.2.11、列出 broker 的名稱空間
GET /admin/v2/brokers/{clusterName}/{brokerId}/ownedNamespaces
如:
curl http://10.49.196.30:8080/admin/v2/brokers/pulsar-cluster-1/app1:8080/ownedNamespaces
1.2.12、列出指定叢集的所有 broker
GET /admin/v2/brokers/{cluster}
如:
curl http://10.49.196.30:8080/admin/v2/brokers/pulsar-cluster-1
1.3、BROKER-STATS
1.3.1、獲取 broker 的主題狀態和系統資源使用資訊
curl http://10.49.196.30:8080/admin/v2/broker-stats/load-report
1.3.2、獲取主題的狀態資訊
curl http://10.49.196.30:8080/admin/v2/broker-stats/topics
1.4、CLUSTERS
1.4.1、列出叢集
curl http://10.49.196.30:8080/admin/v2/clusters
1.4.2、獲取叢集配置資訊
GET /admin/v2/clusters/{cluster}
如:
curl http://10.49.196.30:8080/admin/v2/clusters/pulsar-cluster-1
1.5、TENANTS
1.5.1、列出租戶的名稱空間
curl http://10.49.196.30:8080/admin/v2/tenants
1.5.2、刪除租戶
DELETE /admin/v2/tenants/{tenant}
如:
curl -X DELETE http://10.49.196.30:8080/admin/v2/tenants/test-tenant
1.5.3、獲取租戶的管理配置
GET /admin/v2/tenants/{tenant}
如:
curl http://10.49.196.30:8080/admin/v2/tenants/public
1.5.4、更新租戶管理配置
POST /admin/v2/tenants/{tenant} { "adminRoles": [ "string" ], "allowedClusters": [ "string" ] }
如:
curl -X POST -H 'content-type:application/json' http://10.49.196.30:8080/admin/v2/tenants/test-tenant -d ' { "adminRoles": [ "string" ], "allowedClusters": [ "pulsar-cluster-1" ] }'
1.5.5、建立租戶
PUT /admin/v2/tenants/{tenant}
如:
curl -X PUT -H 'content-type:application/json' http://10.49.196.30:8080/admin/v2/tenants/test-tenant -d ' { "adminRoles": [ "string" ], "allowedClusters": [ "pulsar-cluster-1" ] }'
1.6、NAMESPACES
1.6.1、列出租戶的名稱空間
GET /admin/v2/namespaces/{tenant}
如:
curl http://10.49.196.30:8080/admin/v2/namespaces/public
1.6.2、獲取名稱空間策略
GET /admin/v2/namespaces/{tenant}/{namespace}
如:
curl http://10.49.196.30:8080/admin/v2/namespaces/public/default
1.6.3、刪除名稱空間(同時刪除名稱空間包含的主題)
DELETE /admin/v2/namespaces/{tenant}/{namespace}
如:
curl -X DELETE http://10.49.196.30:8080/admin/v2/namespaces/public/test-ns
1.6.4、建立名稱空間
PUT /admin/v2/namespaces/{tenant}/{namespace}
如:
curl -X PUT http://10.49.196.30:8080/admin/v2/namespaces/public/test-ns
1.7、NON-PERSISTENT TOPIC
1.7.1、列出名稱空間下的非分割槽主題
GET /admin/v2/non-persistent/{tenant}/{namespace}
如:
curl http://10.49.196.30:8080/admin/v2/non-persistent/public/default
1.7.2、列出名稱空間下的分割槽主題
GET /admin/v2/non-persistent/{tenant}/{namespace}/partitioned
如:
curl http://10.49.196.30:8080/admin/v2/non-persistent/public/default/partitioned
1.7.3、建立非分割槽主題
PUT /admin/v2/non-persistent/{tenant}/{namespace}/{topic}
如:
curl -X PUT -L http://10.49.196.30:8080/admin/v2/non-persistent/public/default/test-topic
1.7.4、建立分割槽主題
PUT /admin/v2/non-persistent/{tenant}/{namespace}/{topic}/partitions
如:
curl -X PUT -H 'content-type:application/json' http://10.49.196.30:8080/admin/v2/non-persistent/public/default/test-topic-p/partitions -d 2
1.7.5、刪除非分割槽主題
DELETE /admin/v2/non-persistent/{tenant}/{namespace}/{topic}
如:
curl -X DELETE -L http://10.49.196.30:8080/admin/v2/non-persistent/public/default/test-topic
1.7.6、刪除分割槽主題
DELETE /admin/v2/non-persistent/{tenant}/{namespace}/{topic}/partitions
如:
curl -X DELETE http://10.49.196.30:8080/admin/v2/non-persistent/public/default/test-topic-p/partitions
1.7.7、獲取非分割槽主題的狀態
GET /admin/v2/non-persistent/{tenant}/{namespace}/{topic}/stats
如:
curl -L http://10.49.196.30:8080/admin/v2/non-persistent/public/default/test-topic/stats
1.7.8、獲取分割槽主題的狀態
GET /admin/v2/non-persistent/{tenant}/{namespace}/{topic}/partitioned-stats
如:
curl -L http://10.49.196.30:8080/admin/v2/non-persistent/public/default/test-topic-p/partitioned-stats
1.7.9、獲取非分割槽主題的內部狀態
GET /admin/v2/non-persistent/{tenant}/{namespace}/{topic}/internalStats
如:
curl -L http://10.49.196.30:8080/admin/v2/non-persistent/public/default/test-topic/internalStats
1.7.10、獲取分割槽主題的內部狀態
GET /admin/v2/non-persistent/{tenant}/{namespace}/{topic}/partitioned-internalStats
如:
curl -L http://10.49.196.30:8080/admin/v2/non-persistent/public/default/test-topic-p/partitioned-internalStats
1.7.11、獲取分割槽主題的後設資料資訊
GET /admin/v2/non-persistent/{tenant}/{namespace}/{topic}/partitions
如:
curl -L http://10.49.196.30:8080/admin/v2/non-persistent/public/default/test-topic-p/partitions
1.7.12、設定分割槽主題的分割槽數
POST /admin/v2/non-persistent/{tenant}/{namespace}/{topic}/partitions
如:
curl -X POST -H 'Content-Type:application/json' http://10.49.196.30:8080/admin/v2/non-persistent/public/default/test-topic-p/partitions -d '3'
1.8、PERSISTENT TOPIC
1.8.1、列出名稱空間下的非分割槽主題
GET /admin/v2/persistent/{tenant}/{namespace}
如:
curl http://10.49.196.30:8080/admin/v2/persistent/public/default
1.8.2、列出名稱空間下的分割槽主題
GET /admin/v2/persistent/{tenant}/{namespace}/partitioned
如:
curl -L http://10.49.196.30:8080/admin/v2/persistent/public/default/partitioned
1.8.3、建立非分割槽主題
PUT /admin/v2/non-persistent/{tenant}/{namespace}/{topic}
如:
curl -X PUT -L http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic
1.8.4、建立分割槽主題
PUT /admin/v2/persistent/{tenant}/{namespace}/{topic}/partitions
如:
curl -X PUT -H 'content-type:application/json' http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic-p/partitions -d 2
1.8.5、刪除非分割槽主題
DELETE /admin/v2/persistent/{tenant}/{namespace}/{topic}
如:
curl -X DELETE -L http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic
1.8.6、刪除分割槽主題
DELETE /admin/v2/persistent/{tenant}/{namespace}/{topic}/partitions
如:
curl -X DELETE http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic-p/partitions
1.8.7、獲取非分割槽主題的狀態
GET /admin/v2/persistent/{tenant}/{namespace}/{topic}/stats
如:
curl -L http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic/stats
1.8.8、獲取分割槽主題的狀態
GET /admin/v2/persistent/{tenant}/{namespace}/{topic}/partitioned-stats
如:
curl -L http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic-p/partitioned-stats
1.7.9、獲取非分割槽主題的內部狀態
GET /admin/v2/persistent/{tenant}/{namespace}/{topic}/internalStats
如:
curl -L http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic/internalStats
1.7.10、獲取分割槽主題的內部狀態
GET /admin/v2/persistent/{tenant}/{namespace}/{topic}/partitioned-internalStats
如:
curl http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic-p/partitioned-internalStats
1.7.11、獲取分割槽主題的後設資料資訊
GET /admin/v2/persistent/{tenant}/{namespace}/{topic}/partitions
或:
curl -L http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic-p/partitions
1.7.12、設定分割槽主題的分割槽數(只能比原來大)
POST /admin/v2/persistent/{tenant}/{namespace}/{topic}/partitions
或:
curl -X POST -H 'Content-Type:application/json' http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic-p/partitions -d '3'
1.7.13、獲取最新訊息的 ID
GET /admin/v2/persistent/{tenant}/{namespace}/{topic}/lastMessageId
如:
curl -L http://10.49.196.30:8080/admin/v2/persistent/public/default/my-topic/lastMessageId
1.7.14、透過訊息 ID 獲取訊息
GET /admin/v2/persistent/{tenant}/{namespace}/{topic}/ledger/{ledgerId}/entry/{entryId}
如:
curl -L http://10.49.196.30:8080/admin/v2/persistent/public/default/my-topic/ledger/272/entry/1
1.7.15、透過時間獲取訊息的 ID
GET /admin/v2/persistent/{tenant}/{namespace}/{topic}/messageid/{timestamp}
如:
curl -L http://10.49.196.30:8080/admin/v2/persistent/public/default/my-topic/messageid/1723517025876
1.7.16、檢視訂閱的待消費訊息(不會消費訊息)
GET /admin/v2/persistent/{tenant}/{namespace}/{topic}/subscription/{subName}/position/{messagePosition}
如:
curl -L http://10.49.196.30:8080/admin/v2/persistent/public/default/my-topic/subscription/my-subscription/position/3
1.7.17、跳過特定主題的某個訂閱中的若干條未消費訊息
POST /admin/v2/persistent/{tenant}/{namespace}/{topic}/subscription/{subName}/skip/{numMessages}
如:
curl -X POST -L http://10.49.196.30:8080/admin/v2/persistent/public/default/my-topic/subscription/my-subscription/skip/2
1.7.18、跳過特定主題的某個訂閱中的所有未消費訊息
POST /persistent/{tenant}/{namespace}/{topic}/subscription/{subName}/skip_all
如:
curl -X POST -L http://10.49.196.30:8080/admin/v2/persistent/public/default/my-topic/subscription/my-subscription/skip_all
1.7.19、建立訂閱
PUT /persistent/{tenant}/{namespace}/{topic}/subscription/{subscriptionName}
如:
curl -X PUT -L http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic/subscription/test-subscription
1.7.20、獲取訂閱資訊
GET /admin/v2/persistent/{tenant}/{namespace}/{topic}/subscriptions
如:
curl -L http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic/subscriptions
1.7.21、刪除訂閱
DELETE /admin/v2/persistent/{tenant}/{namespace}/{topic}/subscription/{subName}
如:
curl -X DELETE -L http://10.49.196.30:8080/admin/v2/persistent/public/default/test-topic/subscription/test-subscription
2、Lookup
2.2.1、獲取主題所屬的 broker
GET /lookup/v2/topic/{topic-domain}/{tenant}/{namespace}/{topic}
如:
curl -L http://10.49.196.30:8080/lookup/v2/topic/persistent/public/default/test-topic
參考:https://pulsar.apache.org/docs/3.3.x/reference-rest-api-overview/