0

假设我们有一个与多个服务通信的微集成器。

我们希望能够集群其中一个服务,例如,如果我们向一个服务发送两个请求,我们希望每个请求都由服务的不同节点处理,这可能吗?

服务是第三方 REST API,我们想向两个不同的 URL 发送请求。

Integration studio 元素中有 Load-BalanceEndPoint 元素,但不清楚它是如何工作的,或者即使它允许我们解决上述问题。

谁能帮助我们解决这个问题/解释我们应该如何使用提到的端点?

4

1 回答 1

0

是的,您可以将负载平衡端点用于您的用例。查看以下示例配置。

API配置:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/loadbalance" name="checkLoadBalance" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET">
        <inSequence>
            <call>
                <endpoint key="testLoadBalance"/>
            </call>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

端点配置:

<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="testLoadBalance" xmlns="http://ws.apache.org/ns/synapse">
    <loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
        <endpoint name="endpoint_urn_uuid_6179155B57847314A657084710149040-304004407">
            <http method="GET" uri-template="http://www.mocky.io/v2/5e574b1c3000006000fd38cd">
                <suspendOnFailure>
                    <initialDuration>-1</initialDuration>
                    <progressionFactor>1</progressionFactor>
                </suspendOnFailure>
                <markForSuspension>
                    <retriesBeforeSuspension>0</retriesBeforeSuspension>
                </markForSuspension>
            </http>
        </endpoint>
        <endpoint name="endpoint_urn_uuid_6179155B57847314A657084710149040-304004407">
            <http method="GET" uri-template="http://www.mocky.io/v2/5185415ba171ea3a00704eed">
                <suspendOnFailure>
                    <initialDuration>-1</initialDuration>
                    <progressionFactor>1</progressionFactor>
                </suspendOnFailure>
                <markForSuspension>
                    <retriesBeforeSuspension>0</retriesBeforeSuspension>
                </markForSuspension>
            </http>
        </endpoint>
    </loadbalance>
    <description/>
</endpoint>

在这里,我使用了两个不同的模拟端点。他们将返回{"Hello": "World"}{"hello": "world"}。部署后,如果我第一次调用 checkLoadBalance API,我会从第一个端点得到响应。如果我第二次调用,我会从第二个端点得到响应。在这里,我将算法作为 Roundrobin 给出。因此它将以循环方式进行调度。

于 2020-04-09T20:17:27.273 回答