Reputation: 877
I know that quotas are based on client-id
. Basically I want to run the kafka-producer-perf-test
with a particular client id to test whether the quotas work properly.
How can I assign a client-id
for a particular producer (or) partition?
Upvotes: 5
Views: 26938
Reputation: 1349
You can use ProducerRecord
to specify which partition you want to send message. Say partition 0. Create KafkaConsumer
and assign consumer to specific partition (in this case partition 0). This will ensure, producer and consumer (with given client-id) both are working on same partition id of topic.
ProducerRecord(java.lang.String topic, ava.lang.Integer partition, K key, V value)
Produce message to partition 0
ProducerRecord<byte[],byte[]> record = new ProducerRecord<byte[],byte[]>("PerftestTopic", 0, key, value)
producer.send(record);
Consumer to read from specific partition
TopicPartition partition0 = new TopicPartition("PerftestTopic", 0);
consumer.assign(Arrays.asList(partition0));
Upvotes: 0
Reputation: 1952
When creating a producer, you can assign a unique value to client.id
property
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("client.id", "testclient001");
//set any additional properties.
Producer<String, GenericRecord> producer = new KafkaProducer<String, GenericRecord>(props);
Upvotes: 9