-
Notifications
You must be signed in to change notification settings - Fork 468
Description
Feature request
Description
Have a way to read the topic name from the message that just came into a middleware.
Example use case
I am currently trying to write a middleware for protobuf. We consume binary protobuf from a topic, want to read that into a struct in the middleware and run validations. If the validations fail, send to poison queue.
But to unmarshal the protobuf bytes into the correct struct, we need to know what the correct struct is.
The topic defines the structure of the message to be sent. But it's the topic name which I'd like to use to find the correct struct. Currently there is no way (or I don't know a way) to read the topic name in the middleware.
How it can look like in code
Currently doing something like this:
eventType, ok := msg.Metadata["event_message_schema"]
if !ok {
slog.Error("missing event_message_schema in metadata")
return nil, &UnprocessableEventError{
eventMessage: string(msg.Payload),
err: fmt.Errorf("missing event_message_schema in metadata"),
}
}But this means the metadata needs to be set on each message and I can't just use a topic name -> type mapping
topic := msg.TopicSomething like this would solve my issue