ArganoMS3 | Cloud Integration Solutions

  • About
    • Why Us
    • Leadership
    • Our Core Values
    • Clients
    • ArganoMS3 PHILIPPINES
  • Services & Expertise
    • API & INTEGRATION
      • Tavros
      • KONG API
      • MuleSoft
      • APIGEE
      • REDHAT FUSE / CAMEL
    • STRATEGY & OPTIMIZATION
      • DEVOPS
      • 24x7x365 Ops Support
    • CLOUD SERVICES
      • AMAZON AWS
      • SALESFORCE
    • ARTIFICIAL INTELLIGENCE
      • RPA
      • BIG DATA
      • IoT
  • Partners
    • MuleSoft
    • AWS
    • UiPath
    • Kong
    • Apigee
    • Red Hat
  • Resources
    • ArganoMS3 Is Talkin’ Nerdy
    • Case Study
    • MUnit Whitepaper
    • MuleSoft Runtime Whitepaper
    • API-Led Architecture Whitepaper
  • Careers
  • Blog
    • Archive
  • Contact

Database Connection Check

February 15, 2016

Database Connection Check

Mark J. Norton

I was recently given the task to create a uniform approach to checking the status of all running applications.  These checks use an HTTP listener to provide status information back to the caller. Currently, this information is returned in JSON format, but a shared formatter flow is called to provide a global method to transform it into another form, such as HTML.

The basic application check information includes a timestamp, the name of the application, what host, port, and cluster id it is running on, etc.  Additionally, checks are made for the status of any third party resources being used, such as a database, a REST or WSDL service, message queue, or others.  In particular, I’d like to share how the database connection check works.

The usual way to check to see if a particular database connection is up and running is to run a query against it.  Perhaps something like this:

<db:select config-ref=”MySQL_Configuration” doc:name=”Database”>

            <db:parameterized-query>

                          <![CDATA[select sysdate();]]>

            </db:parameterized-query>

</db:select>

If the connection is down, an exception is thrown that can be caught and status rendered appropriately.  However, there are times when this approach will fail even though the connection is up and running.  Databases containing sensitive information, such as those protected by HIPAA, may disallow select operations.  A more general approach can be developed by accessing the database connector object directly.

The simplest way to access the database connector object directly is to define it as a bean in a Mule global configuration file or a domain configuration file.

<spring:beans>

   <spring:bean id=”Connector” name=”conName”

                    class=”org.apache.commons.dbcp2.BasicDataSource”>

         <spring:property name=”driverClassName”    

                   value=”oracle.jdbc.driver.OracleDriver” />

         <spring:property name=”url” value=”${db.url}” />

         <spring:property name=”username” value=”${db.username}” />

         <spring:property name=”password” value=”${db.password}” />

   </spring:bean>

</spring:beans>

Once the bean is defined, we can access existing methods such as isClosed() to determine if the connection is open or closed.  An active database connection must be open to be used.  This example shows how to capture the database connector status using a MEL statement.

<set-variable doc:name=”isClosed”

value=”#[app.registry.conName.getConnection().isClosed() ? ‘Down’ : ‘Up’]”

variableName=”isClosed”/>

Depending on the database driver you are using, the method name might be slightly different.  Still, this is a more reliable and consistent way to determine if a database connection is viable

Filed Under: Integration, Mulesoft

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

FUTURE PROOF SOFTWARE SOLUTIONS
ArganoMS³ enables organizations to meet today’s software, integration, cloud, and data-related challenges with confidence and ease.

About

  • Why Us
  • Leadership
  • Team
  • Clients
  • We're hiring

Solutions

  • API & Integration
  • Strategy and Optimization
  • Cloud Services
  • Artificial Intelligence

Partners

  • Apigee
  • AWS
  • Kong
  • MuleSoft
  • Red Hat
  • Salesforce
  • UiPath

Popular Links

  • Contact Us
  • Blog
  • White Papers
  • Case Study
COPYRIGHT © 2022 ⬤ ArganoMS³ MOUNTAIN STATE SOFTWARE SOLUTIONS

Copyright © 2023 · MS3 Mountain State Software Solutions · Log in