How to copy a message context to a property?

Using WSO2 Enrich mediator

Assume we need to copy a whole message context to a property for further use. As an example, if we use Amazon SQS Connector, we may need that message to send it to a Queue as the message body, but we need to pass it as a property. How can we achieve this?

Let’s assume that we are building a message which needs to be passed to the SimpleStockQuote. The request simply follows like this.

<m0:getQuote xmlns:m0="http://services.samples">
<m0:request>
<m0:symbol>WSO2</m0:symbol>
</m0:request>
</m0:getQuote>

Thinking from the ease of the user, we do not want the user to send this message as the input. Therefore we ask from the user only the value for the symbol parameter.

Therefore, user input would be as follow.

{
"company":"WSO2"
}

Using this we are going to build the message as convert the whole message context as a property.

We can use a sequence as below.

First, we will copy the user input to a property called companyName. It is used in args as the first argument. The message is build using that as $1.

Then we use enrich mediator to copy the whole message body a property called target_property.

As I explained this can be used anywhere we want as an example, for AmazonSQS Connector, message body as shown below.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store