Slide 12
Slide 12 text
Outside HTTP : Message queue consumers
→ Create middlewares to get/add the Request ID from/to the context.
func (c *Consumer) Start(ctx context.Context) func() {
c.logger = logctx.Get(ctx).WithFields(logrus.Fields{
"topic": c.Topic,
"channel": c.Channel,
})
for message := range c.in {
msgLogger := c.logger.WithFields(logrus.Fields{
"message_id": fmt.Sprintf("%s", message.ID),
"message_type": msg.Type,
"request_id": msg.RequestID,
})
ctx := context.WithValue(
context.WithValue(
context.Background(), "request_id", msg.RequestID,
), "logger", msgLogger,
)
// ... c.Handler(ctx, msg.Type, msg.Payload)
}
}