Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: kafka writer 无法指定key #1009

Closed
lilong669 opened this issue Feb 6, 2024 · 3 comments
Closed

[Bug]: kafka writer 无法指定key #1009

lilong669 opened this issue Feb 6, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@lilong669
Copy link

What happened?

没有办法配置key,所以分区规则就只能组默认的规则,粘性分区。无法指定分区,让数据均匀到各个分区。不知道我说的作者明白了么。。。希望共同探讨解决方案。

Version

4.1.3 (Default)

OS Type

No response

Java JDK Version

Oracle JDK 1.8.0

Relevant log output

No response

@lilong669 lilong669 added the bug Something isn't working label Feb 6, 2024
@wgzhao
Copy link
Owner

wgzhao commented Feb 6, 2024

很抱歉
你说的我的确没明白

@lilong669
Copy link
Author

很抱歉
你说的我的确没明白

kafka生产者有分区策略,随机分区,roundrobin分区,粘性分区,按key分区。有一个按key分区策略,它能按照指定key的hash值去分配不同的数据到不同的分区,我想设置分区key,然后实现以上功能,能指定怎么配置吗?或者说目前无法配置?

@wgzhao
Copy link
Owner

wgzhao commented Jun 3, 2024

目前可以通过设置 properties 来制定额外的属性,如果要设置分区策略,你可以这样配置你的 json 文件

{
"writer": {
          "name": "kafkawriter",
          "parameter": {
            "brokerList": "localhost:9092",
            "topic": "test-1",
            "partitions": 0,
            "batchSize": 1000,
            "column": ["col1", "col2","col3","col4","col5", "col6", "col7", "col8", "col9"],
           "properties": {
              "partitioner.class": "org.apache.kafka.clients.producer.internals.DefaultPartitioner",
            }
          }
    }
}

其中分区策略对应的值分别为:

  • 默认策略: org.apache.kafka.clients.producer.internals.DefaultPartitioner"
  • 粘性分区: org.apache.kafka.clients.producer.internals.UniformStickyPartitioner
  • 轮转分区:org.apache.kafka.clients.producer.internals.RoundRobinPartitioner

@wgzhao wgzhao closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants