Kafka Confluent REST Proxy POST to Topic响应HTTP 415 Unsupported Media Type

llew8vvj  于 2023-08-02  发布在  Apache
关注(0)|答案(2)|浏览(115)

我成功地创建了一个主题,测试主题。当我尝试使用curl命令为主题生成数据时:

curl -v -X POST -H "Content-Type: application/json" -H "Accept: application/json" \
     --data '{"records":[{"key":"jsmith","value":"alarm clock"}, \
     {"key":"htanaka","value":"batteries"},{"key":"awalther","value":"bookshelves"}]}' \
     "http://localhost:8082/topics/test-topic"

字符串
我得到以下响应:
第一个月
我在Docker日志中看到了这个异常:
剩余代理|[2023-07-08 07:40:46,829] ERROR Request Failed with exception(io.confluent.rest.exceptions.DebuggableExceptionMapper)rest-proxy| javax.ws.rs.NotSupportedException:HTTP 415不支持的媒体类型rest-proxy|在org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.getMethodRouter(MethodSelectingRouter.java:421)... POST /topics/test-topic HTTP/1.1”415 62“-”“curl/7.87.0”4(io.confluent.rest-utils.requests)
已尝试更改内容类型:“内容类型:application/vnd.kafka.json.v3+json”,但表现相同。
任何见解赞赏。

wn9m85ua

wn9m85ua1#

请参阅README.md了解REST代理。V3 API的格式和URL与V2不同。Confluent的快速入门页面尚未更新。
下面是一个单一数据值的V3 curl post:

curl -X POST -H "Content-Type: application/json" \
   -d '{"value":{"type":"JSON","data":{"name":"testUser"}}}' \
   http://localhost:8082/v3/clusters/xFhUvurESIeeCI87SXWR-Q/topics/jsontest/records

字符串
下面是一个包含多个数据值的V3 curl帖子:

curl -X POST -H "Content-Type: application/json" \
   -d '{"value":{"type":"JSON","data":"ONE"}} {"value":{"type":"JSON","data":"TWO"}}' \
   http://localhost:8082/v3/clusters/xFhUvurESIeeCI87SXWR-Q/topics/jsontest/records

yh2wf1be

yh2wf1be2#

上述来自www.example.com文件的示例README.md没有提供Kafka密钥值。下面是一些键值的例子,这些键值可以用于数据的分区放置。
单值:

curl -v -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
--data '{"key": {"type": "JSON", "data": 110179}, "value": {"type": "JSON", "data": {"field1": "value1"}}}' \
http://localhost:8082/v3/clusters/vn6t4eKOSqKAMJLIDu-0eg/topics/rtc/records

字符串
多个值:

curl -v -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
--data '{"key": {"type": "JSON", "data": 111}, "value": {"type": "JSON", "data": {"field1": "value1"}}} {"key": {"type": "JSON", "data": 222}, "value": {"type": "JSON", "data": {"field2": "value2"}}}' \
http://localhost:8082/v3/clusters/vn6t4eKOSqKAMJLIDu-0eg/topics/rtc/records

相关问题