繁体   English   中英

如何在Azure API管理中选择使用rewrite-uri将后端设置为两个不同的逻辑应用程序?

[英]How to choose to set back-end using rewrite-uri to two different logic apps in Azure API Management?

我正在尝试使用when条件在两个不同的逻辑应用程序之间进行选择:

<inbound>
    <set-variable name="CompanyID" value="@((string)context.Request.Headers.GetValueOrDefault("CompanyID"))" />
    <set-variable name="AuthKey" value="@((string)context.Request.Headers.GetValueOrDefault("AuthKey"))" />
    <base />
    <choose>
        <when condition="@(context.Variables.GetValueOrDefault<string>("CompanyID") == "1" && context.Variables.GetValueOrDefault<string>("AuthKey") == "1")">
            <set-method id="apim-generated-policy">GET</set-method>
            <rewrite-uri id="apim-generated-policy" template="/manual/paths/invoke/?api-version=2016-06-01&amp;sp=/triggers/manual/run&amp;sv=1.0&amp;sig={{apibrokerlogicapp_manual-invoke_5d36ff21ed}}" />
            <set-header id="apim-generated-policy" name="Ocp-Apim-Subscription-Key" exists-action="delete" />
        </when>
        <when condition="@(context.Variables.GetValueOrDefault<string>("CompanyID") == "2" && context.Variables.GetValueOrDefault<string>("AuthKey") == "2")">
            <set-method id="apim-generated-policy">GET</set-method>
            <rewrite-uri id="apim-generated-policy" template="/manual/paths/invoke/?api-version=2016-06-01&amp;sp=/triggers/manual/run&amp;sv=1.0&amp;sig={{apibrokerlogicapp_manual-invoke_5d36ff21ed}}" />
            <set-header id="apim-generated-policy" name="Ocp-Apim-Subscription-Key" exists-action="delete" />
        </when>
        <otherwise />
    </choose>
</inbound>

我的两个变量“ CompanyID”和“ AuthKey”决定要执行的逻辑应用程序,在上述情况下,由于以下原因,将执行相同的逻辑应用程序:

<rewrite-uri id="apim-generated-policy" template="/manual/paths/invoke/?api-version=2016-06-01&amp;sp=/triggers/manual/run&amp;sv=1.0&amp;sig={{apibrokerlogicapp_manual-invoke_5d36ff21ed}}"

上面的行将执行逻辑应用程序1,但是如何执行逻辑应用程序2? 在哪里可以找到我的逻辑应用程序中的以下URL,以便可以在表达式中进行更改?

/manual/paths/invoke/?api-version=2016-06-01&amp;sp=/triggers/manual/run&amp;sv=1.0&amp;sig={{apibrokerlogicapp_manual-invoke_5d36ff21ed

希望有人能帮忙!

提前致谢!

您还需要设置相应的后端服务(在从LogicApps导入的API的所有操作策略中找到它们),并检查查询参数是否也相应匹配:

<inbound>
    <set-variable name="CompanyID" value="@((string)context.Request.Headers.GetValueOrDefault("CompanyID"))" />
    <set-variable name="AuthKey" value="@((string)context.Request.Headers.GetValueOrDefault("AuthKey"))" />
    <base />
    <choose>
        <when condition="@(context.Variables.GetValueOrDefault<string>("CompanyID") == "1" && context.Variables.GetValueOrDefault<string>("AuthKey") == "1")">
            <set-backend-service backend-id="LogicApp_kw1_kw" />
            <set-method>GET</set-method>
            <rewrite-uri template="/manual/paths/invoke/?api-version=2016-06-01&amp;sp=/triggers/manual/run&amp;sv=1.0&amp;sig={{kw1_manual-invoke_5d680fe2da5ce8c03b53263b}}" />
            <set-header name="Ocp-Apim-Subscription-Key" exists-action="delete" />
        </when>
        <when condition="@(context.Variables.GetValueOrDefault<string>("CompanyID") == "2" && context.Variables.GetValueOrDefault<string>("AuthKey") == "2")">
            <set-backend-service backend-id="LogicApp_kw2_kw" />
            <set-method>GET</set-method>
            <rewrite-uri template="/manual/paths/invoke/?api-version=2016-06-01&amp;sp=/triggers/manual/run&amp;sv=1.0&amp;sig={{kw2_manual-invoke_5d68100a2fe4c33527ceaf4d}}" />
            <set-header name="Ocp-Apim-Subscription-Key" exists-action="delete" />
        </when>
        <otherwise />
    </choose>
</inbound>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM