confluentinc / confluentinc/confluent-kafka-javascript
ProtobufSerializer Error: message type name is empty
- Dominant language
- TypeScript
- Stars
- 304
- Forks
- 45
- Avg merge
- 11h 47m
- Merged PRs (30d)
- 5
Description
**Description**
When attempting to serialize messages using the `ProtobufSerializer` an error is always thrown.
**Environment Information**
- OS Mac M1 Sonoma 14.6.1
- Node Version 20.18.1
- NPM Version 10.8.2:
- confluent-kafka-javascript version 1.0.0:
**Steps to Reproduce**
Execute the below code and it will throw the following error:
```
Error: message type name is empty
at ProtobufSerializer.serialize (/Users/christopher.baumann@konghq.com/Develop/other/confluent-kafka-javascript/schemaregistry/serde/protobuf.ts:146:13)
at Object. (/Users/christopher.baumann@konghq.com/Develop/other/confluent-kafka-javascript/schemaregistry/e2e/schemaregistry-proto.spec.ts:84:31)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
```
Code to reproduce: a test example has been created in https://github.com/confluentinc/confluent-kafka-javascript/pull/218#issue-2745223459
```
const schemaString: string = "\n" +
"syntax = \"proto3\";\n" +
"message TestMessageValue {\n" +
" string name = 1;\n" +
" int32 age = 2;\n" +
"\n" +
"}\n";
const messageValue = {
"name": "Bob Jones",
"age": 25
};
const schemaInfo: SchemaInfo = {
schema: schemaString,
schemaType: 'PROTOBUF'
};
const testTopic = "test";
const schemaRegistryClient = new SchemaRegistryClient(clientConfig);
await schemaRegistryClient.register(testTopic + "-value", schemaInfo);
serializerConfig = { useLatestVersion: true };
serializer = new ProtobufSerializer(schemaRegistryClient, SerdeType.VALUE, serializerConfig);
deserializer = new ProtobufDeserializer(schemaRegistryClient, SerdeType.VALUE, {});
const outgoingMessage = {
key: 'key',
value: await serializer.serialize(testTopic, messageValue)
};
```
**Additional context**
When trying to serialize a message using the ProtoSerializer an error is thrown. The expected behavior is that the serialize should be able to successfully serialize messages.
Note: If the above code is changed to include the `$typeName` then the error changes to the following:
```
Error: message descriptor not in registry
at ProtobufSerializer.serialize (/Users/christopher.baumann@konghq.com/Develop/other/confluent-kafka-javascript/schemaregistry/serde/protobuf.ts:150:13)
at Object. (/Users/christopher.baumann@konghq.com/Develop/other/confluent-kafka-javascript/schemaregistry/e2e/schemaregistry-proto.spec.ts:84:31)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
```
Code to reproduce:
```
const outgoingMessage = {
key: 'key',
value: await serializer.serialize(testTopic, { ...messageValue, $typeName: "TestMessageValue"})
};
```
Contributor guide
Assessment
This issue has not been assessed yet.