Pub/sub API reference
This endpoint lets you publish data to multiple consumers who are listening on a . Dapr guarantees at least once semantics for this endpoint.
HTTP 响应码
参数 | 说明 |
---|---|
daprPort | dapr 端口。 |
pubsubname | the name of pubsub component |
topic | the name of the topic |
metadata | query parameters for metadata as described below |
curl -X POST http://localhost:3500/v1.0/publish/pubsubName/deathStarStatus \
-H "Content-Type: application/json" \
-d '{
"status": "completed"
}'
Headers
The Content-Type
header tells Dapr which content type your data adheres to when constructing a CloudEvent envelope. The value of the Content-Type
header populates the datacontenttype
field in the CloudEvent. Unless specified, Dapr assumes text/plain
. If your content type is JSON, use a Content-Type
header with the value of .
If you want to send your own custom CloundEvent, use the application/cloudevents+json
value for the Content-Type
header.
元数据(Metadata)
Metadata can be sent via query parameters in the request’s URL. It must be prefixed with metadata.
as shown below.
Dapr will invoke the following endpoint on user code to discover topic subscriptions:
HTTP 请求
URL 参数
参数 | 说明 |
---|---|
appPort | 应用程序端口 |
HTTP Response body
A json encoded array of strings.
You can run Kafka locally using this Docker image. To run without Docker, see the getting started guide .
[
{
"topic": "newOrder",
"route": "/orders",
"metadata": {
"rawPayload": "true",
}
]
元数据(Metadata)
Optionally, metadata can be sent via the request body.
Provide route(s) for Dapr to deliver topic events
The following example illustrates this point, considering a subscription for topic newOrder
with route orders
on port 3000: POST http://localhost:3000/orders
HTTP 请求
URL 参数
参数 | 说明 |
---|---|
appPort | 应用程序端口 |
path | route path from the subscription configuration |
Expected HTTP Response
An HTTP 2xx response denotes successful processing of message. For richer response handling, a JSON encoded payload body with the processing status can be sent:
{
"status": "<status>"
}
Dapr assumes a JSON encoded payload response without status
field or an empty payload responses with HTTP 2xx, as .
The HTTP response might be different from HTTP 2xx, the following are Dapr’s behavior in different HTTP statuses:
HTTP Status | 说明 |
---|---|
2xx | message is processed as per status in payload (SUCCESS if empty; ignored if invalid payload). |
404 | error is logged and message is dropped |
other | warning is logged and message to be retried |