Pulsar 入门实战(6)--Rest API

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/

posted @ 2024-11-24 19:16  且行且码  阅读(8)  评论(0编辑  收藏  举报