【发布时间】:2016-04-23 07:03:45
【问题描述】:
在我的案例 WSo2 中,我想通过 ESB 通信两个 Web 服务,为此我必须设置端点和代理服务,但我无法解决。
有什么想法吗?有教程吗?
【问题讨论】:
-
你指的是服务编排吗?例如:从一个 Web 服务获取输入并将其发送到第二个 Web 服务?
在我的案例 WSo2 中,我想通过 ESB 通信两个 Web 服务,为此我必须设置端点和代理服务,但我无法解决。
有什么想法吗?有教程吗?
【问题讨论】:
首先,您应该在 ESB 中的代理服务和 API 之间进行选择。代理服务将为您提供 SOAP 端点以供使用,而 API 将为您提供 RESTful 端点。
但是无论你选择哪个,其余的都是一样的。当您调用代理服务或 API 时,将触发一个 inSequence。在您的 inSequence 中,您将必须混合和匹配一组中介,并根据您的需要定制它们。中介是集成流程中的一个工作单元。
例如,服务链场景可以是这样的:
查看下面的 inSequence,它执行上述步骤。您可以将其放入代理或 API。
<inSequence>
<log level="custom">
<property name="Lets log the incoming payload" expression="$body"/>
</log>
<!-- Payload for first backend -->
<payloadFactory media-type="json">
<format>
"payload":{
"name":"StackOverflow",
"value":"SO"
}
</format>
</payloadFactory>
<!-- Invoke backend 1 -->
<call>
<endpoint>
<http uri="http://backend1/jsonEndpoint" method="post"/>
</endpoint>
</call>
<!-- At this point we have the response from backend1 in the message context -->
<log level="custom">
<property name="Lets log the payload from backend1" expression="$body"/>
</log>
<!-- Payload for second backend. We are using JSONPath to access a value from backend1's payload here -->
<payloadFactory media-type="json">
<format>
"payload":{
"name":"StackOverflow",
"value":"SO",
"id": $1
}
</format>
<args>
<arg expression="$.response.from.backend1.id"/>
</args>
</payloadFactory>
<!-- Invoke backend 2 -->
<call>
<endpoint>
<http uri="http://backend2/endpoint" method="post"/>
</endpoint>
</call>
<!-- At this point we have the response from backend2 in the message context -->
<log level="custom">
<property name="Lets log the payload from backend2" expression="$body"/>
</log>
<!-- Respond back to client -->
<respond/>
</inSequence>
我没有测试过上面的序列,但它应该是相当准确的。为了帮助您入门,这里是我们上面使用的所有内容的文档。
【讨论】: