Skip to content

[microservices] KafkaRequestSerializer not serializing a object with attribute name "value" #12886

Closed
@sprijk

Description

@sprijk

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

When using the Kafka client the default serializer (KafkaRequestSerializer) checks if a message is not a Kafka(JS) message using:

const isNotKafkaMessage =
    isNil(value) ||
    !isObject(value) ||
    (!('key' in value) && !('value' in value));

when using the Kafka Client and sending/emitting an object with a measurement like:
{ time: 1, value: 12 }
the boolean isNotKafkaMessage becomes false, thinking the message is a typical KafkaJS message with key and value attributes.
Of course, the intention is to treat this message as a JSON object that in the end needs to be serialized using JSON.stringify()

Describe the solution you'd like

in my opinion the check should be changed to:

!(('key' in value) && ('value' in value))

to check both key and value attribute names existence in the object...

Teachability, documentation, adoption, migration strategy

I think the docs on the Kafka Client should be updated with the notion you should not use the attributes names value or key in the messages you want to send/emit.
Possibly an explainer on how to use your own Serializer and attach that to the KafkaClient

What is the motivation / use case for changing the behavior?

To not have to particularly exclude used keyword value or key but only treat the message as a Kafka message if they both exist.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions