我是卡夫卡的新朋友。我需要通过Spring Boot为Kafka写一个简单的生产者和消费者,实际上我是从micronaut转向Spring Boot。我对主题划分有疑问。在micronaut中,我将@KafkaKey用作分区键,如下所示:
public void process(@KafkaKey MyKey kafkaKey, @Body MyRecord myRecord)
到了春天,我不知道该怎么做,因为我看到KafkaTemplete类将分区参数作为Integer对象。
public ListenableFuture<SendResult<K, V>> send(String topic, Integer partition, K key, @Nullable V data)
那么如何在Spring Boot中执行第一行?
答案 0 :(得分:1)
KafkaTemplate具有不同的发送消息的方法。例如:
send(java.lang.String topic, K key, V data)
end(java.lang.String topic, V data)
您可以在此处选择最合适的方式: https://docs.spring.io/spring-kafka/api/org/springframework/kafka/core/KafkaTemplate.html