Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Only getting last result back from HighLevelProducer #775

Open
darkbasco opened this issue Oct 6, 2017 · 0 comments
Open

Only getting last result back from HighLevelProducer #775

darkbasco opened this issue Oct 6, 2017 · 0 comments

Comments

@darkbasco
Copy link

darkbasco commented Oct 6, 2017

I am sending multiple messages to a single Kafka topic. The messages seem to send ok and I get back a result like {"0": 10268823} where the value reflects the addition of all of my messages, but I expected an array of results, one for each message, not just the last one. Am I doing something wrong, or not understanding why I don't need what I think I need?

Thanks,
Bill

const kafkaTopic = process.env.KAFKA_TOPIC
const kafkaBrokers = process.env.KAFKA_BROKERS.trim()

	const HighLevelProducer = kafka.HighLevelProducer
	const client = new kafka.KafkaClient({
		kafkaHost: kafkaBrokers,
		connectTimeout: 10000,
		requestTimeout: 30000,
		autoConnect: true,
		//connectRetryOptions: ,
		idleConnection: 300000,
		maxAsyncRequests: 10
	})
	const producer = new HighLevelProducer(client)
	const payloads = [{ topic: kafkaTopic, messages: messages }]

	client.on("ready", function() {
		console.log("client ready")
	})

	client.on("error", function(err) {
		console.log("client error: " + err)
		reject(err)
	})

	producer.on("ready", function() {
		producer.send(payloads, function(err, data) {
			if (err) {
				reject(err)
			} else {
				resolve(data)
			}
		})
	})

	producer.on("error", function(err) {
		console.log("error: " + err)
		reject(err)
	})
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant