這裏是我的卡夫卡消息生產者:僅消耗特定partion消息
ProducerRecord producerRecord = new ProducerRecord(topic, "k1", message);
producer.send(producerRecord);
這裏是我的消費者
TopicPartition partition0 = new TopicPartition(topic, 0);
consumer.assign(Arrays.asList(partition0));
final int minBatchSize = 200;
List<ConsumerRecord<String, byte[]>> buffer = new ArrayList<>();
while (true) {
ConsumerRecords<String, byte[]> records = consumer.poll(100);
for (ConsumerRecord<String, byte[]> record : records) {
buffer.add(record);
System.out.println(record.key() + "KEY: " + record.value());
怎麼可能消耗爲作爲分區鍵只topic
消息
用「partition key'k1'」我猜你實際上是指「message key'k1'」。卡夫卡確實爲您選擇了鑰匙。在使用分區時,必須使用該分區的每條消息。無論你做什麼或只是放棄它,如果它沒有正確的鑰匙取決於你。 – Harald
你是說在接收郵件的同時我應該做'if(msg.key()。equals(「k1」)' – manish
是的,那就是要走的路。 – Harald