
124
|
第
3
章
息发送到端点
/v1.0/bindings/
,如
Dapr
示例仓库(
https://oreil.ly/mtinI
)
中的以下
Python
代码所示:
import time
import requests
import os
dapr_port = os.getenv("DAPR_HTTP_PORT", 3500)
dapr_url = "http://localhost:{}/v1.0/bindings/sample-topic".format(dapr_port)
n = 0
while True:
n += 1
payload = { "data": {"orderId": n}}
print(payload, flush=True)
try:
response = requests.post(dapr_url, json=payload)
print(response.text, flush=True)
except Exception as e:
print(e)
time.sleep(1)
3.3.3
实现输入绑定
输入绑定由
InputBinding
接口定义:
type InputBinding interface {
Init(metadata Metadata) error
Read(handler func(*ReadResponse) error) error
}
read
方法应该是一个阻塞方法,它应该在整个生命周期内阻塞并永不返回。 ...