title: WSO2 ESB Fault Sequence for Store and Forward with REST API
body: <p>Currently we use the Store and Forward pattern in WSO2 ESB. So when a message comes into a proxy we use a sequence to move it into a store (queue) and then have a message processor to process the queued messages and send them to our REST API i.e. process the messages asynchronously. However when the REST API throws 400, 404, 409 or 422 the processor stops (same for 50X errors). We'd like to move these failed message for 4XX status codes to a separate queue where they can be diagnosed and dealt with. This means if there is one bad message it doesn't stop the remaining queued messages being processed. We only want to do this for 4XX faults. 5XX or network issues/timeouts should continue to stop the processor. I've looked into the Dead Letter Channel (<a href="https://docs.wso2.com/display/IntegrationPatterns/Dead+Letter+Channel" rel="nofollow">https://docs.wso2.com/display/IntegrationPatterns/Dead+Letter+Channel</a>) but this seems only compatible with Proxy (synchronous requests). So instead I'm trying to use a Fault Sequence to move the message to another queue however the fault sequence only seems to work with SOAP faults. Is it possible to get it to work with REST API status code faults? <a href="https://docs.wso2.com/display/ESB481/Error+Handling" rel="nofollow">https://docs.wso2.com/display/ESB481/Error+Handling</a></p>
  
  <p>I noticed it possible to add status codes but this seems only useful to reduce retry attempts. Thanks in advance.</p>
  
  <hr>
  
  <p><strong>FOLLOW UP</strong></p>
  
  <p>I tried to trigger a fault sequence for my REST API as suggested by @Jean-Michel but still the fault sequence doesn't run. Try it for yourself with these steps.</p>
  
  <p>Step 1: add a proxy</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;proxy xmlns="http://ws.apache.org/ns/synapse"
     name="TestProxy"
     transports="https,http"
     statistics="disable"
     trace="disable"
     startOnLoad="true"&gt;
  &lt;target faultSequence="DeadLetterQueueSequence"&gt;
    &lt;inSequence&gt;
       &lt;log level="custom" category="ERROR"&gt;
          &lt;property name="TEST" value="Proxy was hit"/&gt;
       &lt;/log&gt;
    &lt;/inSequence&gt;
    &lt;endpoint&gt;
       &lt;address uri="http://localhost:8080/sampleService/failEndpoint400"/&gt;
    &lt;/endpoint&gt;
  &lt;/target&gt;
  &lt;description/&gt;
  &lt;/proxy&gt;
  </code></pre>
  
  <p>Step 2:  Add the dead letter sequence:</p>
  
  <pre><code>&lt;sequence xmlns="http://ws.apache.org/ns/synapse" name="DeadLetterQueueSequence" trace="disable"&gt;
  &lt;log level="full" category="ERROR"&gt;
    &lt;property name="Test" value="DeadLetterQueueSequence was hit"&gt;&lt;/property&gt;
  &lt;/log&gt;
  &lt;/sequence&gt;
  </code></pre>
  
  <p>The 1st log entry appears but never the 2nd (from the DeadLetter sequence).</p>
  
  <p>It seems that the WSO2 ESB isn't REST friendly and only works well with SOAP services.</p>