1. 客戶端認(rèn)證
如果kafka客戶端是認(rèn)證的,那么可以使用userId和clientId兩種認(rèn)證方式。如果沒有認(rèn)證只能使用clientId限流。
bin/kafka-configs.sh --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1048576,consumer_byte_rate=1024' \ --entity-type clients --entity-name clientA
對(duì)clientId=clientA的客戶端添加限流設(shè)置。producer_byte_rate表示每秒最多能寫入到消息量,單位為byte/sec。consumer_byte_rate表示每秒最多能消費(fèi)的消息了,單位也為byte/sec。設(shè)置后立即生效。
2. Producer & Consumer設(shè)置
在producer和consumer的配置中需要加入client.id配置:
Producer:
props.put(ProducerConfig.CLIENT_ID_CONFIG, "clientA");
Consumer:
props.put(ConsumerConfig.CLIENT_ID_CONFIG, "clientA");
限流效果:

3. 查看限流信息
zookeeper:
[zk: localhost:2181(CONNECTED) 5] get /config/clients/clientA {"version":1,"config":{"producer_byte_rate":"1048576","consumer_byte_rate":"1024"}}
浙公網(wǎng)安備 33010602011771號(hào)