+

Idempotent Message Validator

Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule will reach its End of Life on November 2, 2022, when Extended Support ends.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

The Idempotent Message Validator ensures that only unique messages continue through a flow’s execution by checking the unique ID of the incoming message. You can use any incoming attribute of the Mule message as an ID, or you can compute the ID by configuring a DataWeave expression. You can also use the DataWeave Crypto functions to compute hashes (SHA, MD5) from the data.

Message Hashing

DataWeave enables you to import the Crypto library to execute hashing functions. Calculating a hash can be useful when you want to compute a unique ID for the Mule message. For example, if you want to get an MD5 hash from the payload and use it as the ID, open the Idempotent Message Validator properties in Anypoint Studio and set ID Expression (idExpression in XML) to the following DataWeave expression:

#[
    %dw 2.0
    output text/plain
    import dw::Crypto
    ---
    Crypto::hashWith(payload,'MD5')
]

Examples

  • The following example shows an Idempotent Message Validator configured to extract the URL parameter id from the HTTP request and use that value as a unique identifier to filter the message:

    <flow name="myFlow">
      <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/"/>
      ...
      <idempotent-message-validator doc:name="Idempotent Message Validator" idExpression="#[attributes.queryParams.id]"/>
      ...
    </flow>
  • The next example shows an Idempotent Message Validator configured to hash the payload using a DataWeave expression and use the result of this operation as the unique identifier to filter the message:

    <flow name="myFlow">
      <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/"/>
      ...
      <idempotent-message-validator doc:name="Idempotent Message Validator" idExpression="
        #[%dw 2.0
          output text/plain
          import dw::Crypto
          ---
          Crypto::hashWith(payload,'MD5')]"/>
      ...
    </flow>

Parameter Reference

Name Type Description Default Value Required

ID Expression

Expression

The expression Mule uses to generate the ID. You can use a DataWeave function to calculate the ID, or you can extract the ID from any existing value of the Mule message.

#[correlationId]

No

Value Expression

Expression

This parameter is not used. Setting a value has no effect.

#[correlationId]

No

Object Store

Object Store

Either a name to reference a global object store or a definition of a private object store where the component stores the processed message IDs.

Object Store created by the Object Store Manager. Not persistent, with an entry TTL of 5 MINUTES and an expiration interval of 6 SECONDS.

No

Store Prefix

String

Defines the prefix of the object store names. This value is used only for the internally built object store.

configFileName.flowName.IdempotentMessageValidator

No

Throws

  • MULE:DUPLICATE_MESSAGE

Was this article helpful? Thanks for your feedback!
View on GitHub