Should I close KafkaSender after sent batch of messages ?

616 Views Asked by At

The application is a long-run message receiver, the app receive upstream message and transform the messages to small messages, then put these small messages into Kafka.

I found document from Reactor Kafka said:

Reactor Kafka Guide

When the KafkaSender is no longer required, the KafkaSender instance can be closed. The underlying KafkaProducer is closed, closing all client connections and freeing all memory used by the producer.

My question is:

Should I need to close the KafkaSender after every batch of message sent ? Is it make sences that use singleton instance of KafkaSender in the app and just close it when the app shutdown?

Thanks.

1

There are 1 best solutions below

0
On

I think there is an answer. https://projectreactor.io/docs/kafka/release/api/reactor/kafka/sender/KafkaSender.html

Reactive producer that sends outgoing records to topic partitions of a Kafka cluster. The producer is thread-safe and can be used to publish records to multiple partitions. It is recommended that a single KafkaSender is shared for each record type in a client application.