You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, i'm new from golang and fiber. I want to implement a system that: Client sends http request to service A. Service A communicates with service B through kafka. Then service A takes the response from kafka then matches with the request id from client and responses back to client. The normal approach of service A would be:
func main() {
app := fiber.New()
// An example to describe the question
app.Post("/", func(c *fiber.Ct) error {
var req share.SaferRequest
if err := c.BodyParser(&req); err != nil {
return c.Status(400).SendString(err.Error())
} else {
ProduceToKafka(req)
res := ConsumeFromKafka(req.ID)
resBytes, _ := json.Marshal(res)
c.Status(200).Send(resBytes)
}
})
log.Fatal(app.Listen(":3000"))
}
Where we can see that we have to wait for the message to consume from Kafka.
Now my question is: Does fiber support passing the context through other goroutines so that i can use the context corresponding to the request.ID to response to the client. Draft code of my idea:
var m map[string]*fiber.Ctx
func() ConsumeFromKafka() {
for {
res := kafka.Consume()
c := m[res.ID]
g.Status(200).JSON(res)
}
}
func main() {
app := fiber.New()
// An example to describe the question
app.Post("/", func(c *fiber.Ct) error {
var req share.SaferRequest
if err := c.BodyParser(&req); err != nil {
return c.Status(400).SendString(err.Error())
} else {
m[req.ID] = c
ProduceToKafka(req)
}
})
log.Fatal(app.Listen(":3000"))
go ConsumeFromKafka()
forever chan bool
<- forever
}
On the about implementation, the connection must be kept alive during the process produce and consume message from kafka. The connection only shutdown when i response a message back to client. My teammate successfully implemented this idea using vertx using eventbus and RoutingContext so i guess there are some mechanics to work around that. Feel free to discuss.
Thank you for reading my question.
The text was updated successfully, but these errors were encountered:
Thanks for opening your first issue here! 馃帀 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
Question Description
Hi, i'm new from golang and fiber. I want to implement a system that: Client sends http request to service A. Service A communicates with service B through kafka. Then service A takes the response from kafka then matches with the request id from client and responses back to client. The normal approach of service A would be:
Where we can see that we have to wait for the message to consume from Kafka.
Now my question is: Does fiber support passing the context through other goroutines so that i can use the context corresponding to the request.ID to response to the client. Draft code of my idea:
On the about implementation, the connection must be kept alive during the process produce and consume message from kafka. The connection only shutdown when i response a message back to client. My teammate successfully implemented this idea using vertx using eventbus and RoutingContext so i guess there are some mechanics to work around that. Feel free to discuss.
Thank you for reading my question.
The text was updated successfully, but these errors were encountered: