java - Kafka consumer client creation singleton instance vs static method -


please tell 1 best practice 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  kafkaconsumer createkafkafkaconsumer(){  if(consumer = null)     {       consumer = new kafkaconsumer< (getkafkaconsumerproperties());       consumer.subscribe(collections.singleton.(gettopic()));     }   return consumer; } } 

will there considerable benefit in having singleton kafka consumer client in production environment ?

kafka consumer not thread safe shouldn't singleton. in case of producer, thread safe , recommended have single instance.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -