spring hazelcast cache cluster showing warning - spring-boot

I have micro service architecture and all the micro services are using the same database. Now i want to have distributed cache in my architecture. For the moment i choose Hazelnut for distributed. As a start i put the following configuration in all my microservices.
#Configuration
#EnableCaching
#AutoConfigureBefore(value = { DatabaseConfiguration.class })
public class CacheConfiguration {
private final Logger LOG = LoggerFactory.getLogger(CacheConfiguration.class);
#Value("${cache.timeToLiveSeconds:3600}")
private final int timeToLiveSeconds = 3600;
#Value("${cache.backupCount:1}")
private final int backupCount = 1;
#Autowired
private Environment env;
#PreDestroy
public void destroy() {
LOG.info("Closing Cache Manager");
Hazelcast.shutdownAll();
}
#Bean
public CacheManager cacheManager(final HazelcastInstance hazelcastInstance) {
LOG.debug("Starting HazelcastCacheManager");
return new HazelcastCacheManager(hazelcastInstance);
}
#Bean
public HazelcastInstance hazelcastInstance() {
LOG.debug("Configuring Hazelcast");
final HazelcastInstance hazelCastInstance = Hazelcast
.getHazelcastInstanceByName("caching_service");
if (hazelCastInstance != null) {
LOG.debug("Hazelcast already initialized");
return hazelCastInstance;
}
final Config config = new Config();
config.setInstanceName("caching_service");
config.getNetworkConfig().setPort(5701);
config.getNetworkConfig().setPortAutoIncrement(true);
// In development, remove multicast auto-configuration
if (env.acceptsProfiles(Constants.DEV)) {
System.setProperty("hazelcast.local.localAddress", "127.0.0.1");
config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
}
config.getMapConfigs().put("default", initializeDefaultMapConfig());
return Hazelcast.newHazelcastInstance(config);
}
private MapConfig initializeDefaultMapConfig() {
final MapConfig mapConfig = new MapConfig();
/*
* Number of backups. If 1 is set as the backup-count for example, then all
* entries of the map will be copied to another JVM for fail-safety. Valid numbers
* are 0 (no backup), 1, 2, 3.
*/
mapConfig.setBackupCount(0);
/*
* Valid values are: NONE (no eviction), LRU (Least Recently Used), LFU (Least
* Frequently Used). NONE is the default.
*/
mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
/*
* Maximum size of the map. When max size is reached, map is evicted based on the
* policy defined. Any integer between 0 and Integer.MAX_VALUE. 0 means
* Integer.MAX_VALUE. Default is 0.
*/
mapConfig.setMaxSizeConfig(
new MaxSizeConfig(0, MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE));
return mapConfig;
}
}
Now i started my first micro service and the logs lines were
2017-07-16 10:38:06.581 INFO 13084 --- [ main] c.h.instance.DefaultAddressPicker : [LOCAL] [dev] [3.7.7] Picked [127.0.0.1]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
2017-07-16 10:38:06.595 INFO 13084 --- [ main] com.hazelcast.system : [127.0.0.1]:5701 [dev] [3.7.7] Hazelcast 3.7.7 (20170404 - e3c56ea) starting at [127.0.0.1]:5701
2017-07-16 10:38:06.595 INFO 13084 --- [ main] com.hazelcast.system : [127.0.0.1]:5701 [dev] [3.7.7] Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
2017-07-16 10:38:06.595 INFO 13084 --- [ main] com.hazelcast.system : [127.0.0.1]:5701 [dev] [3.7.7] Configured Hazelcast Serialization version : 1
2017-07-16 10:38:06.769 INFO 13084 --- [ main] c.h.s.i.o.impl.BackpressureRegulator : [127.0.0.1]:5701 [dev] [3.7.7] Backpressure is disabled
2017-07-16 10:38:07.171 DEBUG 13084 --- [ main] c.h.internal.cluster.ClusterService : [127.0.0.1]:5701 [dev] [3.7.7] Updating members [Member [127.0.0.1]:5701 - b2e3c44d-0392-4813-a2c8-d648695e8f1d this]
2017-07-16 10:38:07.171 DEBUG 13084 --- [ main] c.h.i.p.InternalPartitionService : [127.0.0.1]:5701 [dev] [3.7.7] Adding Member [127.0.0.1]:5701 - b2e3c44d-0392-4813-a2c8-d648695e8f1d this
2017-07-16 10:38:07.293 INFO 13084 --- [ main] c.h.s.i.o.impl.OperationExecutorImpl : [127.0.0.1]:5701 [dev] [3.7.7] Starting 8 partition threads
2017-07-16 10:38:07.295 INFO 13084 --- [ main] c.h.s.i.o.impl.OperationExecutorImpl : [127.0.0.1]:5701 [dev] [3.7.7] Starting 5 generic threads (1 dedicated for priority tasks)
2017-07-16 10:38:07.302 INFO 13084 --- [ main] com.hazelcast.core.LifecycleService : [127.0.0.1]:5701 [dev] [3.7.7] [127.0.0.1]:5701 is STARTING
2017-07-16 10:38:07.302 DEBUG 13084 --- [ main] c.h.i.p.InternalPartitionService : [127.0.0.1]:5701 [dev] [3.7.7] Adding Member [127.0.0.1]:5701 - b2e3c44d-0392-4813-a2c8-d648695e8f1d this
2017-07-16 10:38:07.303 INFO 13084 --- [ main] c.h.n.t.n.NonBlockingIOThreadingModel : [127.0.0.1]:5701 [dev] [3.7.7] TcpIpConnectionManager configured with Non Blocking IO-threading model: 3 input threads and 3 output threads
2017-07-16 10:38:07.305 DEBUG 13084 --- [ main] c.h.n.t.n.NonBlockingIOThreadingModel : [127.0.0.1]:5701 [dev] [3.7.7] IO threads selector mode is SELECT
2017-07-16 10:38:07.317 WARN 13084 --- [ main] com.hazelcast.instance.Node : [127.0.0.1]:5701 [dev] [3.7.7] No join method is enabled! Starting standalone.
2017-07-16 10:38:07.351 INFO 13084 --- [ main] com.hazelcast.core.LifecycleService : [127.0.0.1]:5701 [dev] [3.7.7] [127.0.0.1]:5701 is STARTED
Now i started my second micro service
2017-07-16 10:41:30.841 INFO 17936 --- [ main] c.h.instance.DefaultAddressPicker : [LOCAL] [dev] [3.7.7] Picked [127.0.0.1]:5702, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5702], bind any local is true
2017-07-16 10:41:30.854 INFO 17936 --- [ main] com.hazelcast.system : [127.0.0.1]:5702 [dev] [3.7.7] Hazelcast 3.7.7 (20170404 - e3c56ea) starting at [127.0.0.1]:5702
2017-07-16 10:41:30.855 INFO 17936 --- [ main] com.hazelcast.system : [127.0.0.1]:5702 [dev] [3.7.7] Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
2017-07-16 10:41:30.855 INFO 17936 --- [ main] com.hazelcast.system : [127.0.0.1]:5702 [dev] [3.7.7] Configured Hazelcast Serialization version : 1
2017-07-16 10:41:31.017 INFO 17936 --- [ main] c.h.s.i.o.impl.BackpressureRegulator : [127.0.0.1]:5702 [dev] [3.7.7] Backpressure is disabled
2017-07-16 10:41:31.451 DEBUG 17936 --- [ main] c.h.internal.cluster.ClusterService : [127.0.0.1]:5702 [dev] [3.7.7] Updating members [Member [127.0.0.1]:5702 - db64274e-73bd-4aa2-ae67-f626433b25c6 this]
2017-07-16 10:41:31.452 DEBUG 17936 --- [ main] c.h.i.p.InternalPartitionService : [127.0.0.1]:5702 [dev] [3.7.7] Adding Member [127.0.0.1]:5702 - db64274e-73bd-4aa2-ae67-f626433b25c6 this
2017-07-16 10:41:31.582 INFO 17936 --- [ main] c.h.s.i.o.impl.OperationExecutorImpl : [127.0.0.1]:5702 [dev] [3.7.7] Starting 8 partition threads
2017-07-16 10:41:31.583 INFO 17936 --- [ main] c.h.s.i.o.impl.OperationExecutorImpl : [127.0.0.1]:5702 [dev] [3.7.7] Starting 5 generic threads (1 dedicated for priority tasks)
2017-07-16 10:41:31.590 INFO 17936 --- [ main] com.hazelcast.core.LifecycleService : [127.0.0.1]:5702 [dev] [3.7.7] [127.0.0.1]:5702 is STARTING
2017-07-16 10:41:31.591 DEBUG 17936 --- [ main] c.h.i.p.InternalPartitionService : [127.0.0.1]:5702 [dev] [3.7.7] Adding Member [127.0.0.1]:5702 - db64274e-73bd-4aa2-ae67-f626433b25c6 this
2017-07-16 10:41:31.591 INFO 17936 --- [ main] c.h.n.t.n.NonBlockingIOThreadingModel : [127.0.0.1]:5702 [dev] [3.7.7] TcpIpConnectionManager configured with Non Blocking IO-threading model: 3 input threads and 3 output threads
2017-07-16 10:41:31.592 DEBUG 17936 --- [ main] c.h.n.t.n.NonBlockingIOThreadingModel : [127.0.0.1]:5702 [dev] [3.7.7] IO threads selector mode is SELECT
2017-07-16 10:41:31.633 WARN 17936 --- [ main] com.hazelcast.instance.Node : [127.0.0.1]:5702 [dev] [3.7.7] No join method is enabled! Starting standalone.
2017-07-16 10:41:31.633 WARN 17936 --- [ main] com.hazelcast.instance.Node : [127.0.0.1]:5702 [dev] [3.7.7] Config seed port is 5701 and cluster size is 1. Some of the ports seem occupied!
2017-07-16 10:41:31.663 INFO 17936 --- [ main] com.hazelcast.core.LifecycleService : [127.0.0.1]:5702 [dev] [3.7.7] [127.0.0.1]:5702 is STARTED
so i wanted to know if i am doing things right here since i get this line after started second microservice
[127.0.0.1]:5702 [dev] [3.7.7] Config seed port is 5701 and cluster size is 1. Some of the ports seem occupied!
I have the following queries
1.) Is the the right way to created Hazelcast spring distributed cache mechanism ?
2.) When i say distributed does it mean that if i have same entity cache in both the micro services , doing CRUD on entity in one micro
service will update the cache in other micro services for the same
entity as well.
3.) If i don't want to use spring cache annotations like Cacheable etc... can i remove EnableCaching or it is not a good idea. I want
to create cache programmatically and manage cache programmatically and not
by annotations.

