Skip to content

Latest commit

 

History

History
76 lines (55 loc) · 3.87 KB

File metadata and controls

76 lines (55 loc) · 3.87 KB
title Azure API Management policy reference - set-backend-service (Dapr) | Microsoft Docs
description Reference for the set-backend-service policy available for use in Dapr integration with Azure API Management. Provides policy usage, settings, and examples.
services api-management
author dlepow
ms.service azure-api-management
ms.topic reference
ms.date 03/18/2024
ms.author danlep

Send request to a service

[!INCLUDE api-management-availability-premium-dev]

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.

[!INCLUDE api-management-policy-generic-alert]

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>

Related policies

[!INCLUDE api-management-policy-ref-next-steps]