2.8 KiB
2.8 KiB
WS Checker
type: ws 用于 WebSocket 服务可达性检查和消息交互验证。
配置项
| 字段 | 说明 | 必填 | 默认值 |
|---|---|---|---|
ws.url |
目标 URL,必须以 ws:// 或 wss:// 开头 |
是 | 无 |
ws.headers |
握手 HTTP 头 | 否 | {} |
ws.subprotocols |
子协议协商 | 否 | [] |
ws.ignoreSSL |
忽略 TLS 证书校验 | 否 | false |
ws.send |
发送的 text 消息,配置后进入请求-响应模式 | 否 | 无 |
ws.receiveTimeout |
等待响应超时,毫秒 | 否 | 5000 |
ws.maxMessageBytes |
单条消息最大字节数,支持 KB、MB、GB 单位 |
否 | 4KB |
expect 校验项
| 字段 | 说明 | 必填 | 默认值 |
|---|---|---|---|
connected |
期望连接结果,true 可达或 false 期望不可达 |
否 | true |
handshakeHeaders |
握手响应头校验,使用 KeyedExpectations |
否 | 无 |
message |
收到的消息内容校验,使用 ContentExpectations 数组,需配置 ws.send |
否 | 无 |
connectTimeMs |
连接建立耗时校验,使用 ValueMatcher |
否 | 无 |
durationMs |
完整执行耗时校验,使用 ValueMatcher |
否 | 无 |
两种模式
不配置 ws.send 时只做可达性检查(连接后立即关闭),配置 ws.send 后进入请求-响应模式(发送消息并等待首条响应)。
示例
可达性检查:
- id: "ws-reachability"
name: "WebSocket 服务可达"
type: ws
ws:
url: "wss://api.example.com/ws"
expect:
durationMs:
lte: 3000
带鉴权的请求-响应:
- id: "ws-echo"
name: "WebSocket Echo 检查"
type: ws
ws:
url: "wss://echo.example.com/ws"
headers:
Authorization: "Bearer ${TOKEN}"
subprotocols: ["json"]
send: '{"action":"ping"}'
receiveTimeout: 3000
expect:
handshakeHeaders:
Sec-WebSocket-Protocol:
equals: "json"
message:
- json:
path: "$.action"
equals: "pong"
durationMs:
lte: 5000
期望不可达:
- id: "ws-internal-down"
name: "内部服务已下线"
type: ws
ws:
url: "ws://internal.monitor:9443/ws"
expect:
connected: false