Getting started with the Dapr Python gRPC service extension
The Dapr Python SDK provides a built in gRPC server extension module, , for creating Dapr services.
You can download and install the Dapr gRPC server extension module with:
Note
开发包包含的功能和行为将兼容此前发行的 Dapr 运行时。 在安装 dapr-dev 包之前,请务必卸载以前任意稳定版本的 dapr-ext-fastapi 的 Python SDK 扩展包。
The InvokeServiceReqest
and InvokeServiceResponse
objects can be used to handle incoming requests.
A simple service that will listen and respond to requests will look like:
app = App()
@app.method(name='my-method')
def mymethod(request: InvokeServiceRequest) -> InvokeServiceResponse:
print(request.metadata, flush=True)
print(request.text(), flush=True)
return InvokeServiceResponse(b'INVOKE_RECEIVED', "text/plain; charset=UTF-8")
A full sample can be found here.
from dapr.ext.grpc import App, BindingRequest
app = App()
@app.binding('kafkaBinding')
def binding(request: BindingRequest):
print(request.text(), flush=True)
app.run(50051)
A full sample can be found .