我想使用Salesforce公开的REST服务,现在我使用一个Sandbox实例并使用Anypoint Studio来创建我的流,我想知道实现它的最佳实践是什么。现在我不确定salesforce连接器是否允许我使用该服务,因此,我使用以下组件:
这是整个流程。
<mule xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:oauth2="http://www.mulesoft.org/schema/mule/oauth2" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd">
<http:request-config name="HTTP_Request_Configuration" host="https://test.salesforce.com" port="80" doc:name="HTTP Request Configuration" protocol="HTTPS">
<oauth2:client-credentials-grant-type clientId="3xQYwWqsvZUYbwMRLHiXQy9A23XXXtxg1OMxdXh5p4eoev53q26CmN0Yx0EyLf_HTLW9X" clientSecret="710XXX1723685311">
<oauth2:token-request tokenUrl="https://test.salesforce.com/services/oauth2/token"/>
</oauth2:client-credentials-grant-type>
</http:request-config>
<file:connector name="File" writeToDirectory="/Users/emoran/Desktop" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
<flow name="outbrain_3wintegrationFlow1">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="10" timeUnit="SECONDS"/>
<http:request config-ref="HTTP_Request_Configuration" path="services/apexrest/outbrain_integration_messages/" method="GET" requestStreamingMode="ALWAYS" sendBodyMode="ALWAYS" doc:name="Consume SFDC LOG Service" doc:description="prueba" parseResponse="false" source="#[message.payload]" target="#[message.payload]">
<http:request-builder>
</http:request-builder>
<http:success-status-code-validator values="0..599"/>
</http:request>
</poll>
<logger message=">>>> RESPONSE FROM SERVER: #[message.payload]" level="DEBUG" doc:name="Logger"/>
<echo-component doc:name="Echo"/>
<file:outbound-endpoint path="/" outputPattern="refacciones.json" connector-ref="File" responseTimeout="10000" doc:name="File"/>
</flow>
</mule>使用此服务的最佳方法是什么?
埃德加
发布于 2015-03-21 00:51:16
Mule中的Salesforce连接器允许您使用Salesforce公开的所有服务。您应该在轮询范围内使用Salesforce连接器从Salesforce获取数据。
下面是您的需求的一个简单示例。
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:context="http://www.springframework.org/schema/context" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<context:property-placeholder location="file:${mule_home}/conf/salesforce-config.properties"/>
<sfdc:config name="Salesforce" doc:name="Salesforce" password="${sf_password}" securityToken="${sf_security_token}" url="${sf_url}" username="${sf_username}">
<sfdc:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
</sfdc:config>
<flow name="sfdcpollerFlow1" doc:name="sfdcpollerFlow1">
<poll doc:name="Poll">
<sfdc:get-updated config-ref="Salesforce" doc:name="Salesforce" duration="10" type="Contract"/>
</poll>
<logger message="RESPONSE FROM SERVER: #[payload]" level="INFO" doc:name="Logger"/>
<echo-component doc:name="Echo"/>
<file:outbound-endpoint path="${file_path}" outputPattern="refacciones.json" responseTimeout="10000" doc:name="File"/>
</flow>
</mule>
在上面的示例中,我将获取修改后的联系人并将其放置到文件夹中。有关Salesforce连接器的更多详细信息,可以参考骡子软文档。
http://www.mulesoft.org/documentation/display/current/Salesforce+Connector http://www.mulesoft.org/documentation/display/current/Connect+with+Salesforce+Example
发布于 2015-03-21 10:07:05
使用Mule中的HTTP连接器与Salsforce的Rest接口是完全有效的。然而,正如其他人所提到的,Salesforce连接器在处理Salesforce API(包括身份验证和连接管理)时,抽象了很多复杂性。
我注意到您的示例使用OAuth,其他示例使用basic/ws安全性,但Salesforce连接器也支持OAuth:http://www.mulesoft.org/documentation/display/current/Salesforce+Connector+Authentication
然而,在幕后,Salesforce连接器主要使用Salesforce SOAP。因此,如果您有特殊的需要使用Rest,那么连接器可能没有帮助。
https://stackoverflow.com/questions/29170411
复制相似问题