Kafka为非Java语言创建主题API选项 [英] Kafka Create Topic API Options for Non-Java Languages

查看:40
本文介绍了Kafka为非Java语言创建主题API选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管您可以通过Java或基于Java的语言创建主题(请参见

While you can create a topic via Java or Java-based languages (see here), there does not seem to be a clean way to do this without using Java. As a result, pure-language client APIs (like kafka-node, a pure JavaScript client) can't directly create topics. Instead, we have two options:

1)使用类似向主题发送元数据请求之类的技巧-如果 auto.create.topics.enable 设置为 true ,则可以创建一个主题-但仅使用默认配置,无法控制分区等.

1) Use a hack like sending a metadata request to a topic -- if auto.create.topics.enable is set to true, then you can create a topic -- but only with the default configuration, no control over partitions, etc.

2)围绕基于Java的客户端编写包装程序,仅用于主题创建.最简单的方法是使用命令行参数来 exec 脚本 bin/kafka-topics.sh ,至少可以这样说,这很丑.

2) Write a wrapper around a Java-based client just for topic creation. The easiest way to do this is to exec the script bin/kafka-topics.sh with command line arguments, which is ugly, to say the least.

但是,还有更好的方法吗?有一个适用于Zookeeper的纯JavaScript客户端,即 node-zookeeper-client ,如果我直接在Zookeeper中操作代理/分区信息会怎样?

Is there a better way to do this, though? There's a pure-JavaScript client for Zookeeper, node-zookeeper-client, what happens if I manipulate broker / partition info directly in Zookeeper?

还有其他想法吗?

推荐答案

您现在可以使用REST Proxy API v3创建带有针对非Java语言的http请求的Kafka主题.

You can now use REST Proxy API v3 to create Kafka topics with http requests for non-Java languages.

根据融合REST代理API参考可以使用当前作为预览功能提供的REST Proxy API v3创建主题.

According to the Confluent REST Proxy API Reference the creation of a topic is possible with the REST Proxy API v3 that is currently available as a preview feature.

"API v3可用于评估和非生产测试目的,或向Confluent提供反馈."

"The API v3 can be used for evaluation and non-production testing purposes or to provide feedback to Confluent."

下面提供了主题创建请求的示例,并记录了

An example of a topic creation request is presented below and documented here:

POST /v3/clusters/cluster-1/topics HTTP/1.1
Host: kafkaproxy.example.com
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "attributes": {
      "topic_name": "topic-1",
      "partitions_count": 2,
      "replication_factor": 3,
      "configs": [
        {
          "name": "cleanup.policy",
          "value": "compact"
        }
      ]
    }
  }
}

使用 curl :

curl -X POST -H "Content-Type: application/vnd.api+json" -H "Accept: application/vnd.api+json" \
          --data '{"data":{"attributes": {"topic_name": "topic-1", "partitions_count": 2, "replication_factor": 1, "configs": [{"name": "cleanup.policy","value": "compact"}]}}}' \
          "http://localhost:8082/v3/clusters/<cluster-id>/topics"

其中可以使用

curl -X GET -H "Accept: application/vnd.api+json" localhost:8082/v3/clusters

这篇关于Kafka为非Java语言创建主题API选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