Definitely hazecast can work in your use case.
Check this answer to similar question
https://stackoverflow.com/a/38247515/27563
Check this blogpost with caching example for spring boot.

Related

Integer Next to Log Level in Spring Boot

2021-04-27 00:27:46.292 WARN 74300 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-04-27 00:27:46.698 INFO 74300 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-04-27 00:27:47.531 INFO 74300 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-04-27 00:27:47.591 INFO 74300 --- [ main] c.s.h.MyApp : Started MyApp in 20.68 seconds (JVM running for 24.132)
What does mean INFO 74300? INFO is log level but what does mean integer next no it? It changes at every running.
That's the PID (Process Identifier)

Eureka Application starts up clean but browser gets 404 (Application is not being hosted at the expected address)?

Full log of startup is below.
When I navigate to:
http://localhost:8010/eureka
there is no log output of the event so obviously the address is bad.
...
...
My URL defined in POM is
eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka
...
...
PLEASE NOTE:
I have VirtualBox and 2 virtual ethernet adapters (that haven't even caused an issue with any springboot app before, but this is my first time running Eureka)
...
...
Console log output at startup:
2019-10-18 13:35:29.693 INFO 10428 --- [ main] .p.d.PhotoAppDiscoveryServiceApplication : No active profile set, falling back to default profiles: default
2019-10-18 13:35:30.195 WARN 10428 --- [ main] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2019-10-18 13:35:30.356 INFO 10428 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=829b0077-09b9-383d-8219-ef5903892aeb
2019-10-18 13:35:30.415 INFO 10428 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$cee4ddf2] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-10-18 13:35:30.597 INFO 10428 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8010 (http)
2019-10-18 13:35:30.616 INFO 10428 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-10-18 13:35:30.617 INFO 10428 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.26]
2019-10-18 13:35:30.724 INFO 10428 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-10-18 13:35:30.724 INFO 10428 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1019 ms
2019-10-18 13:35:30.799 WARN 10428 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-10-18 13:35:30.799 INFO 10428 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-10-18 13:35:30.805 INFO 10428 --- [ main] c.netflix.config.DynamicPropertyFactory : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration#166c2c17
2019-10-18 13:35:32.263 INFO 10428 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2019-10-18 13:35:32.470 INFO 10428 --- [ main] c.s.j.s.i.a.WebApplicationImpl : Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:08 PM'
2019-10-18 13:35:32.518 INFO 10428 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2019-10-18 13:35:32.519 INFO 10428 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/C:/Users/user/.m2/repository/com/thoughtworks/xstream/xstream/1.4.10/xstream-1.4.10.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2019-10-18 13:35:32.606 INFO 10428 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2019-10-18 13:35:32.606 INFO 10428 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2019-10-18 13:35:32.880 WARN 10428 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-10-18 13:35:32.880 INFO 10428 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-10-18 13:35:33.005 INFO 10428 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-10-18 13:35:34.458 INFO 10428 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2019-10-18 13:35:34.550 INFO 10428 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-10-18 13:35:34.568 INFO 10428 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2019-10-18 13:35:34.568 INFO 10428 --- [ main] com.netflix.discovery.DiscoveryClient : Client configured to neither register nor query for data.
2019-10-18 13:35:34.573 INFO 10428 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1571416534572 with initial instances count: 0
2019-10-18 13:35:34.595 INFO 10428 --- [ main] c.n.eureka.DefaultEurekaServerContext : Initializing ...
2019-10-18 13:35:34.596 WARN 10428 --- [ main] c.n.eureka.cluster.PeerEurekaNodes : The replica size seems to be empty. Check the route 53 DNS Registry
2019-10-18 13:35:34.606 INFO 10428 --- [ main] c.n.e.registry.AbstractInstanceRegistry : Finished initializing remote region registries. All known remote regions: []
2019-10-18 13:35:34.607 INFO 10428 --- [ main] c.n.eureka.DefaultEurekaServerContext : Initialized
2019-10-18 13:35:34.615 INFO 10428 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2019-10-18 13:35:34.669 INFO 10428 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application DISCOVERYSERVICE with eureka with status UP
2019-10-18 13:35:34.671 INFO 10428 --- [ Thread-10] o.s.c.n.e.server.EurekaServerBootstrap : Setting the eureka configuration..
2019-10-18 13:35:34.673 INFO 10428 --- [ Thread-10] o.s.c.n.e.server.EurekaServerBootstrap : Eureka data center value eureka.datacenter is not set, defaulting to default
2019-10-18 13:35:34.673 INFO 10428 --- [ Thread-10] o.s.c.n.e.server.EurekaServerBootstrap : Eureka environment value eureka.environment is not set, defaulting to test
2019-10-18 13:35:34.680 INFO 10428 --- [ Thread-10] o.s.c.n.e.server.EurekaServerBootstrap : isAws returned false
2019-10-18 13:35:34.681 INFO 10428 --- [ Thread-10] o.s.c.n.e.server.EurekaServerBootstrap : Initialized server context
2019-10-18 13:35:34.681 INFO 10428 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Got 1 instances from neighboring DS node
2019-10-18 13:35:34.681 INFO 10428 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Renew threshold is: 1
2019-10-18 13:35:34.681 INFO 10428 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP
2019-10-18 13:35:34.689 INFO 10428 --- [ Thread-10] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2019-10-18 13:35:34.703 INFO 10428 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8010 (http) with context path ''
2019-10-18 13:35:34.704 INFO 10428 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8010
2019-10-18 13:35:34.706 INFO 10428 --- [ main] .p.d.PhotoAppDiscoveryServiceApplication : Started PhotoAppDiscoveryServiceApplication in 7.989 seconds (JVM running for 8.689)
2019-10-18 13:35:36.892 INFO 10428 --- [on(1)-127.0.0.1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-10-18 13:35:36.892 INFO 10428 --- [on(1)-127.0.0.1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-10-18 13:35:36.903 INFO 10428 --- [on(1)-127.0.0.1] o.s.web.servlet.DispatcherServlet : Completed initialization in 11 ms
My App:
#SpringBootApplication
#EnableEurekaServer // "stands up a registry that other applications can talk to" https://spring.io/guides/gs/service-registration-and-discovery/
public class PhotoAppDiscoveryServiceApplication {
public static void main(String[] args) {
SpringApplication.run(PhotoAppDiscoveryServiceApplication.class, args);
}
}
My application.properties:
server.port=8010
spring.application.name=discoveryservice
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka
The defaultZone http://localhost:8010 does not host the dashboard.
http://localhost:8010 hosts the dashboard.
http://localhost:8010/eureka
is the URL for Discovery Service Replicas. In this example there is only one instance of Eureka and this is it's address.
https://cloud.spring.io/spring-cloud-netflix/multi/multi__service_discovery_eureka_clients.html
please try with this. because the defaultZone should be in camel case. and server-url should with underscore.
eureka.client.service-url.defaultZone=http://localhost:8010/eureka

2 Hazelcast Members per Spring Boot Instance

I am using Hazelcast as a Hibernate 2LC provider in my Spring Boot application in the embedded/P2P mode. Upon starting the application I could see that two members for my Hazelcast cluster are created. When I start a second instance of my whole application, another two members are created.
Currently, I use the following configuration with HazelcastCacheRegionFactory (not local).
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.region.factory_class=com.hazelcast.hibernate.HazelcastCacheRegionFactory
spring.jpa.properties.hibernate.generate_statistics=true
In the Hazelcast management centre, it looks like one member is the double of the other one. However, when starting a second instance of my Spring Boot application, both member still exist and in total they increase to four.
I already tried to set the backup count to 0 in my hazelcast.xml.
When starting the first instance of my application, I get the following logs:
2019-10-09 12:04:51.055 WARN 21088 --- [ restartedMain] c.h.instance.HazelcastInstanceFactory : Hazelcast is starting in a Java modular environment (Java 9 and newer) but without proper access to required Java packages. Use additional Java arguments to provide Hazelcast access to Java internal API. The internal API access is used to get the best performance results. Arguments to be used:
--add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED
2019-10-09 12:04:51.058 INFO 21088 --- [ restartedMain] c.h.config.AbstractConfigLocator : Loading 'hazelcast.xml' from the classpath.
2019-10-09 12:04:51.238 WARN 21088 --- [ restartedMain] c.h.config.AbstractXmlConfigHelper : Name of the hazelcast schema location is incorrect, using default
2019-10-09 12:04:51.717 INFO 21088 --- [ restartedMain] com.hazelcast.instance.AddressPicker : [LOCAL] [dev] [3.12.2] Prefer IPv4 stack is true, prefer IPv6 addresses is false
2019-10-09 12:04:53.004 INFO 21088 --- [ restartedMain] com.hazelcast.instance.AddressPicker : [LOCAL] [dev] [3.12.2] Picked [10.29.47.243]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
2019-10-09 12:04:53.016 INFO 21088 --- [ restartedMain] com.hazelcast.system : [10.29.47.243]:5701 [dev] [3.12.2] Hazelcast 3.12.2 (20190802 - e34b163) starting at [10.29.47.243]:5701
2019-10-09 12:04:53.016 INFO 21088 --- [ restartedMain] com.hazelcast.system : [10.29.47.243]:5701 [dev] [3.12.2] Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
2019-10-09 12:04:53.240 INFO 21088 --- [ restartedMain] c.h.s.i.o.impl.BackpressureRegulator : [10.29.47.243]:5701 [dev] [3.12.2] Backpressure is disabled
2019-10-09 12:04:55.174 INFO 21088 --- [ restartedMain] com.hazelcast.instance.Node : [10.29.47.243]:5701 [dev] [3.12.2] Creating MulticastJoiner
2019-10-09 12:04:55.313 INFO 21088 --- [ restartedMain] c.h.s.i.o.impl.OperationExecutorImpl : [10.29.47.243]:5701 [dev] [3.12.2] Starting 4 partition threads and 3 generic threads (1 dedicated for priority tasks)
2019-10-09 12:04:55.314 INFO 21088 --- [ restartedMain] c.h.internal.diagnostics.Diagnostics : [10.29.47.243]:5701 [dev] [3.12.2] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
2019-10-09 12:04:55.328 INFO 21088 --- [ restartedMain] com.hazelcast.core.LifecycleService : [10.29.47.243]:5701 [dev] [3.12.2] [10.29.47.243]:5701 is STARTING
2019-10-09 12:04:57.466 INFO 21088 --- [ restartedMain] c.h.internal.cluster.ClusterService : [10.29.47.243]:5701 [dev] [3.12.2]
Members {size:1, ver:1} [
Member [10.29.47.243]:5701 - bf933bd9-9214-4022-a104-514bc5f56267 this
]
2019-10-09 12:04:57.486 INFO 21088 --- [ restartedMain] c.h.i.m.ManagementCenterService : [10.29.47.243]:5701 [dev] [3.12.2] Hazelcast will connect to Hazelcast Management Center on address:
http://localhost:8080/hazelcast-mancenter
2019-10-09 12:04:57.495 INFO 21088 --- [ restartedMain] com.hazelcast.core.LifecycleService : [10.29.47.243]:5701 [dev] [3.12.2] [10.29.47.243]:5701 is STARTED
2019-10-09 12:04:57.544 INFO 21088 --- [MC.State.Sender] com.hazelcast.client.impl.ClientEngine : [10.29.47.243]:5701 [dev] [3.12.2] Applying a new client selector :ClientSelector{any}
2019-10-09 12:04:57.651 INFO 21088 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-10-09 12:04:58.089 INFO 21088 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-10-09 12:04:58.163 INFO 21088 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-10-09 12:04:58.274 INFO 21088 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.3.10.Final}
2019-10-09 12:04:58.276 INFO 21088 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-10-09 12:04:58.533 INFO 21088 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-10-09 12:04:58.777 INFO 21088 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2019-10-09 12:04:59.122 INFO 21088 --- [ restartedMain] c.h.h.HazelcastCacheRegionFactory : Starting up HazelcastCacheRegionFactory
2019-10-09 12:04:59.124 INFO 21088 --- [ restartedMain] c.h.config.AbstractConfigLocator : Loading 'hazelcast.xml' from the classpath.
2019-10-09 12:04:59.127 WARN 21088 --- [ restartedMain] c.h.config.AbstractXmlConfigHelper : Name of the hazelcast schema location is incorrect, using default
2019-10-09 12:04:59.165 INFO 21088 --- [ restartedMain] com.hazelcast.instance.AddressPicker : [LOCAL] [dev] [3.12.2] Prefer IPv4 stack is true, prefer IPv6 addresses is false
2019-10-09 12:04:59.949 INFO 21088 --- [ restartedMain] com.hazelcast.instance.AddressPicker : [LOCAL] [dev] [3.12.2] Picked [10.29.47.243]:5703, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5703], bind any local is true
2019-10-09 12:04:59.950 INFO 21088 --- [ restartedMain] com.hazelcast.system : [10.29.47.243]:5703 [dev] [3.12.2] Hazelcast 3.12.2 (20190802 - e34b163) starting at [10.29.47.243]:5703
2019-10-09 12:04:59.950 INFO 21088 --- [ restartedMain] com.hazelcast.system : [10.29.47.243]:5703 [dev] [3.12.2] Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
2019-10-09 12:04:59.956 INFO 21088 --- [ restartedMain] c.h.s.i.o.impl.BackpressureRegulator : [10.29.47.243]:5703 [dev] [3.12.2] Backpressure is disabled
2019-10-09 12:05:01.343 INFO 21088 --- [ restartedMain] com.hazelcast.instance.Node : [10.29.47.243]:5703 [dev] [3.12.2] Creating MulticastJoiner
2019-10-09 12:05:01.348 INFO 21088 --- [ restartedMain] c.h.s.i.o.impl.OperationExecutorImpl : [10.29.47.243]:5703 [dev] [3.12.2] Starting 4 partition threads and 3 generic threads (1 dedicated for priority tasks)
2019-10-09 12:05:01.349 INFO 21088 --- [ restartedMain] c.h.internal.diagnostics.Diagnostics : [10.29.47.243]:5703 [dev] [3.12.2] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
2019-10-09 12:05:01.349 INFO 21088 --- [ restartedMain] com.hazelcast.core.LifecycleService : [10.29.47.243]:5703 [dev] [3.12.2] [10.29.47.243]:5703 is STARTING
2019-10-09 12:05:01.473 INFO 21088 --- [ restartedMain] c.h.i.cluster.impl.MulticastJoiner : [10.29.47.243]:5703 [dev] [3.12.2] Trying to join to discovered node: [10.29.47.243]:5701
2019-10-09 12:05:01.478 INFO 21088 --- [cached.thread-2] com.hazelcast.nio.tcp.TcpIpConnector : [10.29.47.243]:5703 [dev] [3.12.2] Connecting to /10.29.47.243:5701, timeout: 10000, bind-any: true
2019-10-09 12:05:01.486 INFO 21088 --- [.IO.thread-in-0] com.hazelcast.nio.tcp.TcpIpConnection : [10.29.47.243]:5701 [dev] [3.12.2] Initialized new cluster connection between /10.29.47.243:5701 and /10.29.47.243:51948
2019-10-09 12:05:01.487 INFO 21088 --- [.IO.thread-in-0] com.hazelcast.nio.tcp.TcpIpConnection : [10.29.47.243]:5703 [dev] [3.12.2] Initialized new cluster connection between /10.29.47.243:51948 and /10.29.47.243:5701
2019-10-09 12:05:07.483 INFO 21088 --- [ration.thread-0] c.h.internal.cluster.ClusterService : [10.29.47.243]:5701 [dev] [3.12.2]
Members {size:2, ver:2} [
Member [10.29.47.243]:5701 - bf933bd9-9214-4022-a104-514bc5f56267 this
Member [10.29.47.243]:5703 - 9862ded6-c26d-4da8-929f-f8616a4bf633
]
2019-10-09 12:05:07.489 INFO 21088 --- [ration.thread-0] c.h.internal.cluster.ClusterService : [10.29.47.243]:5703 [dev] [3.12.2]
Members {size:2, ver:2} [
Member [10.29.47.243]:5701 - bf933bd9-9214-4022-a104-514bc5f56267
Member [10.29.47.243]:5703 - 9862ded6-c26d-4da8-929f-f8616a4bf633 this
]
2019-10-09 12:05:08.481 WARN 21088 --- [ restartedMain] com.hazelcast.instance.Node : [10.29.47.243]:5703 [dev] [3.12.2] Config seed port is 5701 and cluster size is 2. Some of the ports seem occupied!
2019-10-09 12:05:08.482 INFO 21088 --- [ restartedMain] c.h.i.m.ManagementCenterService : [10.29.47.243]:5703 [dev] [3.12.2] Hazelcast will connect to Hazelcast Management Center on address:
http://localhost:8080/hazelcast-mancenter
2019-10-09 12:05:08.487 INFO 21088 --- [ restartedMain] com.hazelcast.core.LifecycleService : [10.29.47.243]:5703 [dev] [3.12.2] [10.29.47.243]:5703 is STARTED
How could I solve the issue of having two members per application instance? Is there an actual use of having two members per instance?
Solution by #Mesut
I added the following statement in the application.properties file of Spring Boot (config could be placed elsewhere).
spring.jpa.properties.hibernate.cache.hazelcast.instance_name=your-instance-name
You also have to create a bean with the name 'your-instance-name'. In Spring Boot this could be achieved by annotating a method which returns a Hazelcast instance with #Bean. This could be done in your main class or a #Configuration class.
#Bean
public Config hazelcastConfig() {
Config config = new Config();
config.setInstanceName("your-instance-name");
config.setProperty("hazelcast.phone.home.enabled", "false");
return config;
}
#Bean
public HazelcastInstance hazelcastInstance(Config config) {
return Hazelcast.newHazelcastInstance(config);
}
This results in having only one member per instance of your application (very good). However, the connection to the management centre does not work anymore (not that important in my situation).
If you wanna share the same instance, you should be using the same instance name in both hibernate config and hazelcast.xml.
hibernate.cache.hazelcast.instance_name is the configuration parameter in hibernate side.
You can check documentation here for more info.

