Configuring Clients for High Availability
Configure high availability by setting the pool attribute
subscription-redundancy to the number of copies to be maintained.
A client maintains its queue redundancy level at the time of a primary server failure by connecting to additional secondary servers.
Clients can specify the number of secondary servers where the client registers interest and maintains subscription channels, in addition to the subscription channel with the primary server. The secondary servers maintain redundant update queues for the client. If the primary server fails, a secondary becomes a primary to provide uninterrupted messaging to the client. If possible, another secondary is then initialized so the total number of secondaries is not reduced by the failover.
Setting the Server Redundancy Level in cache.xml
This example sets one redundant server as failover backup to the primary server:
<cache> <pool name="examplePool" subscription-enabled="true" subscription-redundancy="1"> <server host="java_servername1" port="java_port1" /> <server host="java_servername2" port="java_port2" /> </pool> <region name = "ThinClientRegion1" > <region-attributes refid="CACHING_PROXY" pool-name="examplePool"/> </region> </cache>
Setting the Server Redundancy Level Programmatically
You can set the redundancy level programmatically. This example creates a client cache with two redundant cache servers configured in addition to the primary server.
The server redundancy level can be configured using the pool API. For more information about the pool API, see Using Connection Pools.
PropertiesPtr pp = Properties::create( ); systemPtr = CacheFactory::createCacheFactory(pp); // Create a cache. cachePtr = systemPtr->setSubscriptionEnabled(true) ->addServer("localhost", 24680) ->addServer("localhost", 24681) ->addServer("localhost", 24682) ->setSubscriptionRedundancy(2) ->create();
When failover to a secondary server occurs, a new secondary is added to the redundancy set. If no new secondary server is found, the redundancy level is not satisfied but the failover procedure completes successfully. Any new live server is added as a secondary and interest is registered on it.