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
Post a Comment