0
votes

I am using WSO2 ESB as RabbitMQ consumer: I have a proxy service which consumes messages from rabbit queue and sends it to my backend service using http endpoint. Everything works fine and messages are successfully delivered to my backend.

The problem is that my backend service can fail sometimes and I would like to know about that fact and save this information in ESB log for example.

For example I would like to log HTTP/1.1 500 Internal Server Error errors.

How can I achieve this? I found out that I should use FORCE_ERROR_ON_SOAP_FAULT property in my in sequence but it does not work in my case.

My consumer proxy configuration looks as follows:

<proxy name="AMQPProxy" startOnLoad="true" statistics="enable"
    trace="enable" transports="rabbitmq">
    <description/>
    <target>
        <inSequence onError="fault">
            <log level="full"/>
            <property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>
            <property name="OUT_ONLY" value="true"/>
            <property name="FORCE_ERROR_ON_SOAP_FAULT"
                scope="default" type="STRING" value="true"/>
            <send>
                <endpoint key="SampleEndPoint"/>
            </send>
        </inSequence>
        <outSequence>
            <log level="full">
                <property name="MESSAGE" value="outSequence"/>
            </log>
            <drop/>
        </outSequence>
    </target>
    <parameter name="rabbitmq.queue.routing.key">route</parameter>
    <parameter name="rabbitmq.exchange.name">exchange</parameter>
    <parameter name="rabbitmq.queue.name">queue</parameter>
    <parameter name="rabbitmq.connection.factory">AMQPConnectionFactory</parameter>
</proxy>

How should I configure it to handle 5xx errors?

Edit:

I finally solve it using following proxy configuration:

<proxy name="AMQPProxy" startOnLoad="true" statistics="enable"
    trace="enable" transports="rabbitmq">
    <description/>
    <target>
        <inSequence onError="fault">
            <log level="full"/>
            <property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>
            <send>
                <endpoint key="SampleEndPoint"/>
            </send>
        </inSequence>
        <outSequence>
            <log>
                <property expression="$axis2:HTTP_SC" name="Status Code"/>
            </log>
            <filter regex="^((?!(200|202)).)*$" source="$axis2:HTTP_SC">
                <then>
                    <property expression="$axis2:HTTP_SC" name="ERROR_CODE"/>
                    <property expression="$axis2:HTTP_SC_DESC" name="ERROR_MESSAGE"/>
                    <sequence key="fault"/>
                </then>
            </filter>
            <drop/>
        </outSequence>
    </target>
    <parameter name="rabbitmq.queue.routing.key">route</parameter>
    <parameter name="rabbitmq.exchange.name">exchange</parameter>
    <parameter name="rabbitmq.queue.name">queue</parameter>
    <parameter name="rabbitmq.connection.factory">AMQPConnectionFactory</parameter>
</proxy>
1

1 Answers

0
votes

You could modify you fault sequence to capture this information, for example:

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="fault">
    <!-- Log the message at the full log level with the ERROR_MESSAGE and the ERROR_CODE-->
    <log level="full">
        <property name="text" value="An unexpected error occured. Executing fault sequence"/>
        <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
        <property name="detail" expression="get-property('ERROR_DETAIL')"/>
        <property name="exception" expression="get-property('ERROR_EXCEPTION')"/>
        <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
    </log>
    <!-- Drops the messages by default if there is a fault -->
    <drop/>
</sequence>

Also you may want to send a soap fault message to the client, so you can create a soapfault message and send it to the client in this way:

<makefault version="soap11">
    <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
    <reason expression="get-property('ERROR_MESSAGE')"/>
</makefault>
<send/>
<drop/>