3 Replies Latest reply on Dec 26, 2012 6:51 PM by Aristides Neto

    Looking for suggestions on how to pause my application if identified that the DB is not available

    Noa Drach Novice

      Hello all,

       

      I am trying to think of a way to implement in AS7 a mechanism that will help me identify situations where the DB is not avaiable.

       

      basically what will happen if the DB is not avaiable is that i will not have new content generated by my app (lets say i use schedulers to sample data from the DB and create activity inside my system according to this) but if there was already some content created than i will probably have my DLQ filled up because the MDBs handling the current content of the queues will fail and get the messages redelived until they will get to the DLQ.

       

      so basically what i want to do is this:

       

      on the first exception that i catch and analyze that it's a result of the DB not being available:

        1. set a system wide flag
        2. put the messaging system into some pause - how can i do this?
        3. start some process that will sample the DB to discover if it's active again - how can i sample the DB state?

       

      Thanks,

      Noa

        • 1. Re: Looking for suggestions on how to pause my application if identified that the DB is not available
          Nicklas Karlsson Master

          Hmm, I have no AS around to test this but I would think that a @Singleton or @ApplicationScoped component could hold the flag and perhaps a ModelControllerClient can be used for manipulating the messaging system (and checking the state of the DB). The DB state could also be checked by a scheduled task that would call some ping method and catch any exceptions.

          1 of 1 people found this helpful
          • 2. Re: Looking for suggestions on how to pause my application if identified that the DB is not available
            Noa Drach Novice

            Thanks for the pointers.

             

            I didn't implement it yet - but I did some digging around in the CLI to find the commands to use and came up with the following - just sharing for future reference or if someone think I took the wrong commands:

             

            For the data source:

             


            When the DB is down:
            /subsystem=datasources/data-source=DefaultDS/:test-connection-in-pool
            {
                "outcome" => "failed",
                "failure-description" => "JBAS010440: failed to invoke operation: JBAS010447: Connection is not valid",
                "rolled-back" => true
            }
            
            When the DB is up:
            /subsystem=datasources/data-source=DefaultDS/:test-connection-in-pool
            {
                "outcome" => "success",
                "result" => [true]
            }
            
            

             

            For the queues:


            List all the queues:
            /subsystem=messaging/hornetq-server=default/:read-children-resources(child-type=jms-queue,recursive=false,proxies=false,include-runtime=false,include-defaults=true)
            
            Pause a queue:
            /subsystem=messaging/hornetq-server=default/jms-queue=<queue name>/:pause
            
            Resume a queue:
            /subsystem=messaging/hornetq-server=default/jms-queue=<queue name>/:resume
            
            

            • 3. Re: Looking for suggestions on how to pause my application if identified that the DB is not available
              Aristides Neto Newbie

              I think that @Singleton look like a good solution, but if you are working with cluster you will have one singleton per instance holding the down flag. Therefore I suggest using infinispan to keep the value indicanting if the system is pause.

               

              The scheduled task as suggested before is a good idea to check for DB restore, you could even make you java run a script to restart the database using something like  Runtime.getRuntime().exec("restart.sh").