FastStream brokers are very easy to integrate with any of your applications: it is enough to initialize the broker at startup and close it correctly at the end of your application.
Most HTTP frameworks have built-in lifecycle hooks for this.
Tip
If you want to use FastStream in conjunction with FastAPI, perhaps you should use a special plugin
importfalconimportfalcon.asgifromfaststream.kafkaimportKafkaBrokerbroker=KafkaBroker("localhost:9092")@broker.subscriber("test")asyncdefbase_handler(body):print(body)classThingsResource:asyncdefon_get(self,req,resp):resp.status=falcon.HTTP_200resp.content_type=falcon.MEDIA_TEXTresp.text=("\nTwo things awe me most, the starry sky ""above me and the moral law within me.\n""\n"" ~ Immanuel Kant\n\n")classStreamMiddleware:asyncdefprocess_startup(self,scope,event):awaitbroker.start()asyncdefprocess_shutdown(self,scope,event):awaitbroker.close()app=falcon.asgi.App()app.add_middleware(StreamMiddleware())app.add_route("/things",ThingsResource())