Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next iteration of pub/sub quickstarts (python, dotnet) #7

Merged
merged 11 commits into from
Feb 5, 2022

Conversation

paulyuk
Copy link
Contributor

@paulyuk paulyuk commented Jan 31, 2022

This addresses a few challenges with the current quickstart both around functionality and style:

Python

  • example: checkout service is now the publisher, and order-processor is now the subscriber. this matches common examples, e.g. https://docs.microsoft.com/en-us/azure/architecture/example-scenario/data/ecommerce-order-processing
  • function: use HTTP routes in subscriber, in case app protocol not set to gRPC. I like the decorator example but we need a bigger change for that.
  • function: send a python -> json object for orders instead of raw int for orderid, which will break json.dumps parsing downstream. now it looks like order = {"orderid": random.randint(1, 1000)}
  • function: reduced use of random and simplified sleep
  • style:
  • created a folder for each service
  • changed all files to lowercase
  • changed main running file name to app.py
  • updated requirements.txt with matching pip install dependencies, namely dapr and Flask
  • checked with Flake8 linter

Dotnet (C#)

@paulyuk paulyuk changed the title Next iteration of python pub/sub Next iteration of pub/sub quickstarts (python, dotnet) Jan 31, 2022
@greenie-msft
Copy link
Collaborator

greenie-msft commented Jan 31, 2022

PubSub Subscribe was recently added to Flask Dapr: dapr/python-sdk#351.

My suggestion is to publish this update and use it as it simplifies the amount of code developers need to write:

from flask import Flask, request
from flask_dapr import DaprApp
app = Flask('myapp')
dapr_app = DaprApp(app)

@dapr_app.subscribe(pubsub='pubsub', topic='some_topic', route='/some_endpoint')
def my_event_handler():
  # request.data contains pubsub event
  pass

@paulyuk paulyuk marked this pull request as draft February 1, 2022 18:05
@paulyuk
Copy link
Contributor Author

paulyuk commented Feb 1, 2022

PubSub Subscribe was recently added to Flask Dapr: dapr/python-sdk#351.

My suggestion is to publish this update and use it as it simplifies the amount of code developers need to write:

from flask import Flask, request
from flask_dapr import DaprApp
app = Flask('myapp')
dapr_app = DaprApp(app)

@dapr_app.subscribe(pubsub='pubsub', topic='some_topic', route='/some_endpoint')
def my_event_handler():
  # request.data contains pubsub event
  pass

Agreed. Nice! It's in. You just have to pip install the 1.5 sdk version but the requirements.txt now does this.

@amulyavarote
Copy link
Owner

We might have to change the variables and method names later on to keep it consistent across all the programming languages. I am currently working on the spec/template to be followed in the coding/design. We might make few changes according to it.

Now the PR looks good to me :-)

@paulyuk paulyuk marked this pull request as ready for review February 4, 2022 17:33
@greenie-msft greenie-msft merged commit 84b3c60 into amulyavarote:master Feb 5, 2022
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.

4 participants