Pub/sub API reference

Detailed documentation on the pub/sub API

Publish a message to a given topic

This endpoint lets you publish data to multiple consumers who are listening on a topic. Dapr guarantees at least once semantics for this endpoint.

HTTP Request

  1. POST http://localhost:<daprPort>/v1.0/publish/<pubsubname>/<topic>

HTTP Response codes

CodeDescription
200Message delivered
500Delivery failed

URL Parameters

ParameterDescription
daprPortthe Dapr port
pubsubnamethe name of pubsub component.
topicthe name of the topic

Note, all URL parameters are case-sensitive.

  1. curl -X POST http://localhost:3500/v1.0/publish/pubsubName/deathStarStatus \
  2. -H "Content-Type: application/json" \
  3. -d '{
  4. "status": "completed"
  5. }'

Optional Application (User Code) Routes

Provide a route for Dapr to discover topic subscriptions

Dapr will invoke the following endpoint on user code to discover topic subscriptions:

HTTP Request

  1. GET http://localhost:<appPort>/dapr/subscribe

URL Parameters

ParameterDescription
appPortthe application port

HTTP Response body

A json encoded array of strings.

Example:

  1. [
  2. {
  3. "pubsubname": "pubsub",
  4. "topic": "newOrder",
  5. "route": "/orders"
  6. }
  7. ]

Note, all subscription parameters are case-sensitive.

Provide route(s) for Dapr to deliver topic events

In order to deliver topic events, a POST call will be made to user code with the route specified in the subscription response.

The following example illustrates this point, considering a subscription for topic newOrder with route orders on port 3000: POST http://localhost:3000/orders

HTTP Request

  1. POST http://localhost:<appPort>/<path>

Note, all URL parameters are case-sensitive.

URL Parameters

ParameterDescription
appPortthe application port
pathroute path from the subscription configuration

Expected HTTP Response

An HTTP 200 response with JSON encoded payload body with the processing status:

  1. {
  2. "status": "<status>"
  3. }
StatusDescription
SUCCESSmessage is processed successfully
RETRYmessage to be retried by Dapr
DROPwarning is logged and message is dropped

For empty payload responses in HTTP 2xx, Dapr assumes SUCCESS.

The HTTP response might be different from HTTP 2xx, the following are Dapr’s behavior in different HTTP statuses:

HTTP StatusDescription
2xxmessage is processed as per status in payload (SUCCESS if empty; ignored if invalid payload).
404error is logged and message is dropped
otherwarning is logged and message to be retried

Message envelope

Dapr Pub/Sub adheres to version 1.0 of Cloud Events.

Related links

Last modified February 16, 2021: Merge pull request #1235 from dapr/update-v0.11 (b4e9fbb)