kafka配置

记一下kafka生产者,消费者的Properties配置信息

producer

Properties properties = new Properties();
properties.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServerConfig);
properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
properties.setProperty(ProducerConfig.ACKS_CONFIG, "1");
properties.setProperty(ProducerConfig.BATCH_SIZE_CONFIG, "204800");
properties.setProperty(ProducerConfig.RETRIES_CONFIG, "1");
properties.setProperty(ProducerConfig.PARTITIONER_CLASS_CONFIG, "org.apache.kafka.clients.producer.internals.DefaultPartitioner");
properties.setProperty(ProducerConfig.BUFFER_MEMORY_CONFIG, "33554432");
properties.setProperty(ProducerConfig.COMPRESSION_TYPE_CONFIG, "none");
properties.setProperty(ProducerConfig.MAX_BLOCK_MS_CONFIG, "60000");
properties.setProperty(ProducerConfig.SEND_BUFFER_CONFIG, "131072");
properties.setProperty(ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG, "540000");
properties.setProperty(ProducerConfig.MAX_REQUEST_SIZE_CONFIG, "1048576");
properties.setProperty(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, "30000");
properties.setProperty(ProducerConfig.RECEIVE_BUFFER_CONFIG, "32768");

consumer

Properties properties = new Properties();
properties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServerConfig);
properties.setProperty(ConsumerConfig.GROUP_ID_CONFIG, consumerGroupId);
properties.setProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
properties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
properties.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
properties.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
properties.setProperty(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, "1048576");
properties.setProperty(ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG, "60000");
properties.setProperty(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, "30000");
properties.setProperty(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG, "10000");

其中ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG有个限制,必须是在roup.min.session.timeout.ms和roup.max.session.timeout.ms之间,max默认是30000,这个值不设置还不行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值