Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

504
Views
Ejecuté mi código y obtuve este error: TypeError: eventType.toBuffer no es una función

Cuando traté de ejecutar el siguiente código en Visual Studio, recibí el siguiente error:

TypeError: eventType.toBuffer no es una función en queueRandomMessage

Código:

 const Kafka = require('node-rdkafka'); const eventType = require('../eventType.js'); const stream = Kafka.Producer.createWriteStream({ 'metadata.broker.list': 'localhost:9092' }, {}, { topic: 'test' }); stream.on('error', (err) => { console.error('Error in our kafka stream'); console.error(err); }); function queueRandomMessage() { const category = getRandomAnimal(); const noise = getRandomNoise(category); const event = { category, noise }; const success = stream.write(eventType.toBuffer(event)); if (success) { console.log(`message queued (${JSON.stringify(event)})`); } else { console.log('Too many messages in the queue already..'); } } function getRandomAnimal() { const categories = ['CAT', 'DOG']; return categories[Math.floor(Math.random() * categories.length)]; } function getRandomNoise(animal) { if (animal === 'CAT') { const noises = ['meow', 'purr']; return noises[Math.floor(Math.random() * noises.length)]; } else if (animal === 'DOG') { const noises = ['bark', 'woof']; return noises[Math.floor(Math.random() * noises.length)]; } else { return 'silence..'; } } setInterval(() => { queueRandomMessage(); }, 3000);

Este es el código para eventType.js que usé:

 const avro = require('avsc'); module.export = avro.Type.forSchema({ type: 'record', fields: [ { name: 'category', type: { type: 'enum', symbols: ['DOG', 'CAT'] } }, { name: 'noise', type: 'string', } ] });

¿Qué debo hacer para corregir este error?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debería ser module.exports

 const avro = require('avsc'); module.exports = avro.Type.forSchema({ type: 'record', fields: [ { name: 'category', type: { type: 'enum', symbols: ['DOG', 'CAT'] } }, { name: 'noise', type: 'string', } ] });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!