本来以为我用过幂等性了,再使用事务应该很简单,不知道幂等性使用的可以去查看上一篇。
首先肯定是照着文档配置生产者,配置如下:
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092,localhost:9093,localhost:9094");
props.put("acks", "all");
props.put("retries", 3);
props.put("batch.size", 163840);
props.put("linger.ms", 10);
props.put("buffer.memory", 33554432);
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("enable.idempotence",true);
props.put("max.in.flight.requests.per.connection",5);
props.put("transactional.id","aaa");
Producer<String, String> producer = new KafkaProdu