Skip to content

Allow Middleware to know which handler will process or which topic the message came from #625

@DrBlury

Description

@DrBlury

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.Topic

Something like this would solve my issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions