在Mulesoft中,我如何动态管理多个Twitter用户帐户,因为目前它只需要一个只能拥有一个用户的应用程序的连接器配置中的consumerkey,consumersecret,accesskey和accesstoken。
请有人解释一下吗?
<twitter:config name="Twitter__Configuration" accessKey="#[flowVars.accessToken]" consumerKey="#[flowVars.consumerKey]" consumerSecret="#[flowVars.consumerSecret]" doc:name="Twitter: Configuration" accessSecret="#[flowVars.accessTokenSecret]"/>
<flow name="twitterFlow1">
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select * from twittercredentials;]]></db:parameterized-query>
</db:select>
<set-variable variableName="consumerKey" value="#[message.payload[0]['consumerkey']]" doc:name="Variable" />
<set-variable variableName="consumerSecret" value="#[message.payload[0]['consumersecret']]" doc:name="Variable" />
<set-variable variableName="accessToken" value="#[message.payload[0]['accesstoken']]" doc:name="Variable" />
<set-variable variableName="accessTokenSecret" value="#[message.payload[0]['accesstokensecret']]" doc:name="Variable" />
</flow>
<flow name="twitterFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/twitterconnect" doc:name="HTTP"/>
<flow-ref name="twitterFlow1" />
<twitter:show-user config-ref="Twitter__Configuration" doc:name="Twitter"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
答案 0 :(得分:1)
我想在mule社区论坛的this post中,您可以找到问题的答案。 基本上你可以用这种方式在twitter globalk连接器中使用mule表达式语言:
<twitter:config name="Twitter" accessKey="#[flowVars.accessKey]"
accessSecret="#[flowVars.accessSecret]" consumerKey="#
[flowVars.consumerKey]" consumerSecret="#[flowVars.consumerSecret]"/>
希望这有帮助
完整示例:
这是一个示例流程:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:twitter="http://www.mulesoft.org/schema/mule/twitter" 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"
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/twitter http://www.mulesoft.org/schema/mule/twitter/current/mule-twitter.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<twitter:config name="Twitter" accessKey="#[flowVars['accessKey']]" accessSecret="#[flowVars['accessSecret']]" consumerKey="Cannot be parametrized" consumerSecret="Cannot be parametrized" useSSL="false" doc:name="Twitter"/>
<flow name="twitterFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<message-properties-transformer scope="invocation" doc:name="Message Properties">
<add-message-property key="accessKey" value="#['myVarAccessKey']"/>
<add-message-property key="accessSecret" value="#['myVarAccessSecret']"/>
</message-properties-transformer>
<twitter:update-status config-ref="Twitter" status="ciao" doc:name="Twitter"/>
</flow>
</mule>
这里还有一个使用IP过滤(twitter ip系列)的wireshark捕获屏幕截图,用于调试http调用: