首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何配置httpsink以设置标头内容类型

如何配置httpsink以设置标头内容类型
EN

Stack Overflow用户
提问于 2022-12-01 14:40:11
回答 1查看 26关注 0票数 0

我已经设置了本地kafka集群和本地微服务端点。我想要的是向httpsink提供像{"foo":"bar"}这样的主题消息,这样它就可以用json调用API端点。

我没有使用模式注册中心。

下面是我的合流httpsink连接器配置,

代码语言:javascript
复制
{
  "name": "httpsink3",
  "config": {
    "name": "httpsink3",
    "connector.class": "io.confluent.connect.http.HttpSinkConnector",
    "tasks.max": "1",
    "key.converter": "org.apache.kafka.connect.storage.StringConverter",
    "value.converter": "org.apache.kafka.connect.storage.StringConverter",
    "topics": "test3",
    "http.api.url": "http://localhost:5000/out",
    "reporter.result.topic.name": "success-responses",
    "reporter.result.topic.replication.factor": "1",
    "reporter.error.topic.name": "error-responses",
    "reporter.error.topic.replication.factor": "1",
    "reporter.bootstrap.servers": "localhost:9092",
    "confluent.topic.bootstrap.servers": "localhost:9092",
    "confluent.topic.replication.factor": "1"
  }
}

结果是

代码语言:javascript
复制
decision-decision-1  | [2022-12-01 15:10:52,500] DEBUG in routes 79: request.headers=Content-Length: 13
decision-decision-1  | Content-Type: text/plain; charset=UTF-8
decision-decision-1  | Host: localhost:5000
decision-decision-1  | Connection: Keep-Alive
decision-decision-1  | User-Agent: Apache-HttpClient/4.5.13 (Java/11.0.17)
decision-decision-1  | Accept-Encoding: gzip,deflate
decision-decision-1  |
decision-decision-1  |
decision-decision-1  | [2022-12-01 15:10:52,501] DEBUG in routes 80: request.data={"foo":"bar"}
decision-decision-1  | [2022-12-01 15:10:52,502] DEBUG in routes 86: is json str

我期望将输出消息头设置为application/json,而不是text/平原

我也尝试过使用选项"value.converter": "org.apache.kafka.connect.json.JsonConverter",,但更糟糕的是,它保留了文本标题,但将内容更改为{"foo"="bar"}

有什么办法来配置这个吗?

非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-12-01 15:56:55

已修复。遵循这个https://docs.confluent.io/kafka-connectors/http/current/overview.html#header-forwarding-example

并将标题选项更改为" headers ":“Content: application/json”

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74643641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档