blob: 4eceebaebc7d0b9981224c0d159d4ae26c684e85 [file] [log] [blame]
---
title: Configuring Clients for High Availability
---
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
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:
``` pre
<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](../connection-pools/connection-pools.html#using-connection-pools).
``` pre
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.