在 Ignite 服务器上已经有配置时在 Ignite 客户端上有相同的配置
Having same configuration on Ignite client when already have configuration on Ignite server
好的
这是我的 Ignite 服务器配置代码。
@Bean("serverCfg")
public IgniteConfiguration createConfiguration() throws Exception {
IgniteConfiguration cfg = new IgniteConfiguration(); cfg.setIgniteInstanceName("CcPlatformUserRolesOrganizationAssociationServer");
cfg.setSqlSchemas("public");
TcpDiscoverySpi discovery = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new
TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500..47510"));
discovery.setIpFinder(ipFinder);
cfg.setDiscoverySpi(discovery);
// cfg.setPeerClassLoadingEnabled(true);
cfg.setCacheConfiguration(cacheOrganizationsCache()
,
cacheRolesCache(), cacheUsersCache(),
cacheUsersRolesCache(), cacheGroupsCache(),
cacheGroupusersCache(), cacheGlobalPermissionsCache(),
cacheTemplatesCache(), cachePasswordsCache()
);
return cfg;
}
这是我的 Ignite 客户端代码。
@Bean
public Ignite createConfiguration() throws Exception {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setClientMode(true); cfg.setIgniteInstanceName("CcPlatformUserRolesOrganizationAssociationServerClient");
TcpDiscoverySpi discovery = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new
TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500..47510"));
discovery.setIpFinder(ipFinder);
cfg.setDiscoverySpi(discovery);
cfg.setCacheConfiguration( cacheOrganizationsCache(), cacheRolesCache(),
cacheUsersCache(), cacheUsersRolesCache(), cacheGroupsCache(),
cacheGroupusersCache() );
Ignite ignite = Ignition.start(cfg);
ignite.cluster().active(true);
return ignite;
}
所以我的问题是我是否必须有相同的代码段来包含所有缓存配置,包括客户端的数据源?
如何避免这种代码冗余?
您不必在客户端提供所有缓存配置。一旦第一个服务器节点出现,它将启动所有缓存,其他节点将能够使用它们,无论它们是否在自己的配置中。节点加入时将创建任何新的缓存。加入具有不同现有缓存 cfg 的新节点时,缓存配置永远不会更改。
好的 这是我的 Ignite 服务器配置代码。
@Bean("serverCfg")
public IgniteConfiguration createConfiguration() throws Exception {
IgniteConfiguration cfg = new IgniteConfiguration(); cfg.setIgniteInstanceName("CcPlatformUserRolesOrganizationAssociationServer");
cfg.setSqlSchemas("public");
TcpDiscoverySpi discovery = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new
TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500..47510"));
discovery.setIpFinder(ipFinder);
cfg.setDiscoverySpi(discovery);
// cfg.setPeerClassLoadingEnabled(true);
cfg.setCacheConfiguration(cacheOrganizationsCache()
,
cacheRolesCache(), cacheUsersCache(),
cacheUsersRolesCache(), cacheGroupsCache(),
cacheGroupusersCache(), cacheGlobalPermissionsCache(),
cacheTemplatesCache(), cachePasswordsCache()
);
return cfg;
}
这是我的 Ignite 客户端代码。
@Bean
public Ignite createConfiguration() throws Exception {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setClientMode(true); cfg.setIgniteInstanceName("CcPlatformUserRolesOrganizationAssociationServerClient");
TcpDiscoverySpi discovery = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new
TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500..47510"));
discovery.setIpFinder(ipFinder);
cfg.setDiscoverySpi(discovery);
cfg.setCacheConfiguration( cacheOrganizationsCache(), cacheRolesCache(),
cacheUsersCache(), cacheUsersRolesCache(), cacheGroupsCache(),
cacheGroupusersCache() );
Ignite ignite = Ignition.start(cfg);
ignite.cluster().active(true);
return ignite;
}
所以我的问题是我是否必须有相同的代码段来包含所有缓存配置,包括客户端的数据源? 如何避免这种代码冗余?
您不必在客户端提供所有缓存配置。一旦第一个服务器节点出现,它将启动所有缓存,其他节点将能够使用它们,无论它们是否在自己的配置中。节点加入时将创建任何新的缓存。加入具有不同现有缓存 cfg 的新节点时,缓存配置永远不会更改。