【问题标题】:How Do I Configure API Management With Multiple Back Ends?如何配置具有多个后端的 API 管理?
【发布时间】:2019-06-05 20:03:44
【问题描述】:

我正在为客户托管一项服务,我们在 Azure 中为每个客户部署了相同的应用程序。

基本上每个客户都是这样:

Application Gateway ->
App Service Environment ->
API Management ->
VM with Application back end ->
Remote Azure SQl Data

前 3 层显着增加了成本。

可以这样配置吗?

Application Gateway ->
App Service Environment ->
API Management ->
    - Client 1 
        VM1 with Application back end ->
        Remote Azure SQl Data1
    - Client 2 
        VM2 with Application back end ->
        Remote Azure SQl Data2
    - Client 3 
        VM3 with Application back end ->
        Remote Azure SQl Data3

即Web 层路由到适当的后端不知何故

例如也许每个客户端都会使用不同的 URL 访问 Web 层。

http://client1.rest-application.azure.com

http://client2.rest-application.azure.com

但它们都通过同一个应用程序网关。

【问题讨论】:

    标签: azure azure-api-management azure-application-gateway


    【解决方案1】:

    您需要使用 APIM 策略根据 HTTP 标头信息将流量路由到不同的后端池。

    这是根据请求正文大小路由流量的示例策略。

    此文件中定义的策略演示了如何根据消息正文的大小路由请求。 Content-Length 标头包含消息正文的大小。 256 KB,Azure 服务总线中的消息大小限制。 他 sn-p 检查消息是否小于 256000 字节。如果它更大,请求被路由到其他地方。 将以下 sn-p 复制到入站部分。

    <policies>
    <inbound>
        <base/>
            <set-variable name="bodySize" value="@(context.Request.Headers["Content-Length"][0])"/>
            <choose>
                <when condition="@(int.Parse(context.Variables.GetValueOrDefault<string>("bodySize"))<256000)">
                    <!-- let it pass through by doing nothing -->
                </when>
                <otherwise>
                    <rewrite-uri template="{{alternate-path-and-query}}"/>
                    <set-backend-service base-url="{{alternate-host}}"/>
                </otherwise>
            </choose>
    
            <!-- In rare cases where Content-Length header is not present we'll have to read the body to get its length. -->
            <!--
            <choose>
                <when condition="@(context.Request.Body.As<string>(preserveContent: true).Length<256000)">
    
                </when>
                <otherwise>
                    <rewrite-uri template=""/>
                    <set-backend-service base-url=""/>
                </otherwise>
            </choose>
            -->
    </inbound>
    <backend>
        <base/>
    </backend>
    <outbound>
        <base/>
    </outbound>
    <on-error>
        <base/>
    </on-error>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-09
      • 1970-01-01
      • 2018-08-01
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多