The Mule 4 SQS connector is one of my least favorite connectors.  It’s one of the worst connectors I have ever used as far as inconcistency between the sending datamodel and the receive messages data model. 

To receive a JSON message off of SQS this is the code snippet that I use:

    <sqs:receivemessages doc:name="Receivemessages" config-ref="Amazon_SQS_Configuration" queueUrl="${sqs.orderscreatequeue}" preserveMessages="true" numberOfMessages="10">
                     <reconnect-forever frequency="10000" />
    <set-variable variableName="sqs_receipt_handle" value="#[attributes.'sqs.message.receipt.handle']" doc:name="set-sql-receipt-handle/>
    <set-variable variableName="messageId" value="#[attributes.messageId.StringValue]" doc:name="set-messageId" />
    <set-variable variableName="orderId" value="#[attributes.orderId.StringValue]" doc:name="set-pimProductId" />
    <set-payload value="#[output application/json   --- read(payload)]" doc:name="set-payload" />    

This bit of code is pretty normal for a Mulesoft connector. Though that last line is a little annoying, because the SQS connector has no idea about the datatype coming across and assumes text/plain, so I have to force it into a JSON.  That’s fine though, I can live with all of that.  Attributes are used correctly here, I can get attributes that I set on the data sent to the SQS queue. 

Let’s look at the other side of this same transaction, how to send that same SQS message:

      <set-payload value="#[output text/plain --- write(payload, 'application/json')]" doc:name="set-payload" />
      <ee:transform doc:name="Transform Message" >
             <ee:message >              
                     <ee:set-payload ><![CDATA[%dw 2.0
output application/json
       body: payload as String,
              "messageId": {
                     "stringValue" : vars.messageId  ,
                     "dataType" : "String"
              } as Object {
                     class: "org.mule.extension.sqs.api.model.MessageAttributeValue"
              "orderId": {
                     "stringValue" : vars.orderId,
                     "dataType" : "String"
              } as Object {
                     class : "org.mule.extension.sqs.api.model.MessageAttributeValue"
       } as Object {
              class: "java.util.HashMap"
       } as Object {
              class : "org.mule.extension.sqs.api.model.Message"
      <logger level="DEBUG" doc:name="Logger" category="com.fbb.int006" message="#[vars.messageId] Order #[vars.orderId] SQS Payload: #[payload]"/>
      <sqs:send-message doc:name="Send message" config-ref="Amazon_SQS_Configuration" queueUrl="${sqs.orderscreatequeue}"/>

The required transform to set the correct message object to send to SQS is one of the UGLIEST transforms I’ve ever seen, and it’s not documented anywhere.  I had to look at source code for the SQS connector to get the SQS datamodel (org.mule.extension.sqs.api.model.Message) and then piece together code from a variety of places to do this. 

This is like, the worst, and really needs to be improved.