Configuring the Multiple-Hub Site
These tables list the new configuration attributes for multi-site load balancing.
Gateway Hub Attribute
Specifies whether the hub should attempt to start as primary or secondary hub. Valid values are primary, secondary, and none.
For multiple-hub systems this must be specified. If it is not, region events go to all available hubs, which results in duplicate sends to remote sites.
The cache.xml in this example defines the gateway hub configurations for VM1 in Two-Hub Configuration With Primaries in Different VMs.
Two-Hub Gateway Hub Configuration in cache.xml<cache><gateway-hub id="Site1a" port="22222" startup-policy="secondary">...</gateway-hub><gateway-hub id="Site1b" port="22223" startup-policy="primary">...</gateway-hub>
This shows the API equivalent.
Two-Hub Gateway Hub Configuration Through the API// Create or obtain the GemFire cacheCache cache = ... ;// Create the first Gateway HubGatewayHub site1aHub = cache.setGatewayHub("Site1a", 22222);site1aHub.setStartupPolicy("STARTUP_POLICY_SECONDARY");// Create the second Gateway HubGatewayHub site1bHub = cache.setGatewayHub("Site1b", 22223);site1bHub.setStartupPolicy("STARTUP_POLICY_PRIMARY");// Define gateways and endpoints for the gateway hubs ...
When you use multiple hubs, you must point each gateway-enabled region at one of the hubs. If you do not specify a hub, region events are delivered to every hub and then sent to remote sites by each hub’s primary instance. The region configuration must be consistent across the distributed system, even in caches where there are no hubs running.
Split region events between your hubs as evenly as you can. If you have two hubs and three regions, for example, with one region having the bulk of the events, put that region on one hub and the others on the other hub.
This cache.xml assigns the example regions in Two-Hub Configuration With Primaries in Different VMs to their respective hubs.
Enabling Region Communication With Gateway Hubs in cache.xml<region name="A"><region-attributes ... enable-gateway="true" hub-id="Site1a"/>...</region><region name="B"><region-attributes ... enable-gateway="true" hub-id="Site1b"/>...</region>
This is the same configuration through the API.
Enabling Region Communication With a Gateway Hub Through the API// Region AAttributesFactory factory = new AttributesFactory();factory.setEnableGateway(new Boolean(true));factory.setGatewayHubId("Site1a");Region multiSiteRegionA = cache.createRegion("A", factory.create());// Region BAttributesFactory factory = new AttributesFactory();factory.setEnableGateway(new Boolean(true));factory.setGatewayHubId("Site1b");Region multiSiteRegionB = cache.createRegion("B", factory.create());