What I have.
A FastAPI app which consists of two sub apps and are mounted and specific paths. One of them is a websocket app. A single node Kafka cluster with two topics. One to which the websocket app writes and other from which the websocket app reads. A react application that uses socket.io client to make connection to the FastAPI app. Specifically the websocket sub app.
What I am trying to achieve
I am able to write to the Kafka topic from the websocket sub app as it is straightforward. Every user that connects to the app is given a socket it. I am mapping every socket id to the user identifier and storing it for later use. After the producer produces the message there is some other processing that is done on the data by another app and then it writes to a topic from which I have to read the messages. Basically a consumer. In the message I have a user identifier using which I can detect the socket id.
Now, I am unsure as to how to and when to start my consumer with respect to a FastAPI application. Does it need to be a standalone module? If yes, how do I send back the response to the original websocket client. [I have socket id stored.]