Chris
Chris

Reputation: 23

Mule SQS sendMessage throwing Failed to transform from "json" to "java.util.HashMap"

After upgrading to latest SQS connector previously working code now fails.

The latest version of the connector requires the message attribute to be specified.

API doc's show message should be a String. http://mulesoft.github.io/sqs-connector/3.0.0/mule/sqs-config.html#send-message

Using:

<object-to-string-transformer doc:name="Object to String"/>

The flow takes the posted data and submits it as a SQS message.

<flow name="rxWebhook">
    <http:listener config-ref="HTTPS_8081" path="/" doc:name="HTTPS" responseStreamingMode="ALWAYS">
        <http:response-builder disablePropertiesAsHeaders="true"/>
    </http:listener>
    <object-to-string-transformer doc:name="Object to String"/>
    <sqs:send-message config-ref="Amazon_SQS_USWEST2" message="#[payload]" queueUrl="${aws.sqs.myQueue}" doc:name="Amazon SQS"/>
</flow>

When posting json data to the flow it errors with:

org.mule.api.transformer.TransformerMessagingException: Failed to transform from "json" to "java.util.HashMap". Message payload is of type: String

Upvotes: 2

Views: 1646

Answers (1)

Ryan Carter
Ryan Carter

Reputation: 11606

I think it's because theres i an optional parameter named:

<sqs:message-attributes>

Which defaults to #[payload] and expects the payload to be a Map. So to avoid this, specify the param and try passing null maybe:

<sqs:send-message config-ref="Amazon_SQS_USWEST2" message="#[payload]" queueUrl="${aws.sqs.myQueue}" doc:name="Amazon SQS">
            <sqs:message-attributes ref="#[null]"/>
</sqs:send-message>

Upvotes: 2

Related Questions