NSQ的HTTP API

来源:互联网 发布:改良圈算法 编辑:程序博客网 时间:2024/06/05 05:24
HTTP API
/ping  liveness
/info  version
/stats  comprehensive runtime telemetry
/pub - publish a message to a topic
/mpub - publish multiple messages to a topic
/config - configure nsqd
/debug/pprof - pprof debugging portal
/debug/pprof/profile - generate pprof CPU profile
/debug/pprof/goroutine - generate pprof goroutine profile
/debug/pprof/heap - generate pprof heap profile
/debug/pprof/block - generate pprof blocking profile
/debug/pprof/threadcreate - generate pprof OS thread profile

v1 namespace (as of nsqd v0.2.29+):
/topic/create - create a new topic
/topic/delete - delete a topic
/topic/empty - empty a topic
/topic/pause - pause message flow for a topic
/topic/unpause - unpause message flow for a topic
/channel/create - create a new channel
/channel/delete - delete a channel
/channel/empty - empty a channel
/channel/pause - pause message flow for a channel
/channel/unpause - unpause message flow for a channel


HTTP API
• /ping  - 活跃度
• /info  - 版本
• /stats  - 检查综合运行
• /pub  - 发布消息到话题(topic)
• /mpub  - 发布多个消息到话题(topic)
• /debug/pprof  - pprof 调试入口
• /debug/pprof/profile  - 生成 pprof CPU 配置文件
• /debug/pprof/goroutine  - 生成 pprof 计算配置文件
• /debug/pprof/heap  - 生成 pprof 堆配置文件
• /debug/pprof/block  - 生成 pprof 块配置文件
• /debug/pprof/threadcreate  - 生成 pprof OS 线程配置文件
v1 命名空间 (as of nsqd v0.2.29+ ):
• /topic/create  - 创建一个新的话题(topic)
• /topic/delete  - 删除一个话题(topic)
• /topic/empty  - 清空话题(topic)
• /topic/pause  - 暂停话题(topic)的消息流
• /topic/unpause  - 恢复话题(topic)的消息流
• /channel/create  - 创建一个新的通道(channel)
• /channel/delete  - 删除一个通道(channel)
• /channel/empty  - 清空一个通道(channel)
• /channel/pause  - 暂停通道(channel)的消息流
• /channel/unpause  - 恢复通道(channel)的消息

POST /pubAnchor link for: post pub

发布消息

Query Params:

topic - the topic to publish to

Body:

raw message bytes

Example:

$ curl -d "<message>" http://127.0.0.1:4151/pub?topic=name

POST /mpubAnchor link for: post mpub

一次发多条消息

Query Params:

topic - the topic to publish tobinary - bool ('true' or 'false') to enable binary mode

Body

\n separated raw message bytes

NOTE: 多条消息用\n分割, 使用 ?binary=true 参数时,将启用binary mode,但是post body需要符合以下形式,HTTP Content-Length header 需要被发送,长度为POST body的长度