Hazelcast cluster not available on Eureka

I had a problem configuring simple Hazelcast cluster for existing Eureka client.
My application is simple Java SpringBoot application with Eureka discovery enabled, it is properly available for Eureka, however Hazelcast cluster is not.
This is my configuration:
hazelcast.xml
<hazelcast
xsi:schemaLocation="http://www.hazelcast.com/schema/config http://www.hazelcast.com/schema/config/hazelcast-config-3.9.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<properties>
<property name="hazelcast.discovery.enabled">true</property>
<property name="hazelcast.jmx">true</property>
<property name="hazelcast.http.healthcheck.enabled">true</property>
<property name="hazelcast.rest.enabled">true</property>
<property name="hazelcast.logging.type">slf4j</property>
<property name="hazelcast.diagnostics.enabled">true</property>
<property name="hazelcast.diagnostics.metric.level">info</property>
<property name="hazelcast.name">hazelcast-cluster</property>
</properties>
<group>
<name>xxxx</name>
<password>xx</password>
</group>
<instance-name>hazelcast-cluster</instance-name>
<network>
<join>
<multicast enabled="false"/>
<tcp-ip enabled="false"/>
<aws enabled="false"/>
<discovery-strategies>
<discovery-strategy class="com.hazelcast.eureka.one.EurekaOneDiscoveryStrategy" enabled="true">
<properties>
<property name="self-registration">true</property>
<property name="namespace">hazelcast</property>
</properties>
</discovery-strategy>
</discovery-strategies>
</join>
</network>
maps....
</hazelcast>
Spring boot application:
#SpringBootApplication
#EnableAutoConfiguration ( exclude = { WebMvcAutoConfiguration.class } )
#EnableDiscoveryClient
#EnableEurekaClient
public class HazelcastClusterApplication {
public static void main( String[] args ) {
SpringApplication.run( HazelcastClusterApplication.class, args );
}
}
Configuration class:
#Configuration
public class HazelcastInstanceConfiguration {
#Bean
public HazelcastInstance hazelcastInstance(Config config, EurekaClient eurekaClient) {
EurekaOneDiscoveryStrategyFactory.setEurekaClient( eurekaClient );
return Hazelcast.newHazelcastInstance(config);
}
#Bean
public Config config() {
Config config = new ClasspathXmlConfig( "hazelcast.xml" );
return config;
}
}
bootstrap.yml
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8011/eureka/
register-with-eureka: true
spring:
mvc:
favicon:
enabled: false
application:
name: cache-server
cloud:
config:
discovery:
enabled: true
serviceId: config-server
failFast: false
retry:
initialInterval: 10000
maxInterval: 60000
maxAttempts: 12
multiplier: 10.1
config:
name: application.*, ${spring.application.name}*.*
server:
port: 7990
Maven dependencies:
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-eureka-one</artifactId>
<version>1.0.2</version>
</dependency>
After running, 'cache-server' application is available on Eureka, however I guess also 'hazelcast-cluster' should be available, but it is not. Or my assumption is wrong?
Startup logs:
INFO 17628 --- [ main] c.h.s.d.integration.DiscoveryService : [10.230.115.128]:5701 [xxxx] [3.11] Waiting for registration with Eureka...
INFO 17628 --- [ main] c.h.s.d.integration.DiscoveryService : [10.230.115.128]:5701 [xxxx] [3.11] Waiting for registration with Eureka...
INFO 17628 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CACHE-SERVER/pc_data:cache-server:7990: registering service...
INFO 17628 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CACHE-SERVER/pc_data:cache-server:7990 - registration status: 204
INFO 17628 --- [ main] c.h.s.d.integration.DiscoveryService : [10.230.115.128]:5701 [xxxx] [3.11] Waiting for registration with Eureka...
DEBUG 17628 --- [ main] c.h.i.cluster.impl.DiscoveryJoiner : [10.230.115.128]:5701 [xxxx] [3.11] This node will assume master role since no possible member where connected to.
DEBUG 17628 --- [ main] c.h.internal.cluster.ClusterService : [10.230.115.128]:5701 [xxxx] [3.11] Setting master address to [10.230.115.128]:5701
DEBUG 17628 --- [ main] c.h.i.cluster.impl.MembershipManager : [10.230.115.128]:5701 [xxxx] [3.11] Local member list join version is set to 1
DEBUG 17628 --- [ main] c.h.i.cluster.impl.DiscoveryJoiner : [10.230.115.128]:5701 [xxxx] [3.11] PostJoin master: [10.230.115.128]:5701, isMaster: true
INFO 17628 --- [ main] c.h.internal.cluster.ClusterService : [10.230.115.128]:5701 [xxxx] [3.11]
Members {size:1, ver:1} [
Member [10.230.115.128]:5701 - f6ed031e-5740-4daa-b583-5b91d98816c2 this
]
And then my cache-server application is available on Eureka, but not hazelcast-cluster as I guess it should.
Hazelcast client service logs (cutted):
2018-12-11 09:48:01.673 INFO [security-service,,,] 21496 --- [ main] com.hazelcast.client.HazelcastClient : hz.client_0 [xxxx] [3.11] A non-empty group password is configured for the Hazelcast client. Starting with Hazelcast version 3.11, clients with the same group name, but with different group passwords (that do not use authentication) will be accepted to a cluster. The group password configuration will be removed completely in a future release.
2018-12-11 09:48:01.700 INFO [security-service,,,] 21496 --- [ main] com.hazelcast.core.LifecycleService : hz.client_0 [xxxx] [3.11] HazelcastClient 3.11 (20181023 - 1500bbb) is STARTING
2018-12-11 09:48:03.233 INFO [security-service,,,] 21496 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2018-12-11 09:48:03.249 INFO [security-service,,,] 21496 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2018-12-11 09:48:03.264 INFO [security-service,,,] 21496 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2018-12-11 09:48:03.266 INFO [security-service,,,] 21496 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2018-12-11 09:48:03.267 INFO [security-service,,,] 21496 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2018-12-11 09:48:03.267 INFO [security-service,,,] 21496 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2018-12-11 09:48:03.417 INFO [security-service,,,] 21496 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2018-12-11 09:48:03.421 INFO [security-service,,,] 21496 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2018-12-11 09:48:03.421 INFO [security-service,,,] 21496 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2018-12-11 09:48:03.422 INFO [security-service,,,] 21496 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2018-12-11 09:48:03.422 INFO [security-service,,,] 21496 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
2018-12-11 09:48:03.423 INFO [security-service,,,] 21496 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2018-12-11 09:48:03.424 INFO [security-service,,,] 21496 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2018-12-11 09:48:03.424 INFO [security-service,,,] 21496 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2018-12-11 09:48:03.426 INFO [security-service,,,] 21496 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200
2018-12-11 09:48:03.426 INFO [security-service,,,] 21496 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 5
2018-12-11 09:48:03.426 INFO [security-service,,,] 21496 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2018-12-11 09:48:03.442 INFO [security-service,,,] 21496 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1544518083442 with initial instances count: 3
2018-12-11 09:48:03.488 INFO [security-service,,,] 21496 --- [ main] c.h.s.d.integration.DiscoveryService : hz.client_0 [xxxx] [3.11] Waiting for registration with Eureka...
2018-12-11 09:48:08.468 INFO [security-service,,,] 21496 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_SECURITY-SERVICE/GPLPLW2002.gft.com:security-service:8035 - Re-registering apps/SECURITY-SERVICE
2018-12-11 09:48:08.468 INFO [security-service,,,] 21496 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_SECURITY-SERVICE/GPLPLW2002.gft.com:security-service:8035: registering service...
2018-12-11 09:48:08.499 INFO [security-service,,,] 21496 --- [ main] c.h.s.d.integration.DiscoveryService : hz.client_0 [xxxx] [3.11] Waiting for registration with Eureka...
2018-12-11 09:48:08.530 INFO [security-service,,,] 21496 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_SECURITY-SERVICE/GPLPLW2002.gft.com:security-service:8035 - registration status: 204
2018-12-11 09:48:13.500 INFO [security-service,,,] 21496 --- [ main] c.h.s.d.integration.DiscoveryService : hz.client_0 [xxxx] [3.11] Waiting for registration with Eureka...
2018-12-11 09:48:18.503 INFO [security-service,,,] 21496 --- [ main] c.h.s.d.integration.DiscoveryService : hz.client_0 [xxxx] [3.11] Waiting for registration with Eureka...
2018-12-11 09:48:23.512 INFO [security-service,,,] 21496 --- [ main] c.h.s.d.integration.DiscoveryService : hz.client_0 [xxxx] [3.11] Waiting for registration with Eureka...
2018-12-11 09:48:28.513 INFO [security-service,,,] 21496 --- [ main] c.h.s.d.integration.DiscoveryService : hz.client_0 [xxxx] [3.11] Waiting for registration with Eureka...
2018-12-11 09:48:33.515 INFO [security-service,,,] 21496 --- [ main] c.h.s.d.integration.DiscoveryService : hz.client_0 [xxxx] [3.11] Waiting for registration with Eureka...
2018-12-11 09:48:33.557 INFO [security-service,,,] 21496 --- [ main] c.h.client.spi.ClientInvocationService : hz.client_0 [xxxx] [3.11] Running with 2 response threads
2018-12-11 09:48:33.742 INFO [security-service,,,] 21496 --- [ main] com.hazelcast.core.LifecycleService : hz.client_0 [xxxx] [3.11] HazelcastClient 3.11 (20181023 - 1500bbb) is STARTED
2018-12-11 09:48:33.772 DEBUG [security-service,,,] 21496 --- [ main] c.h.i.networking.nio.NioNetworking : hz.client_0 [xxxx] [3.11] TcpIpConnectionManager configured with Non Blocking IO-threading model: 1 input threads and 1 output threads
2018-12-11 09:48:33.774 DEBUG [security-service,,,] 21496 --- [ main] c.h.i.networking.nio.NioNetworking : hz.client_0 [xxxx] [3.11] IO threads selector mode is SELECT
2018-12-11 09:48:33.818 WARN [security-service,,,] 21496 --- [ient_0.cluster-] c.h.c.c.ClientConnectionManager : hz.client_0 [xxxx] [3.11] Unable to get alive cluster connection, try in 3000 ms later, attempt 1 of 2.
2018-12-11 09:48:36.822 WARN [security-service,,,] 21496 --- [ient_0.cluster-] c.h.c.c.ClientConnectionManager : hz.client_0 [xxxx] [3.11] Unable to get alive cluster connection, attempt 2 of 2.
2018-12-11 09:48:36.824 WARN [security-service,,,] 21496 --- [ient_0.cluster-] c.h.c.c.ClientConnectionManager : hz.client_0 [xxxx] [3.11] Could not connect to cluster, shutting down the client. Unable to connect to any address! The following addresses were tried: []
2018-12-11 09:48:36.828 INFO [security-service,,,] 21496 --- [clientShutdown-] com.hazelcast.core.LifecycleService : hz.client_0 [xxxx] [3.11] HazelcastClient 3.11 (20181023 - 1500bbb) is SHUTTING_DOWN
2018-12-11 09:48:36.839 INFO [security-service,,,] 21496 --- [clientShutdown-] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2018-12-11 09:48:36.843 INFO [security-service,,,] 21496 --- [clientShutdown-] com.netflix.discovery.DiscoveryClient : Unregistering ...
2018-12-11 09:48:36.844 WARN [security-service,,,] 21496 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: o.....org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cacheManager' defined in class path resource
.......
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hazelcastInstance' defined in class path resource [xxxx/hazelcast/HazelcastClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.hazelcast.core.HazelcastInstance]: Factory method 'hazelcastInstance' threw exception; nested exception is java.lang.IllegalStateException: Unable to connect to any address! The following addresses were tried: []
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
... 150 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.hazelcast.core.HazelcastInstance]: Factory method 'hazelcastInstance' threw exception; nested exception is java.lang.IllegalStateException: Unable to connect to any address! The following addresses were tried: []
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 163 common frames omitted
Caused by: java.lang.IllegalStateException: Unable to connect to any address! The following addresses were tried: []
at com.hazelcast.client.connection.nio.ClusterConnector.connectToClusterInternal(ClusterConnector.java:206)
at com.hazelcast.client.connection.nio.ClusterConnector.access$400(ClusterConnector.java:56)
at com.hazelcast.client.connection.nio.ClusterConnector$2.call(ClusterConnector.java:215)
at com.hazelcast.client.connection.nio.ClusterConnector$2.call(ClusterConnector.java:211)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:64)
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:80)
What is wrong with my configuration, is this a server problem or client?
Client configuration:
#Bean
#Autowired
public HazelcastInstance hazelcastInstance( EurekaClient eurekaClient, GroupConfig groupConfig ) {
EurekaOneDiscoveryStrategyFactory.setEurekaClient( eurekaClient );
ClientConfig config = new ClientConfig();
config.setGroupConfig( groupConfig );
config.setProperty( "hazelcast.discovery.enabled", "true" );
DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig( new EurekaOneDiscoveryStrategyFactory() );
discoveryStrategyConfig.addProperty( "use-classpath-eureka-client-props", "false" );
discoveryStrategyConfig.addProperty( "self-registration", "false" );
DiscoveryConfig discoveryConfig = new DiscoveryConfig();
discoveryConfig.addDiscoveryStrategyConfig( discoveryStrategyConfig );
config.getNetworkConfig().setDiscoveryConfig( discoveryConfig );
return HazelcastClient.newHazelcastClient( config );
}
The problem is that you use the same EurekaClient for you app discovery (port 7990) and your Hazelcast discovery (port 5701). For more information, read the related GH issue.
You can solve it in two ways:
Use the property use-metadata-for-host-and-port as described here
Use separate Eureka Client and ports for your app and Hazelcast
EDIT: The use-metadata-for-host-and-port will be released in hazelcast-eureka:1.0.3 soon. I've also prepared Hazelcast Eureka Code Sample.
Have you seen the example configs in Eureka plugin repo and also the code sample with Eureka? I see there are some differences in the configs with yours. Please check and let me know if you still have problems.

