Skip to content

Commit

Permalink
Add application.py for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranvpl committed Sep 15, 2023
1 parent 7590553 commit 8687199
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pydantic import BaseModel, Field

from faststream import FastStream, Logger
from faststream.kafka import KafkaBroker


class MultiplyMessage(BaseModel):
a: int = Field(..., examples=[2], description="Integer value")
b: int = Field(..., examples=[3], description="Integer value")


class Results(BaseModel):
res: int = Field(..., examples=[6], description="Result of multiplication")


broker = KafkaBroker("localhost:9092")
app = FastStream(broker)


@broker.subscriber("multiply")
@broker.publisher("results")
async def multiply_numbers(msg: MultiplyMessage, logger: Logger) -> Results:
logger.info(msg)

result = msg.a * msg.b
result_obj = Results(res=result)
return result_obj

0 comments on commit 8687199

Please sign in to comment.