แก้ไข

แชร์ผ่าน


Send request to a service

APPLIES TO: Developer | Premium

The set-backend-service policy sets the target URL for the current request to http://localhost:3500/v1.0/invoke/{app-id}[.{ns-name}]/method/{method-name}, replacing template parameters with values specified in the policy statement.

The policy assumes that Dapr runs in a sidecar container in the same pod as the gateway. Upon receiving the request, Dapr runtime performs service discovery and actual invocation, including possible protocol translation between HTTP and gRPC, retries, distributed tracing, and error handling. Learn more about Dapr integration with API Management.

Note

Set the policy's elements and child elements in the order provided in the policy statement. Learn more about how to set or edit API Management policies.

Policy statement

<set-backend-service backend-id="dapr" dapr-app-id="app-id" dapr-method="method-name" dapr-namespace="ns-name" />

Attributes

Attribute Description Required Default
backend-id Must be set to "dapr". Yes N/A
dapr-app-id Name of the target microservice. Used to form the appId parameter in Dapr. Policy expressions are allowed. Yes N/A
dapr-method Name of the method or a URL to invoke on the target microservice. Maps to the method-name parameter in Dapr. Policy expressions are allowed. Yes N/A
dapr-namespace Name of the namespace the target microservice is residing in. Used to form the appId parameter in Dapr. Policy expressions are allowed. No N/A

Usage

Usage notes

Dapr support must be enabled in the self-hosted gateway.

Example

The following example demonstrates invoking the method named "back" on the microservice called "echo". The set-backend-service policy sets the destination URL to http://localhost:3500/v1.0/invoke/echo.echo-app/method/back. The forward-request policy dispatches the request to the Dapr runtime, which delivers it to the microservice.

The forward-request policy is shown here for clarity. The policy is typically "inherited" from the global scope via the base keyword.

<policies>
    <inbound>
        <base />
        <set-backend-service backend-id="dapr" dapr-app-id="echo" dapr-method="back" dapr-namespace="echo-app" />
    </inbound>
    <backend>
        <forward-request />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

For more information about working with policies, see: