通过mule与amazon SNS api通信时使用Topic对象

时间:2015-05-04 20:09:22

标签: amazon-web-services mule amazon

我正在使用Anypoint Studio来试验连接器。此时,我正在尝试创建一个简单的流程,列出亚马逊SNS端点上可用的主题,并搜索某个主题是否可用。 到目前为止,我能够从API获得主题列表的响应,然后我使用Object转换为JSON转换器,但我想迭代列表以搜索某个主题(使用java或无论过滤器)。主题实体已存在于Anypoint Studio的amazon API中,但我无法找到如何将其映射到API返回的响应。任何提示都将不胜感激。 编辑:这是流程的代码,删除了访问密钥。

<?xml version="1.0" encoding="UTF-8"?>

<sns:config name="Amazon_SNS" accessKey="" secretKey=""  doc:name="Amazon SNS" region="EUWEST1">
    <sns:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
</sns:config>
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
<json:object-to-json-transformer name="Object_to_JSON" doc:name="Object to JSON"/>
<flow name="CreateTopic">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/createtopic" doc:name="HTTP"/>
    <sns:create-topic config-ref="Amazon_SNS" doc:name="Amazon SNS">
        <sns:create-topic-request name="#[message.inboundProperties.'http.query.params'.name]"/>
    </sns:create-topic>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
<flow name="Subscribe">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/Subscribe" doc:name="HTTP"/>
    <sns:subscribe config-ref="Amazon_SNS" doc:name="Amazon SNS">
        <sns:subscribe-request topicArn="#[message.inboundProperties.'http.query.params'.topic]" protocol="email" endpoint="#[message.inboundProperties.'http.query.params'.subscriber]"/>
    </sns:subscribe>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
<flow name="ListTopics">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/listTopics" doc:name="HTTP"/>
    <sns:list-topics config-ref="Amazon_SNS" doc:name="Amazon SNS">
    </sns:list-topics>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
<flow name="Publish">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/publish" doc:name="HTTP"/>
    <sns:publish config-ref="Amazon_SNS" doc:name="Amazon SNS">
        <sns:publish-request topicArn="#[message.inboundProperties.'http.query.params'.topic]" message="There's new content in the topic #[message.inboundProperties.'http.query.params'.topic]" subject="New comments on an idea - Crowdsourcing Forums" messageStructure="Raw"/>
    </sns:publish>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
<flow name="checkTopic">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/checkTopic" doc:name="HTTP"/>
    <sns:get-topic-attributes config-ref="Amazon_SNS" doc:name="Amazon SNS">
        <sns:get-topic-attributes-request topicArn="#[message.inboundProperties.'http.query.params'.topic]"/>
    </sns:get-topic-attributes>
</flow>

1 个答案:

答案 0 :(得分:0)

您从sns:list-topics获得的消息有效负载为com.amazonaws.services.sns.model.ListTopicsResult

因此,您可以使用MEL转换器来过滤主题列表,其表达式如下:

($ in message.payload.topics if $.topicArn contains 'my-topic')

参考:Projections and folds in MVEL 2.0