The publish-to-dapr policy instructs API Management gateway to send a message to a Dapr Publish/Subscribe topic. The policy accomplishes that by making an HTTP POST request to http://localhost:3500/v1.0/publish/{{pubsub-name}}/{{topic}}, replacing template parameters and adding content specified in the policy statement.
The policy assumes that Dapr runtime is running in a sidecar container in the same pod as the gateway. Dapr runtime implements the Pub/Sub semantics. Learn more about Dapr integration with API Management.
The name of the target PubSub component. Maps to the pubsubname parameter in Dapr. If not present, the topic attribute value must be in the form of pubsub-name/topic-name. Policy expressions are allowed.
No
None
topic
The name of the topic. Maps to the topic parameter in Dapr. Policy expressions are allowed.
Yes
N/A
ignore-error
If set to true, instructs the policy not to trigger "on-error" section upon receiving error from Dapr runtime. Policy expressions aren't allowed.
No
false
response-variable-name
Name of the Variables collection entry to use for storing response from Dapr runtime. Policy expressions aren't allowed.
No
None
timeout
Time (in seconds) to wait for Dapr runtime to respond. Can range from 1 to 240 seconds. Policy expressions are allowed.
No
5
template
Templating engine to use for transforming the message content. "Liquid" is the only supported value.
No
None
content-type
Type of the message content. "application/json" is the only supported value.
Dapr support must be enabled in the self-hosted gateway.
Example
The following example demonstrates sending the body of the current request to the "new" topic of the "orders" Pub/Sub component. Response received from the Dapr runtime is stored in the "dapr-response" entry of the Variables collection in the context object.
If Dapr runtime can't locate the target topic, for example, and responds with an error, the "on-error" section is triggered. The response received from the Dapr runtime is returned to the caller verbatim. Otherwise, default 200 OK response is returned.
The "backend" section is empty and the request is not forwarded to the backend.