Contact Free trial Login

Publish Messages

The Publish operation in the Anypoint MQ connector lets you create a new Anypoint MQ message and send it to the specified destination, be it a queue, FIFO queue, or a message exchange. With it, you can configure not only the content of the message, but also all the headers and properties you need.

Send a Message

When used in its default form, the connector publishes whatever is in its message payload:

<anypoint-mq:publish destination="invoiceQueue" config-ref="MQ_config"/>

But what happens if the payload is not in the correct format, and you actually need to make a transformation? You can place a DataWeave transformation before the publish operation, but that would cause the message payload to change and impact the operation placed after the publish operation.

To avoid this undesired impact, you can now place the transformation inside the publish operation:

<anypoint-mq:publish destination="invoiceQueue" config-ref="MQ_config">
  <anypoint-mq:body>#[%dw 2.0
   output application/json
   ---
   payload.payments
   ]</anypoint-mq:body>
</anypoint-mq:publish>

The transformation can be used for generating the content that is published, without producing a side effect on the message in transit.

Configure User Properties

Every Anypoint MQ message can have a set of properties, which can be used in many different ways, such as to provide compatibility with other messaging systems or to communicate the content-type of a message. The publish operation allows you to configure these properties directly in the message.

When you need to set a property for an outgoing message, you can use the properties element in the message:

<anypoint-mq:publish config-ref="MQ_config" destination="${bridgeDestination}"
                     properties="#[{AUTH_TYPE: 'jwt', AUTH_TOKEN: attributes.queryParams.token}]">
    <anypoint-mq:body>#["bridged_" ++ payload]</anypoint-mq:body>
</anypoint-mq:publish>

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub