XmlBlaster Logo

REQUIREMENT

client.cpp.failsafe

XmlBlaster Logo


Type NEW
Priority HIGH
Status CLOSED
Topic The c++ client library supports failsafe reconnect where published messages are queued as long as the communication to xmlBlaster is broken.
Des
cription

Hidden inside ConnectionsHandler there is a mechanism which in asynchronous way pings xmlBlaster to check if the communication is ok. When the ping fails, or when a request to xmlBlaster fails due to communication problems, the client library tries to reestablish the connection. This is done in an asynchronous way (an own thread in ConnectionHandler). While the library tries to reconnect all publish requests are queued on ram or persistently depending on the queue/connection/type configuration.
Connect requests are queued too, provided you explicitly specify a public session id. When a connection request is queued, a faked ConnectReturnQos is returned to the client. Note that the private session id is missing but this does not create any problems since the client never uses it explicitly when invoking xmlBlaster (it is handled transparently and individually by the underlying communication protocols).

For a detailed explication of the feature have a look at the specific requirement for failsafe reconnect.

You can register a listener to be instantly notified about the connection status changes. To do so the following methods must be implemented by the object implementing the I_ConnectionProblems interface. It is the object passed in the initFailsafe(...) method in XmlBlasterAccess.

  • bool reachedAlive(StatesEnum oldState, I_ConnectionsHandler* connectionsHandler)
  • void reachedDead(StatesEnum oldState, I_ConnectionsHandler* connectionsHandler)
  • void reachedPolling(StatesEnum oldState, I_ConnectionsHandler* connectionsHandler)
As the method names suggest, these notifications are invoked after the state of the connection has been taken place. So inside these methods the user can assume that the state of the I_ConnectionHander is what the method name says (for example when reachedAlive is invoked, the state is already ALIVE).
The reachedAlive method returns a bool. If you return true the queue will be flushed, i.e. the queue entries will be dispatched to xmlBlaster. If you return false, all queue entries will be discarded.

If you don't invoke the method initFailsafe or if you pass to it a NULL pointer, then the failsafe mode and the described failsafe behavior runs silently in the client library. Note also that you must invoke initFailsafe before you invoke connect.

NOTE: To activate the failsafe mode you need to pass the command line parameter -dispatch/connection/delay with a value > 0. It is the sleeping interval in milliseconds between each reconnect retry. 5000 is a good value to start with.

Example
CPP
   



class HelloWorld2 : public I_Callback,         
                    public I_ConnectionProblems
{
   ......


   bool reachedAlive(StatesEnum, I_ConnectionsHandler*)
   {
      log_.info(ME, "reconnected");
      return true;
   }

   void reachedDead(StatesEnum, I_ConnectionsHandler*)
   {
      log_.info(ME, "lost connection");
   }

   void reachedPolling(StatesEnum, I_ConnectionsHandler*)
   {
      log_.info(ME, "going to poll modus");
   }

   ......


   void execute()
   {
      try {
         XmlBlasterAccess con(global_);

         // here you initialize the failsafe behaviour by giving
         // a pointer to the instance to notify when a state change
         // occcurs (which in this case is the 'this' object)

         con.initFailsafe(this);
         
         // do what you want to do here (connect publish subscribe)
         .....
   }

   string update(const string& sessionId, 
                 UpdateKey& updateKey, 
                 void *content, 
                 long contentSize, 
                 UpdateQos& updateQos)
   {
      log_.info(ME, "update: key: " + updateKey.toXml());
      log_.info(ME, "update: qos: " + updateQos.toXml());
      return "";
   }

};




   
   
Configure

These parameters allow to configure the C++-client on command line, over xmlBlaster.properties or over the environment (with lower priority):

Property Default / Example Description Impl
-dispatch/connection/pingInterval 10000 Ping the server every given milliseconds yes
-dispatch/connection/retries -1 How often to retry if connection fails (-1 is forever) yes
-dispatch/connection/delay 5000 Delay between connection retries in milliseconds A delay value > 0 switches fails save mode on, 0 switches it off yes

NOTE: Configuration parameters are specified on command line (-someValue 17) or in the xmlBlaster.properties file (someValue=17). See requirement "util.property" for details.
Columns named Impl tells you if the feature is implemented.
Columns named Hot tells you if the configuration is changeable in hot operation.

See REQ client.cpp
See REQ client.cpp.queue
See REQ client.failsafe

This page is generated from the requirement XML file xmlBlaster/doc/requirements/client.cpp.failsafe.xml

Back to overview