Search code examples
databasemule

How to use choice on MULE to see if a database is up before sending message?


On every message i receive on mule i log it into a database and route the message, but if the database is down for some reason it just stop routing the service, is it possible to check the database with choise, like if it is possible to connect before sending the message?

code:

<jdbc:connector name="jdbcConnector" dataSource-ref="WSA" validateConnections="false" queryTimeout="10" pollingFrequency="10000" doc:name="Database"> 
    <jdbc:query key="wsadb" value="insert into inbound_messages (payload, timestamp, agent, ip_from, endpoint, soap_operation) values ('', now(), #[groovy: return message.getInboundProperty('user-agent').toString()], #[groovy: return message.getInboundProperty('MULE_REMOTE_CLIENT_ADDRESS').toString()], #[groovy: return message.getInboundProperty('http.request').toString()], '');"></jdbc:query>  
</jdbc:connector>

<flow name="log-request" doc:name="log-request"> 
    <vm:inbound-endpoint path="log-request.in" doc:name="VM"></vm:inbound-endpoint>  
    <logger message="#[groovy: return message.getInboundProperty('user-agent').toString()], #[groovy: return message.getInboundProperty('MULE_REMOTE_CLIENT_ADDRESS').toString()], #[groovy: return message.getInboundProperty('http.request').toString()]" level="INFO" doc:name="Logger"></logger>
    <!--choice doc:name="Choice"-->
        <jdbc:outbound-endpoint exchange-pattern="one-way" queryKey="wsadb" responseTimeout="10000" queryTimeout="-1" connector-ref="jdbcConnector" doc:name="Persist raw message"></jdbc:outbound-endpoint>
    <!--/choice-->
</flow>

Solution

  • Consider using the until successful router:
    http://www.mulesoft.org/documentation/display/current/Routing+Message+Processors#RoutingMessageProcessors-UntilSuccessful