Trying to use Kafka in this way is a recipe for co...
# ktor
j
Trying to use Kafka in this way is a recipe for complex architecture. Your basic problem is that Kafka consumer is disconnected from any single HTTP transaction. In order to use Kafka this way you probably need to create an application local event bus. Easiest way to do this is to have a collection of "listeners" (local threadsafe queues most likely) that are waiting for an event/message to arrive from Kafka and when any message is received check if there are any listeners that can have the message delivered. This way in your Ktor handlers you can create a new queue/listener, add it to the collection and then await on a message being dequeued, you can then either send the message to the client via websocket or just normal blocking HTTP transaction.