You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently working on a project where I need to serialize and send messages to Confluent Kafka using the Confluent Schema Registry and AVRO. The challenge I'm facing is that the messages have an unknown structure, and I only have the schema ID and topic.
I've tried using interface{} and map[string]interface{} but ser.Serialize(topic, &record) fails and I'm unable to serialize the message. One of the errors I'm getting is unknown type interface.
Detailed Scenario
I have a log file with JSON records that contain the schema ID, topic, and a JSON message to be sent to Confluent Kafka. The JSON message is arbitrary, and I don't know its structure in advance. Here's the structure when reading the records:
This throws an unknown type interface error when using Msg map[string]interface{} or interface{}.
Alternative Attempt
As an alternative, I tried using github.com/hamba/avro/v2 to serialize the Msg with the schema retrieved from schemaRegistryClient.GetBySubjectAndID, but it didn't work either:
I have the same requirement. I found that using map[string]interface{} will break an assumption of the library. ie. It only supports struct.
Reasons:
struct is required in order to convert to a schema. On the other hand, map Type cannot be converted to schema.
This local schema will be used by SubjectNameStrategy. It may not be necessary for default implementation which takes the topic name as the subject. If your app has to support multiple schemas for the same topic, you may need a different strategy which extracts the record name from the schema.
This local schema is required to register schema if AutoRegisterSchemas is true.
This local schema is required for lookup if latest schema is not preferred.
It would be nice if this library can support map[string]interface{}, even at the expense of losing some of the features.
Description
I'm currently working on a project where I need to serialize and send messages to Confluent Kafka using the Confluent Schema Registry and AVRO. The challenge I'm facing is that the messages have an unknown structure, and I only have the schema ID and topic.
I've tried using
interface{}
andmap[string]interface{}
butser.Serialize(topic, &record)
fails and I'm unable to serialize the message. One of the errors I'm getting isunknown type interface
.Detailed Scenario
I have a log file with JSON records that contain the schema ID, topic, and a JSON message to be sent to Confluent Kafka. The JSON message is arbitrary, and I don't know its structure in advance. Here's the structure when reading the records:
The Issue
I'm unable to serialize the
Msg
without knowing its structure. Here is the code I'm using:This throws an
unknown type interface
error when usingMsg map[string]interface{}
orinterface{}
.Alternative Attempt
As an alternative, I tried using
github.com/hamba/avro/v2
to serialize theMsg
with the schema retrieved fromschemaRegistryClient.GetBySubjectAndID
, but it didn't work either:This throws a
float64 is unsupported for Avro int
error for Msg with just anint
value.Question
How can I accomplish serializing an arbitrary JSON message using AVRO and the schema registry? Any help or guidance would be greatly appreciated.
Thanks!
How to reproduce
See code above. I'm happy to share the full code if needed.
Checklist
Please provide the following information:
LibraryVersion()
):2.5.0
ConfigMap{...}
"debug": ".."
as necessary)The text was updated successfully, but these errors were encountered: