Skip to content

Add FastStream example to docs#958

Open
birthdaysgift wants to merge 2 commits intoets-labs:developfrom
birthdaysgift:master
Open

Add FastStream example to docs#958
birthdaysgift wants to merge 2 commits intoets-labs:developfrom
birthdaysgift:master

Conversation

@birthdaysgift
Copy link
Copy Markdown

@birthdaysgift birthdaysgift commented Apr 17, 2026

Despite FastStream uses FastDepends under the hood the existing example for FastDepends from documentation doesn't work out of the box when used in FastStream handlers.

So I thought that having an explicit example of how to use dependency_injector with FastStream would be helpful for other devs seeking for a solution for such integration.

:description: This example demonstrates a usage of FastStream with Dependency Injector.


This example shows how to use ``Dependency Injector`` with `FastStream <https://dummy.faststream.airt.ai/0.5/faststream/>`_.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This example shows how to use ``Dependency Injector`` with `FastStream <https://dummy.faststream.airt.ai/0.5/faststream/>`_.
This example shows how to use ``Dependency Injector`` with `FastStream <https://github.com/ag2ai/faststream>`_.

Comment on lines +3 to +4
FastStream example
=============
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FastStream example
=============
FastStream example
==================

Comment on lines +21 to +24
counter = providers.Singleton(Counter)


broker = RedisBroker("redis://redis", logger=None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
counter = providers.Singleton(Counter)
broker = RedisBroker("redis://redis", logger=None)
config = providers.Configuration()
counter = providers.Singleton(Counter)
broker = providers.Resource(RedisBroker, config.redis_url, logger=None)
app = providers.Factory(FastStream, broker, logger=None)

If we're demonstrating integration, it would be better to go all-out.

Comment on lines +51 to +52

await FastStream(broker, logger=None).run()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment above

Suggested change
await FastStream(broker, logger=None).run()
app = await container.app()
await app.run()



def main():
client = redis.Redis(host="redis", port=6379)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No DI container?

Comment on lines +19 to +23
Ensure that ``run.sh`` has execution permission:

.. code-block:: bash

sudo chmod +x ./run.sh
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Ensure that ``run.sh`` has execution permission:
.. code-block:: bash
sudo chmod +x ./run.sh

You can chmod +x ./run.sh and commit it right away. Git keeps track of mode flags.

Comment on lines +9 to +19
consumer:
container_name: "${COMPOSE_PROJECT_NAME}-consumer"
build:
dockerfile: Dockerfile.consumer
depends_on:
- redis

producer:
container_name: "${COMPOSE_PROJECT_NAME}-producer"
build:
dockerfile: Dockerfile.producer
Copy link
Copy Markdown
Contributor

@ZipFile ZipFile Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
consumer:
container_name: "${COMPOSE_PROJECT_NAME}-consumer"
build:
dockerfile: Dockerfile.consumer
depends_on:
- redis
producer:
container_name: "${COMPOSE_PROJECT_NAME}-producer"
build:
dockerfile: Dockerfile.producer
consumer:
image: faststream-example
depends_on:
- redis
producer:
image: faststream-example

See comment about extra Dockerfile.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add reference to docs/examples/index.rst so it appears alongside other examples.

Comment on lines +8 to +15
docker container rm \
faststream-example-producer \
faststream-example-consumer \
faststream-example-redis

docker image rm \
faststream-example-producer \
faststream-example-consumer
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
docker container rm \
faststream-example-producer \
faststream-example-consumer \
faststream-example-redis
docker image rm \
faststream-example-producer \
faststream-example-consumer
docker compose down --rmi local

Though, I'm not sure if this is a desired behavior, since user might want to tinker with an example app for longer. Better include it in the documentation.

@@ -0,0 +1,15 @@
#!/usr/bin/env bash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set +x

@ZipFile ZipFile changed the base branch from master to develop April 18, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants