如何在 Mule 中使用带有 GET 操作的 REST API 实现回调接口?



如何使用 REST API 和 GET 操作在 Mule 中实现回调接口?欢迎任何关于骡子的参考示例

以下是示例代码的步骤(最后陈述了一些假设):

  1. 在项目的src/main/api中创建RAML映射:
#%RAML 0.8
---
title: sample
/YourServiceEndpoint
get:
responses:
200:
body:
application/json:
  1. 在 Mule 中使用 APIKit 路由器在src/main/app中创建映射。这会根据问题使用GET(在为您的用例编写集成测试时,您可以使用POST或任何其他 REST 操作代替):
<!-- /api/v1 is defined in the APIKit configuration -->
<flow name="get:/api/v1/YourServiceEndPoint">
<http:inbound-endpoint exchange-pattern="request-response" connector-ref="HTTP_HTTPS" ref="HTTP" doc:name="HTTP"/>
<apikit:router config-ref="APIKitRouter" doc:name="APIkit Router"/>
<exception-strategy ref="Standard_Error_Responses" doc:name="Reference Exception Strategy"/>
<!-- do all other stuff here; for example -->
<when expression="#[payload.containsKey(&quot;resultSet1&quot;) &amp;&amp; payload.get(&quot;resultSet1&quot;).size() &gt; 0]">
<set-payload value="#[payload.get(&quot;resultSet1&quot;).get(0)]" doc:name="Set Payload"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</when>
</flow>
  1. 上述connector-ref要求全局配置(很可能定义为项目中的global-configuration.xml)具有类似于以下内容的配置片段:
<https:connector name="HTTPS" enableCookies="true" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTPHTTPS">
<https:tls-server path="${truststoreLocation}" storePassword="${truststorePassword}"/>
</https:connector>

假设:

  1. APIKit Router 需要 Mulesoft/Salesforce 的企业许可证,否则这不起作用。

  2. 代码段路径假定使用 Maven。如果您的项目尚不支持 maven,请选择Project >Mavenize

  3. 这只是一个建议,与问题无关。用例声明"巨大的数据负载",这意味着应该通过架构以不同的方式处理 - 您可能应该使用SFTP而不是HTTP/HTTPS API。

有用的说明:

  1. 应用程序的"帮助"菜单中还有其他示例,演示了 SOAP、Callable接口等的使用。这将使你能够前进。

最新更新