Skip to content

Latest commit

 

History

History
42 lines (25 loc) · 1.58 KB

File metadata and controls

42 lines (25 loc) · 1.58 KB

FastStream example

This example shows how to use Dependency Injector with FastStream.

The source code is available on the Github.

Despite FastStream uses FastDepends library for dependency injection, the integration between Dependency injector and FastStream has a small difference from already existing :ref:`fastdepends` example.

Since FastStream also leverages function signatures to determine input data types you have to use Depends() function with cast=False argument to make FastStream ignore your injected dependency argument in the function signature.

Example below shows how to inject Counter class into FastStream redis handler so that it will distinguish between message schema (User) and injected dependency (Counter) and use them both correctly.

Listing of consumer.py:

.. literalinclude:: ../../examples/miniapps/faststream/src/consumer.py
   :language: python

Listing of producer.py:

.. literalinclude:: ../../examples/miniapps/faststream/src/producer.py
   :language: python

Sources

Explore the sources on the Github.

.. disqus::