Does it make sense to have a single send inside a kafka transaction using spring kafka?

From kafka 3.0 we get strongest delivery guarantees by default (acks=all, enable.idempotence=true). ( www.confluent.io/blog/apache-kafka-3-0-major-improvements-and-new-features/ ).

Mostly, transactions mean atomicity ( and in sql, isolation, etc ).

Having strongly delivery guarantee, I can send a message in kafka either as:

kafkaTemplate.send("my_topic", "my value");

or

kafkaTemplate.executeInTransaction(kt -> kt.send("my_topic", "my value"));

but is there any difference if I only have a single send inside?

I would see the sense of a transaction if I would want to send atomically more messages like:

List values = Arrays.asList("dog", "cat", "horse", "zebra");
kafkaTemplate.executeInTransaction(kt -> {
    values.forEach(v -> kt.send("my_topic", v));
    return null;
});

Read more here: Source link