Skip to content

REST API 参考 ​

FlowMQ 提供 REST API 用于管理消息基础设施,包括主题、队列、流和消息的程序化操作。

基础信息 ​

Base URL ​

http://{your-flowmq-host}:{port}/api/v1

认证 ​

在请求头中携带 API Key:

Authorization: Bearer YOUR_API_KEY

响应格式 ​

成功响应:

json
{
  "success": true,
  "data": { ... },
  "error": null
}

错误响应:

json
{
  "success": false,
  "data": null,
  "error": {
    "code": "ERROR_CODE",
    "message": "错误描述",
    "details": {}
  }
}

HTTP 状态码 ​

状态码说明
200请求成功
201资源创建成功
400请求参数无效
401未认证或认证失败
403权限不足
404资源不存在
409资源已存在
500服务器内部错误

主题 (Topics) ​

发布消息 ​

http
POST /topics/{topic_name}/messages

请求体:

json
{
  "payload": "Hello, FlowMQ!",
  "content_type": "text/plain",
  "properties": {
    "user_id": "12345",
    "priority": "high"
  },
  "partition_key": "user-12345"
}
字段类型必填说明
payloadstring是消息内容
content_typestring否MIME 类型,默认 application/json
propertiesobject否自定义消息属性
partition_keystring否分区键

响应:

json
{
  "success": true,
  "data": {
    "message_id": "msg_abc123",
    "topic": "orders/eu/new",
    "timestamp": "2024-01-15T10:30:00Z"
  }
}

批量发布 ​

http
POST /topics/{topic_name}/messages/batch

请求体:

json
{
  "messages": [
    { "payload": "Message 1", "properties": {"batch_id": "batch-1"} },
    { "payload": "Message 2", "properties": {"batch_id": "batch-1"} }
  ]
}

队列 (Queues) ​

创建队列 ​

http
POST /queues

请求体:

json
{
  "name": "order-processing-queue",
  "topic_filter": "orders/#",
  "max_size_mb": 1024,
  "message_ttl_seconds": 86400,
  "max_retries": 3,
  "dead_letter_topic": "orders/dead-letter"
}
字段类型必填说明
namestring是队列名称
topic_filterstring是主题过滤器(如 orders/#)
max_size_mbint否最大容量(MB),默认 1024
message_ttl_secondsint否消息 TTL(秒),默认 86400
max_retriesint否最大重试次数,默认 3
dead_letter_topicstring否死信主题

列出队列 ​

http
GET /queues?limit=50&offset=0

获取队列详情 ​

http
GET /queues/{queue_name}

删除队列 ​

http
DELETE /queues/{queue_name}

消费消息 ​

http
POST /queues/{queue_name}/messages/consume

请求体:

json
{
  "max_messages": 10,
  "timeout_seconds": 30,
  "visibility_timeout_seconds": 300
}

响应:

json
{
  "success": true,
  "data": {
    "messages": [
      {
        "message_id": "msg_abc123",
        "payload": "Order #12345",
        "content_type": "application/json",
        "properties": {"priority": "high"},
        "publish_time": "2024-01-15T10:30:00Z",
        "receive_count": 1,
        "receipt_handle": "receipt_xyz789"
      }
    ],
    "count": 1
  }
}

确认消息 ​

http
POST /queues/{queue_name}/messages/{message_id}/ack

请求体:

json
{
  "receipt_handle": "receipt_xyz789"
}

流 (Streams) ​

创建流 ​

http
POST /streams

请求体:

json
{
  "name": "order-events-stream",
  "topic_filter": "orders/#",
  "retention_days": 30,
  "max_size_gb": 100,
  "partition_count": 3
}
字段类型必填说明
namestring是流名称
topic_filterstring是主题过滤器
retention_daysint否消息保留天数,默认 7
max_size_gbint否最大容量(GB),默认 10
partition_countint否分区数,默认 1

列出流 ​

http
GET /streams?limit=50&offset=0

获取流详情 ​

http
GET /streams/{stream_name}

删除流 ​

http
DELETE /streams/{stream_name}

注意:以上 API 接口以企业版实际交付版本为准,具体参数和行为可能因版本而异。

FlowMQ