zbus MQ protocol is pretty simple, by following HTTP format, with zbus control syntax inside of the HTTP headers.
Websocket by default embbeded in the transport stack sharing same TCP port, zbus automatically detect the transport protocol. The rule is straightforward, when websocket step in, HTTP message is translated to JSON format, which is handy to stringify back to standard HTTP message.
{
headers: {
cmd: pub|sub|create|remove|query|ping
id: <message_id>,
apiKey: <apid_key>,
signature: <signature>
},
status: 200|400|404|403|500 ... //[required], standsfor response
url: <url_string>, //[optional]
method: <http_method>, //[optional]
body: <body> //[optional]
}
All requests to zbus should have id field in headers (optional), when auth required, both apiKey and signature are required.
Signature generation algorithm
1) sort key ascending in request (recursively on both key and value), and generate json string
2) Init HmacSHA256 with secretKey, do encrypt on 1)'s json string to generate bytes
3) signature = Hex format in upper case on the 2)'s bytes
Request
{
headers: {
cmd: pub, //required
mq: <mq_name>, //required
},
body: <body>
}
Response
{
status: 200|400|403|500....,
body: <body>
}
Request
{
headers: {
cmd: sub, //required
mq: <mq_name>, //required
channel: <channel_name> //required
window: <window_size>
}
}
Response
First message: indicates subscribe success or failure
{
status: 200|400|403|500,
body: <string_response>
}
Following messages:
{
headers: {
mq: <mq_name>, //required
channel: <channel_name> //required
source: <message from>
id: <message id>
},
body: <business_data>
}
Request
{
headers: {
cmd: take, //required
mq: <mq_name>, //required
channel: <channel_name> //required
window: <batch_size>
}
}
Response
{
status: 200|400|403|500|604, //604 stands for NO data
body: <data>
}
Request
{
headers: {
cmd: create, //required
mq: <mq_name>, //required
mqType: memory|disk|db, //default to memory
mqMask: <mask_integer>,
channel: <channel_name>,
channelMask: <mask_integer>,
offset: <channel_offset>,
checksum: <offset_checksum>
filter: <channel_filter>,
}
}
Response
{
status: 200|400|403|500,
body: <message_response>
}
Request
{
headers: {
cmd: remove, //required
mq: <mq_name>, //required
channel: <channel_name>
}
}
Response
{
status: 200|400|403|500,
body: <message_response>
}
Request
{
headers: {
cmd: query, //required
mq: <mq_name>, //required
channel: <channel_name>
}
}
Response
{
status: 200|400|403|500,
body: <mq_channel_info>
}
Example
{
body: {
channels: [ ],
mask: 0,
name: "DiskQ",
size: 200000,
type: "disk"
},
status: 200
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。