[ 4-byte num messages ][ 4-byte message #1 size ][ N-byte binary data ]      ... (repeated <num_messages> times)

Example:

$ curl -d "<message>\n<message>\n<message>" http://127.0.0.1:4151/mpub?topic=name

POST /topic/createAnchor link for: post topiccreate

弃用名字: /create_topic

创建topic

Query Params:

topic - the topic to create

Example:

$ curl -X POST http://127.0.0.1:4151/topic/create?topic=name

POST /topic/deleteAnchor link for: post topicdelete

弃用名字: /delete_topic

删除一个存在的topic,包括所有的channel

Query Params:

topic - the existing topic to delete

Example:

$ curl -X POST http://127.0.0.1:4151/topic/delete?topic=name

POST /channel/createAnchor link for: post channelcreate

弃用名字: /create_channel

从一个已经存在的topic上创建channel

Query Params:

topic - the existing topicchannel - the channel to create

Example:

$ curl -X POST http://127.0.0.1:4151/channel/create?topic=name&channel=name

POST /channel/deleteAnchor link for: post channeldelete

Deprecated alias: /delete_channel

在一个存在的topic上删除一个channel

Query Params:

topic - the existing topicchannel - the existing channel to delete

Example:

$ curl -X POST http://127.0.0.1:4151/channel/delete?topic=name&channel=name

POST /topic/emptyAnchor link for: post topicempty

Deprecated alias: /empty_topic

清空一个topic里所有的队列消息(包括内存和硬盘里的)

Query Params:

topic - the existing topic to empty

Example:

$ curl -X POST http://127.0.0.1:4151/topic/empty?topic=name

POST /channel/emptyAnchor link for: post channelempty

Deprecated alias: /empty_channel

清空一个channel里所有的队列消息(包括内存和硬盘里的)

Query Params:

topic - the existing topicchannel - the existing channel to empty

Example:

$ curl -X POST http://127.0.0.1:4151/channel/empty?topic=name&channel=name

POST /topic/pauseAnchor link for: post topicpause

Deprecated alias: /pause_topic

暂停发送消息到所有的channel,消息将会暂时队列在topic内部

Pause message flow to all channels on an existing topic (messages will queue at topic)

Query Params:

topic - the existing topic

Example:

$ curl -X POST http://127.0.0.1:4151/topic/pause?topic=name

POST /topic/unpauseAnchor link for: post topicunpause

Deprecated alias: /unpause_topic

终止暂停,继续发送消息到channel

Resume message flow to channels of an existing, paused, topic

Query Params:

topic - the existing topic

Example:

$ curl -X POST http://127.0.0.1:4151/topic/unpause?topic=name

POST /channel/pauseAnchor link for: post channelpause

Deprecated alias: /channel_pause

暂停发送消息到消费者,消息被队列在channel

Pause message flow to consumers of an existing channel (messages will queue at channel)

Query Params:

topic - the existing topicchannel - the existing channel to pause

Example:

$ curl -X POST http://127.0.0.1:4151/channel/pause?topic=name&channel=name

POST /channel/unpauseAnchor link for: post channelunpause

Deprecated alias: /unpause_channel

继续发送消息到消费者

Resume message flow to consumers of an existing, paused, channel

Query Params:

topic - the existing topicchannel - the existing channel to pause

Example:

$ curl -X POST http://127.0.0.1:4151/channel/unpause?topic=name&channel=name

GET /statsAnchor link for: get stats

返回内部的统计信息

Return internal statistics

Query Params

format - (optional) `text` or `json` (default = `text`)topic - (optional) filter to topicchannel - (optional) filter to channel

Example:

$ curl http://127.0.0.1:4151/stats

GET /pingAnchor link for: get ping

监控终端,返回200是没有问题的,返回500的就是有问题“unhealthy”的。

Monitoring endpoint, should return 200 OK. It returns an HTTP 500 if it is not healthy.

NOTE: The only “unhealthy” state is if nsqd failed to write messages to disk when overflow occurred.

目前唯一会出现这种情况的是当发生内存中的消息溢出的时候,nsqd不能把消息写到硬盘上。

GET /infoAnchor link for: get info

Version information

返回版本信息

GET /debug/pprofAnchor link for: get debugpprof

An index page of available debugging endpoints

可用的调试节点的页码

GET /debug/pprof/profileAnchor link for: get debugpprofprofile

Starts a pprof CPU profile for 30s and returns the output via the request

NOTE: this endpoint is not listed in the /debug/pprof index page because of its effect on runtime performance.

开始30秒的pprof CPU配置,并通过请求返回

由于这些节点处在运行时,所有这些节点将不在debug/pprof展示的页码中显示

GET /debug/pprof/goroutineAnchor link for: get debugpprofgoroutine

Returns a stack trace for all running goroutines

返回所有运行的go路由的栈跟踪

GET /debug/pprof/heapAnchor link for: get debugpprofheap

Returns a heap and memstats profile (top portion can be used as a pprof memory profile)

返回堆和内存配置信息(前面的内容可作为 pprof配置信息)

GET /debug/pprof/blockAnchor link for: get debugpprofblock

返回 goroutine 块配置信息

GET /debug/pprof/threadcreate

返回 goroutine 栈记录 

GET /config/nsqlookupd_tcp_addressesAnchor link for: get confignsqlookupdtcpaddresses

nsqlookupd TCP addresses的列表

Example:

$ curl http://127.0.0.1:4151/config/nsqlookupd_tcp_addresses

PUT /config/nsqlookupd_tcp_addressesAnchor link for: put confignsqlookupdtcpaddresses

更新 nsqlookupd TCP addresses.

Body:

JSON array of TCP addresses.

Example:

$ curl -X PUT http://127.0.0.1:4151/config/nsqlookupd_tcp_addresses \    -d '["127.0.0.1:4160", "127.0.0.2:4160"]'




A

PUT /config/nsqlookupd_tcp_addressesAnchor link for: put confignsqlookupdtcpaddresses

Update the nsqlookupd TCP addresses.

Body:

JSON array of TCP addresses.

Example:

$ curl -X PUT http://127.0.0.1:4151/config/nsqlookupd_tcp_addresses \    -d '["127.0.0.1:4160", "127.0.0.2:4160"]'
范湖nchor link for: get confignsqlookupdtcpaddresses

0 0
原创粉丝点击