mirror of https://github.com/dapr/quickstarts.git
Update Python pub_sub fastapi example (#635)
Signed-off-by: Michał Klich <michal@klichx.dev>
This commit is contained in:
parent
3aea5f8ed5
commit
57fc9655cb
|
@ -41,9 +41,8 @@ background: true
|
|||
sleep: 10
|
||||
-->
|
||||
|
||||
|
||||
```bash
|
||||
dapr run --app-id order-processor --components-path ../../../components/ --app-port 5001 -- python3 app.py
|
||||
dapr run --app-id order-processor --components-path ../../../components/ --app-port 5001 -- uvicorn app:app --port 5001
|
||||
```
|
||||
|
||||
<!-- END_STEP -->
|
||||
|
@ -76,7 +75,7 @@ working_dir: ./checkout
|
|||
background: true
|
||||
sleep: 10
|
||||
-->
|
||||
|
||||
|
||||
```bash
|
||||
dapr run --app-id checkout --components-path ../../../components/ -- python3 app.py
|
||||
```
|
||||
|
|
|
@ -1,12 +1,26 @@
|
|||
from fastapi import FastAPI
|
||||
# from cloudevents.http import from_http
|
||||
from dapr.ext.fastapi import DaprApp
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
dapr_app = DaprApp(app)
|
||||
|
||||
|
||||
class CloudEvent(BaseModel):
|
||||
datacontenttype: str
|
||||
source: str
|
||||
topic: str
|
||||
pubsubname: str
|
||||
data: dict
|
||||
id: str
|
||||
specversion: str
|
||||
tracestate: str
|
||||
type: str
|
||||
traceid: str
|
||||
|
||||
|
||||
# Dapr subscription routes orders topic to this route
|
||||
@dapr_app.subscribe(pubsub='orderpubsub', topic='orders')
|
||||
def orders_subscriber(detail):
|
||||
print('got here')
|
||||
def orders_subscriber(event: CloudEvent):
|
||||
print('Subscriber received : %s' % event.data['orderId'], flush=True)
|
||||
return {'success': True}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
fastapi
|
||||
dapr-ext-fastapi==1.5.0
|
||||
cloudevents
|
||||
uvicorn
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
Flask
|
||||
dapr
|
||||
cloudevents
|
||||
uvicorn
|
||||
|
|
Loading…
Reference in New Issue