When I try to emit a Kafka event with the Kafka node in n8n, I get the following error when giving a Buffer object as the message:
ERROR: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Object
Workflow
myProto = MyProtoClass.create({prop1: '1', prop2: '2'})
o = Buffer.from(myProto, encoding='utf8')
Emission works if I apply o.toString() but then event processing fails with an IndexError (which I got locally when I tried to save with toString() but resolved if saving the Buffer object to a binary file directly).
Any suggestions as to what I should change would be most appreciated!
n8n setup
n8n version: 0.164.1
Running n8n with the execution process [own(default), main]: own
Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker
The error says you are passing an object and it is expecting a string, you would need to make your object a string or a buffer instance like the typescript / JavaScript error message is suggesting.
I may be missing more of this but the error is still clear, what you are passing is not being seen as the correct data type so while it looks like it should be a buffer it is actually an object when you use it.
I don’t have your protoclass so testing isn’t possible but at the moment I don’t think this is an error with n8n.
@Jon Do you think you could point me to which kafka library and function is used to produce the event, so maybe I can check how the “message” argument is being used?
Sadly I don’t have any example workflows that use a buffer with Kafka but as a test maybe you could try an http request node and have it download some binary data from somewhere and use that as the input for Kafka and see if it works.
I think this is either a bug or a feature request, i.e. allow for Buffer messages, not only string (which also implies not casting it to string). I don’t actually have enough knowledge to understand all the edge cases and make a proposal MR.