Idempotent Filter in Mule 4 | Filter in Mule 4

Idempotent filter in Mule 4


It will not allow payload to pass if same payload is allowed to pass more than once.

Flow:

 

Idempotent filter configuration:


Method: POST

Input & output:
On hitting first time from postman:


On hitting second time with same payload:


XML project code:



<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
     xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
     <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="6410b392-3fcc-4f5c-b1d0-e5be6f7811da" >
          <http:listener-connection host="0.0.0.0" port="8085" />
     </http:listener-config>
     <flow name="test_idempotent" doc:id="6b29cfee-8203-410b-87cb-f44c693ec585" >
          <http:listener doc:name="Listener" doc:id="660ae438-50ed-4932-9a06-792624a29d87" config-ref="HTTP_Listener_config" path="/idem"/>
          <idempotent-message-validator doc:name="Idempotent Message Validator" doc:id="0197e194-1cb1-4b5d-9239-63c44ba726a0" idExpression="#[payload]"/>
     </flow>
</mule>