Spring Boot with Hazelcast and Tomcat

How do you use Hazelcast as a http session store with embedded Tomcat with Spring Boot and Spring Security? I see there is a EmbeddedServletContainerCustomizer and SpringAwareWebFilter but I don't understand how to use it.
As described in Hazelcast's documentation, you need to configure Hazelcast's SpringAwareWebFilter and SessionListener. You can do so in Spring Boot by declaring a FilterRegistrationBean and a ServletListenerRegistrationBean respectively:
#Bean
public FilterRegistrationBean hazelcastFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean(new SpringAwareWebFilter());
registration.addUrlPatterns("/*");
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE);
// Configure init parameters as appropriate:
// registration.addInitParameter("foo", "bar");
return registration;
}
#Bean
public ServletListenerRegistrationBean<SessionListener> hazelcastSessionListener() {
return new ServletListenerRegistrationBean<SessionListener>(new SessionListener());
}
SpringAwareWebFilter and SessionListener are both in Hazelcast's hazelcast-wm module so you'll need to add a dependency on com.hazelcast:hazelcast-wm to your pom.xml or build.gradle. hazelcast-wm also requires Spring Security to be on the classpath.
Now, when you run your application, you should see log output from Hazelcast during startup that's similar to the following:
2014-12-17 10:29:32.401 INFO 94332 --- [ost-startStop-1] com.hazelcast.config.XmlConfigLocator : Loading 'hazelcast-default.xml' from classpath.
2014-12-17 10:29:32.435 INFO 94332 --- [ost-startStop-1] c.hazelcast.web.HazelcastInstanceLoader : Creating a new HazelcastInstance for session replication
2014-12-17 10:29:32.582 INFO 94332 --- [ost-startStop-1] c.h.instance.DefaultAddressPicker : [LOCAL] [dev] [3.3.3] Prefer IPv4 stack is true.
2014-12-17 10:29:32.590 INFO 94332 --- [ost-startStop-1] c.h.instance.DefaultAddressPicker : [LOCAL] [dev] [3.3.3] Picked Address[169.254.144.237]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
2014-12-17 10:29:32.612 INFO 94332 --- [ost-startStop-1] c.h.spi.impl.BasicOperationScheduler : [169.254.144.237]:5701 [dev] [3.3.3] Starting with 16 generic operation threads and 16 partition operation threads.
2014-12-17 10:29:32.657 INFO 94332 --- [ost-startStop-1] com.hazelcast.system : [169.254.144.237]:5701 [dev] [3.3.3] Hazelcast 3.3.3 (20141112 - eadb69c) starting at Address[169.254.144.237]:5701
2014-12-17 10:29:32.657 INFO 94332 --- [ost-startStop-1] com.hazelcast.system : [169.254.144.237]:5701 [dev] [3.3.3] Copyright (C) 2008-2014 Hazelcast.com
2014-12-17 10:29:32.661 INFO 94332 --- [ost-startStop-1] com.hazelcast.instance.Node : [169.254.144.237]:5701 [dev] [3.3.3] Creating MulticastJoiner
2014-12-17 10:29:32.664 INFO 94332 --- [ost-startStop-1] com.hazelcast.core.LifecycleService : [169.254.144.237]:5701 [dev] [3.3.3] Address[169.254.144.237]:5701 is STARTING
2014-12-17 10:29:38.482 INFO 94332 --- [ost-startStop-1] com.hazelcast.cluster.MulticastJoiner : [169.254.144.237]:5701 [dev] [3.3.3]
Members [1] {
Member [169.254.144.237]:5701 this
}
2014-12-17 10:29:38.503 INFO 94332 --- [ost-startStop-1] com.hazelcast.core.LifecycleService : [169.254.144.237]:5701 [dev] [3.3.3] Address[169.254.144.237]:5701 is STARTED
Why not uses Spring-session? It is pretty easy.
Instead of using Tomcat’s HttpSession, we are actually persisting the values in Redis. Spring Session replaces the HttpSession with an implementation that is backed by Redis. When Spring Security’s SecurityContextPersistenceFilter saves the SecurityContext to the HttpSession it is then persisted into Redis.
#EnableRedisHttpSession
public class HttpSessionConfig {
}
#src/main/resources/application.properties
spring.redis.host=localhost
spring.redis.password=secret
spring.redis.port=6379
http://docs.spring.io/spring-session/docs/current/reference/html5/guides/boot.html

Resources