Sarrafa Dorewa
Saita Kwafi da Rarraba a cikin Kafka: Lokacin ƙirƙirar topic, zaku iya ƙirƙira adadin ɓangarori na wancan topic tare da replication factor. Lambar replication factor ita ce adadin kwafi ga kowane partition, yana ƙayyade adadin dillalai waɗanda kowane saƙo za a maimaita su.
Misali: Bari mu ce kuna da orders
topic partitions 3 da replication factor na 2. Wannan yana nufin kowane saƙo za a maimaita shi zuwa dillalai 2 daban-daban. Idan mutum broker ya sami gazawa, har yanzu kuna iya samun damar saƙonnin daga sauran broker.
Tabbatar da daidaito
Hanyar Yardawa lokacin Aika da Karɓar Saƙonni: A cikin Apache Kafka, zaku iya amfani da tsarin amincewa lokacin aikawa da karɓar saƙonni don tabbatar da daidaito da dorewa. Wannan tsarin yana tabbatar da cewa an aiko da saƙonni cikin nasara ko kuma yarda da su kafin ci gaba da ƙarin ayyuka.
Misali: Lokacin aika saƙonni, zaku iya amfani da acks
zaɓi don ƙayyadadden tsarin yarda. Misali, acks: 1
yana tabbatar da cewa an aika da sakon cikin nasara ga broker jagoran partition. Ta hanyar jiran sanarwa, za ku san lokacin da aka adana saƙo a cikin aminci kafin ci gaba da wasu ayyuka.
const { Kafka } = require('kafkajs');
const kafka = new Kafka({
clientId: 'your-client-id',
brokers: ['broker1:port1', 'broker2:port2'],
});
const producer = kafka.producer();
const sendMessages = async() => {
await producer.connect();
await producer.send({
topic: 'your-topic',
messages: [{ value: 'Hello Kafka!' }],
acks: 1, // Acknowledge after the message is successfully sent
});
await producer.disconnect();
};
sendMessages();
Lura:
- Tabbatar maye gurbin
'your-client-id'
,'broker1:port1'
,'your-topic'
, da sauran dabi'u tare da ainihin bayanin aikin ku. - Zaɓuɓɓukan daidaitawa da hanyoyin yarda na iya bambanta dangane da takamaiman buƙatun aikin.
Ta hanyar daidaita rarrabuwa, kwafi, ta amfani da hanyoyin yarda, da zaɓuɓɓukan maimaitawa, zaku iya sarrafa Dorewa da Tabbatar da daidaito yayin Apache Kafka amfani da Node.js.