-
Notifications
You must be signed in to change notification settings - Fork 52
KafkaConnectionPool
VictorZeng edited this page May 12, 2016
·
3 revisions
Use the KafkaConnectionPool need instantiate PoolConfig
and Properties
For example, the following
/* poolConfig */
PoolConfig config = new PoolConfig();
config.setMaxTotal(20);
config.setMaxIdle(5);
config.setMaxWaitMillis(1000);
config.setTestOnBorrow(true);
/* properties */
Properties props = new Properties();
props.setProperty("metadata.broker.list", "localhost:9092");
props.setProperty("producer.type", "async");
props.setProperty("request.required.acks", "0");
props.setProperty("compression.codec", "snappy");
props.setProperty("batch.num.messages", "200");
/* connection pool */
KafkaConnectionPool pool = new KafkaConnectionPool(config, props);
/* pool getConnection */
Producer<byte[], byte[]> producer = pool.getConnection();
...
/* producer send */
producer.send(...);
/* pool returnConnection */
pool.returnConnection(producer);
More configs see the Configuration wiki.