lundi 12 septembre 2016

Kafka consumer client creation singleton instance vs static method

Please tell which one is the best practice to create Kafka consumer client.

public class KafkaConsumerFactory {

public static createKafKafkaConsumer(){
       KafkaConsumer consumer = new KafkaConsumer<   (getKafkaConsumerProperties());
      consumer.subscribe(Collections.Singleton.(getTopic()));
      return consumer;
}

Or ..

public class KafkaConsumerFactory {
KafkaConsumer consumer;  

public  createKafKafkaConsumer(){

if(consumer = null)
    {
      consumer = new KafkaConsumer< (getKafkaConsumerProperties());
      consumer.subscribe(Collections.Singleton.(getTopic()));
    }

 return consumer;
}
}

Will there be any considerable benefit in having singleton Kafka consumer client in production environment ?

Aucun commentaire:

Enregistrer un commentaire