如何使用 REST API 和 GET 操作在 Mule 中实现回调接口?欢迎任何关于骡子的参考示例
以下是示例代码的步骤(最后陈述了一些假设):
- 在项目的
src/main/api
中创建RAML映射:
#%RAML 0.8
---
title: sample
/YourServiceEndpoint
get:
responses:
200:
body:
application/json:
- 在 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("resultSet1") && payload.get("resultSet1").size() > 0]">
<set-payload value="#[payload.get("resultSet1").get(0)]" doc:name="Set Payload"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</when>
</flow>
- 上述
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>
假设:
APIKit Router 需要 Mulesoft/Salesforce 的企业许可证,否则这不起作用。
代码段路径假定使用 Maven。如果您的项目尚不支持 maven,请选择
Project >Mavenize
。这只是一个建议,与问题无关。用例声明"巨大的数据负载",这意味着应该通过架构以不同的方式处理 - 您可能应该使用SFTP而不是HTTP/HTTPS API。
有用的说明:
- 应用程序的"帮助"菜单中还有其他示例,演示了 SOAP、
Callable
接口等的使用。这将使你能够前进。