Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有多个后端的Azure API管理_Azure_Api_Frontend_Backend - Fatal编程技术网

具有多个后端的Azure API管理

具有多个后端的Azure API管理,azure,api,frontend,backend,Azure,Api,Frontend,Backend,我有一个Azure API管理集并正在运行。API调用是对Azure虚拟机上运行FastAPI的Docker容器进行的。这个后端容器负责根据它收到的查询运行一些AI模型。对于单个用户来说,这一切都很好 问题是:这些AI模型是在容器内的配置文件中定义的,并且是特定于用户的 我想使用Azure API管理来路由基于(比如)用户订阅的请求。换句话说,给定订阅,我想知道调用哪个后端(每个后端都是一个容器,在Azure虚拟机上为特定用户/公司运行特定的AI模型) 最好的方法是什么?我发现您可以使用入站策略

我有一个Azure API管理集并正在运行。API调用是对Azure虚拟机上运行FastAPI的Docker容器进行的。这个后端容器负责根据它收到的查询运行一些AI模型。对于单个用户来说,这一切都很好

问题是:这些AI模型是在容器内的配置文件中定义的,并且是特定于用户的

我想使用Azure API管理来路由基于(比如)用户订阅的请求。换句话说,给定订阅,我想知道调用哪个后端(每个后端都是一个容器,在Azure虚拟机上为特定用户/公司运行特定的AI模型)


最好的方法是什么?

我发现您可以使用入站策略根据用户所属的组指定要使用的后端。提到我的答案来了

转到API管理,选择组并创建与用户相关的组。然后将用户添加到各自的组中

转到您的API,选择入站规则,并使用以下内容指定后端:

<policies>
<inbound>
    <choose>
        <when condition="@(context.User.Groups.Select(g => g.Name).Contains("org1"))">
            <set-backend-service base-url="https://abc-apim.azure-api.net/org1app" />
        </when>
        <when condition="@(context.User.Groups.Select(g => g.Name).Contains("org2"))">
            <set-backend-service base-url="https://abc-apim.azure-api.net/org2app" />
        </when>
        <otherwise>
            <return-response>
                <set-status code="401" reason="Unauthorized" />
                <set-header name="WWW-Authenticate" exists-action="override">
                    <value>Bearer error="Invalid user group"</value>
                </set-header>
            </return-response>
        </otherwise>
    </choose>
    <base />
</inbound>
<backend>
    <base />
</backend>
<outbound>
    <base />
</outbound>
<on-error>
    <base />
</on-error>
</policies>

承载错误=“无效用户组”
我不理解这种方法不是很优雅,因为您必须在策略中硬编码后端路由。但它是有效的