小编Naf*_*uji的帖子

使用 Kafka 进行一对一和群组消息传递

由于 Kafka 具有基于主题的发布-订阅架构,我如何使用 Kafka 处理 Web 应用程序的一对一和组消息传递部分?我正在使用 SpringBoot+Angular 堆栈和 Docker Kafka 服务器。

messaging apache-kafka spring-kafka

5
推荐指数
1
解决办法
2088
查看次数

KafkaTemplate.send(key,value,topic) 与自定义分区器?

我看到并使用默认分区器类实现了KafkaTemplate.send(TOPIC,message)方法。

但在这里,我不传递钥匙。我有一个简单的自定义分区器类,我还想发送到KafkaTemplate(TOPIC,key,message)这样的 kafka 服务器,其中在 ProducerConfig 中我设置了用于分区的 customPartitioner 类。

我看到如果我提供自定义分区器,KafkaTemplate 的 Will send(Topic, Key, Message) 方法会调用 Partition 方法吗?但我没有完全明白。

  1. 我的简单的 customPartitioner 类:
public class CustomPartitionar implements Partitioner {
   private PartitionMapper newMapper;
   public CustomPartitionar(){
       newMapper = new PartitionMapper();
   }
   @Override
   public void configure(Map<String, ?> configs) {

   }
   @Override
   public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes,Cluster cluster) {
       int partition = 0;
       String userName = (String) key;
       // Find the id …
Run Code Online (Sandbox Code Playgroud)

spring-kafka

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

spring-kafka ×2

apache-kafka ×1

messaging ×1