2015-07-23 34 views
5

Ho scritto un produttore Kafka in NodeJS e Kafka Consumer in Java Maven. Il mio argomento è "test" che è stato creato con il seguente comando:BrokerNotAvailableError: Impossibile trovare il leader Eccezione durante lo Spark Streaming

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test 

Produttore in NodeJS:

var kafka = require('kafka-node'); 
var Producer = kafka.Producer; 
var Client = kafka.Client; 
var client = new Client('localhost:2181'); 
var producer = new Producer(client); 

producer.on('ready', function() { 
    producer.send([ 
     { topic: 'test', partition: 0, messages: ["This is the zero message I am sending from Kafka to Spark"], attributes: 0}, 
     { topic: 'test', partition: 1, messages: ["This is the first message I am sending from Kafka to Spark"], attributes: 0}, 
     { topic: 'test', partition: 2, messages: ["This is the second message I am sending from Kafka to Spark"], attributes: 0} 
     ], function (err, result) { 
     console.log(err || result); 
     process.exit(); 
    }); 
}); 

Quando invio due messaggi da NodeJS produttore, è consumato con successo da Java Consumer. Ma quando invio di tre o più messaggi da NodeJS produttore, mi dà errore seguente:

{[BrokerNotAvailableError: Impossibile trovare il leader] messaggio: 'Impossibile trovare il leader'}

voglio chiedere come posso impostare LEADER su qualsiasi messaggio in un argomento "test". O quale dovrebbe essere la soluzione per il problema.

+0

Per ottenere più affidabilità è possibile eseguire più numero di broker e abilitare la replica sull'argomento in modo che se il broker leader si arresta, altri broker follower assumono la posizione e si eseguirà meno nella situazione Leaders non disponibile. – anand

risposta

1

L'argomento è stato creato con 1 partizione, tuttavia al lato del produttore si sta tentando di inviare messaggi a 3 partizioni, logicamente Kafka non dovrebbe trovare il leader per le altre partizioni e dovrebbe lanciare questa eccezione.

0

Invece di partizioni utilizzare partizioni al plurale.

ad esempio:

producer.on('ready', function() { 
producer.send([ 
    { topic: 'test', partitions: 0, messages: ["This is the zero message I am sending from Kafka to Spark"], attributes: 0}, 
    { topic: 'test', partitions: 1, messages: ["This is the first message I am sending from Kafka to Spark"], attributes: 0}, 
    { topic: 'test', partitions: 2, messages: ["This is the second message I am sending from Kafka to Spark"], attributes: 0} 
    ], function (err, result) { 
    console.log(err || result); 
    process.exit(); 
}); 

});

1

C'è un bug che può causare questo nella versione corrente di kafka-node

https://github.com/SOHU-Co/kafka-node/issues/354

HighLevelProducer with KeyedPartitioner fails on first send #354 When using KeyedParitioner with the HighLevelProducer the first send fails with BrokerNotAvailableError: Could not find the leader Consecutive sends work perfectly.

anche vedere https://www.npmjs.com/package/kafka-node#highlevelproducer-with-keyedpartitioner-errors-on-first-send

che raccomanda

Call client.refreshMetadata() before sending the first message.

Questo è come mi Ho fatto quello

Problemi correlati