java中key的作用_kafka中的key有啥作用?

kafka源码ProducerRecord.java类的注释说明了key的作用,注释如下:

A key/value pair to be sent to Kafka. This consists of a topic name to which the record is being sent, an optional partition number, and an optional key and value.

一个k/v对被发送到kafka。这包含被发送记录的主题名字,一个可选的分区编号,一个可选的key和value。

If a valid partition number is specified that partition will be used when sending the record. If no partition is specified but a key is present a partition will be chosen using a hash of the key. If neither key nor partition is present a partition will be assigned in a round-robin fashion.

如果一个有效的partition属性数值被指定,那么在发送记录时partition属性数值就会被应用。如果没有partition属性数值被指定,而一个key属性被声明的话,一个partition会通过key的hash而被选中。如果既没有key也没有partition属性数值被声明,那么一个partition将会被分配以轮询的方式。

The record also has an associated timestamp. If the user did not provide a timestamp, the producer will stamp the record with its current time. The timestamp eventually used by Kafka depends on the timestamp type configured for the topic.

record也有一个关联的时间戳。如果用户未提供一个时间戳,producer 将会通过当前的时间标记此record。时间戳最终会被kafka应用,其依赖时间戳类型来配置主题。

If the topic is configured to use {@link org.apache.kafka.common.record.TimestampType#CREATE_TIME CreateTime},the timestamp in the producer record will be used by the broker。

如果主题是配置用的CREATE_TIME ,在producer记录中的时间戳将会被broker应用。

If the topic is configured to use {@link org.apache.kafka.common.record.TimestampType#LOG_APPEND_TIME LogAppendTime}, the timestamp in the producer record will be overwritten by the broker with the broker local time when it appends the message to its log.

如果主题被配置用的LogAppendTime,当broker添加消息到它的日志中的时候,producer记录中的时间戳将会被broker覆盖掉,覆盖成以broker本地的时间。

In either of the cases above, the timestamp that has actually been used will be returned to user in {@link RecordMetadata}

对于以上两者之一,确实已被应用的时间戳将会在RecordMetadata中返回给用户。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值