Using Amazon SQS with Mule and iON

December 29 2011

1 comment. 0
motif

I’m probably preaching to the choir here, but application messaging is extremely important for a wide variety of applications. It allows you to:

  • Decouple application message processing from receiving
  • Orchestrate data between two applications
  • Handle the loss of a server without losing data
  • Process data at a later date when you have more capacity

Yet, creating a reliable, highly scalable messaging infrastructure is extremely difficult – and sometimes not even an option. Amazon SQS takes that problem off your hands – it’s a hosted, highly scalable, reliable queueing service for applications. And now you can use it easily in your Mule applications with our new SQS support.

How to use it

It’s quite simple to connect Mule to SQS. There are two primary things you need to know how to do – send and receive. Use the <send-message> processor to send the payload as a String to Amazon. For example, this snippet will take an HTTP POST message and put it on SQS.

<flow name="producer">
    <inbound-endpoint address="http://localhost:9090/queue"/>
    <sqs:send-message/>
</flow>

(You can optionally specify the payload attribute to use an expression to send something other than the message payload to SQS).

Receiving is just as easy; simply use the <receive-messages> processor. Here’s an example which receives messages from a queue and puts them in Mongo DB:

<flow name="consumer">
    <sqs:receive-messages />
    <mongo:insert-object-from-map collection="some_collection">
      <mongo:element-attributes>
        <mongo:element-attribute key="text">#[payload]</mongo:element-attribute>
      </mongo:element-attributes>
    </mongo:insert-object-from-map>
</flow>

When a message is received, your flow will process it. If the flow executes without an exception, the connector will automatically delete it from the queue. You can also optionally delete it yourself by setting the “preserveMessages” attribute to true and using the <delete-message> processor. In addition to sending and receiving, you can do all the other SQS operations including modifying queue attributes, permissions or get message counts.

You can learn more information and get started with the SQS connector on MuleForge.


We'd love to hear your opinion on this post


One Response to “Using Amazon SQS with Mule and iON”

  1. Hi,

    I am trying to do this from Mule Studio. I hope I dont need maven in this case. I imported the sqs supporting jar file and I try to deploy the application to MuleION. But it failed.

    Please help if i am wrong some where.

    Regards
    Guru