我已经使用 curl 调用在 kafka-rest 上执行了 HTTP POST。一个请求成功,但另一个请求(具有不同的 json)返回 422 错误 ({"error_code":422,"message":"Unrecognized field: receiver"})。
工作要求
curl -X POST -H "Content-Type: application/vnd.kafka.json.v2+json" -H "Accept: application/vnd.kafka.v2+json" --data '{"records":[{"value":{"foo":"bar"}}]}' "http://localhost:8082/topics/jsontest"
输出
{"offsets":[{"partition":0,"offset":0,"error_code":null,"error":null}],"key_schema_id":null,"value_schema_id":null}
不工作请求
curl -X POST -H "Content-Type: application/vnd.kafka.json.v2+json" -H "Accept: application/vnd.kafka.v2+json" --data @alert-request.json "http://localhost:8082/topics/jsontest"
输出
{"error_code":422,"message":"Unrecognized field: receiver"}
警报请求.json
{
"receiver": "email-logs",
"status": "firing",
"alerts": [
{
"status": "firing",
"labels": {
"alertname": "CPUUsageAbove20%",
"instance": "node-exporter:9100",
"job": "node-exporter",
"monitor": "my-project",
"severity": "warn",
"team": "raptors"
},
"annotations": {
"dashboard": "www.prometheus.io",
"description": "CPU usage on node-exporter:9100 has reached 60"
},
"startsAt": "2020-04-30T08:03:17.309164516Z",
"endsAt": "0001-01-01T00:00:00Z",
"generatorURL": "http://0ab6d9955c65:9090/graph?g0.expr=60+%3E+job%3Anode_cpu_seconds%3Ausage+%3E+20\u0026g0.tab=1",
"fingerprint": "9c558a8c20c2ba08"
}
],
"groupLabels": {
"alertname": "CPUUsageAbove20%",
"team": "raptors"
},
"commonLabels": {
"alertname": "CPUUsageAbove20%",
"instance": "node-exporter:9100",
"job": "node-exporter",
"monitor": "my-project",
"severity": "warn",
"team": "raptors"
},
"commonAnnotations": {
"dashboard": "www.prometheus.io",
"description": "CPU usage on node-exporter:9100 has reached 60"
},
"externalURL": "http://5493399b56dc:9093",
"version": "4",
"groupKey": "{}/{team=~\"^(?:(raptors|leafs))$\"}:{alertname=\"CPUUsageAbove20%\", team=\"raptors\"}"
}
我需要使用 kafka-rest 将上面的 json 写入 kafka,并且我使用 curl 调用在 kafka-rest 上执行 HTTP 发布,但它返回错误。如何使用 kafka-rest(使用 curl)成功写入 kafka?