Apache kafka 如何从kafka主题中检索消息并将其用作汇合http接收器连接器中的值?

Apache kafka 如何从kafka主题中检索消息并将其用作汇合http接收器连接器中的值?,apache-kafka,apache-kafka-connect,confluent-platform,Apache Kafka,Apache Kafka Connect,Confluent Platform,我使用confluent http接收器连接器读取来自kafka主题的消息并将其发送到端点。 下面是http接收器连接器 { “名称”:“HttpSink”, “配置”:{ “主题”:“http消息”, “tasks.max”:“1”, “connector.class”:“io.confluent.connect.http.HttpSinkConnector”, “value.converter”:“org.apache.kafka.connect.storage.StringConverte

我使用confluent http接收器连接器读取来自kafka主题的消息并将其发送到端点。 下面是http接收器连接器

{
“名称”:“HttpSink”,
“配置”:{
“主题”:“http消息”,
“tasks.max”:“1”,
“connector.class”:“io.confluent.connect.http.HttpSinkConnector”,
“value.converter”:“org.apache.kafka.connect.storage.StringConverter”,
“主题”:“主题名称”,
“request.method”:“POST”,
“behavior.on.null.values”:“忽略”,
“behavior.on.error”:“log”,
“confluent.topic.bootstrap.servers”:“localhost:9092”,
“confluent.topic.replication.factor”:“1”,
“reporter.bootstrap.servers”:“localhost:9092”,
“reporter.result.topic.name”:“成功响应”,
“reporter.result.topic.replication.factor”:“1”,
“reporter.error.topic.name”:“错误响应”,
“reporter.error.topic.replication.factor”:“1”,
“http.api.url”:”,
“授权类型”:“基本”,
“connection.user”:“”,
“连接。密码”:”
}
}
主题中的消息具有以下json格式:

{
“端点url”:http://localhost:8080/api/messages",
“rest方法”:“,
“凭证”:{“用户名”:“用户名”,“密码”:“密码”},
“有效载荷”:{}
}
因此,使用http接收器连接器,我需要从主题消息中检索“端点url”和“凭据”的值,并将其用作同一连接器中的“http.api.url”、“connection.user”和“connection.password”密钥的值

所以最终的格式应该是

{
“名称”:“HttpSink”,
“配置”:{
“主题”:“http消息”,
“tasks.max”:“1”,
“connector.class”:“io.confluent.connect.http.HttpSinkConnector”,
“value.converter”:“org.apache.kafka.connect.storage.StringConverter”,
“主题”:“主题”,
“request.method”:“POST”,
“behavior.on.null.values”:“忽略”,
“behavior.on.error”:“log”,
“confluent.topic.bootstrap.servers”:“localhost:9092”,
“confluent.topic.replication.factor”:“1”,
“reporter.bootstrap.servers”:“localhost:9092”,
“reporter.result.topic.name”:“成功响应”,
“reporter.result.topic.replication.factor”:“1”,
“reporter.error.topic.name”:“错误响应”,
“reporter.error.topic.replication.factor”:“1”,
“http.api.url”:”http://localhost:8080/api/messages",
“授权类型”:“基本”,
“connection.user”:“用户名”,
“连接.密码”:“密码”
}
}

如何从主题消息中检索数据并在同一连接器中使用它?

我找到了答案。这可以通过创建自定义连接器来实现。下面是http接收器自定义连接器的参考链接

使用maven:

使用gradle:

执行步骤

Step 1 : Clone the project and build
Step 2 : Copy the jar to the desired location. For example, you can create a directory named <path-to-kafka>/share/kafka/plugins then copy the connector plugin jar.
Step 3 : Add this to the plugin path in your Connect properties file. For example, plugin.path=/usr/local/share/kafka/plugins. Kafka Connect finds the plugins using its plugin path. A plugin path is a comma-separated list of directories defined in the Kafka Connect's worker configuration.
Step 4 : Start the Connect workers with that configuration. Connect will discover all connectors defined within those plugins.
connect-http-sink.properties文件内容如下所示:

name=HttpSink
http.api.url=http://localhost:8080/api/messages
request.methods=POST
topics=http-test-topic
connector.class=com.connector.HttpSinkConnector

我认为您必须获取连接器源代码并编辑
公共作废(收集记录)
方法。下面是一个http接收器连接器示例:@Felipe感谢您的回复。是的,可以通过使用自定义连接器来实现。
name=HttpSink
http.api.url=http://localhost:8080/api/messages
request.methods=POST
topics=http-test-topic
connector.class=com.connector.HttpSinkConnector