Search code examples
spring-bootapache-camelhazelcast

Hazelcast in Spring Boot ignoring my NetworkConfig


I'm using Hazelcast as my main data store backed by JPA to a database. I'm trying to get it to not use multicast to find other instances in our development environment since we're working on different classes, etc. and pointing at our own databases, but Hazelcast is still connecting up. I know it's calling my HazelcastConfiguration class, but it's also using the hazelcast-defaults.xml in the jar file and creating a cluster.

@Bean(name = "hazelcastInstance")
public HazelcastInstance getHazelcastInstance(Config config) {
  return new HazelcastInstanceFactory(config).getHazelcastInstance();
}

@Bean(name = "hazelCastConfig")
public Config config ()
{
  MapConfig userMapConfig = buildUserMapConfig();
  ...
  Config config = new Config();
  config.setNetworkConfig(buildNetworkConfig());
  return config;
}

private NetworkConfig buildNetworkConfig () {
  NetworkConfig networkConfig = new NetworkConfig();
  JoinConfig join = new JoinConfig();
  MulticastConfig multicastConfig = new MulticastConfig();
  multicastConfig.setEnabled(false);
  join.setMulticastConfig(multicastConfig);
  TcpIpConfig tcpIpConfig = new TcpIpConfig();
  tcpIpConfig.setEnabled(false);
  join.setTcpIpConfig(tcpIpConfig);
  networkConfig.setJoin(join);
  return networkConfig;
}

Now I can see that these are being called and it has to be using my configuration because the entities get backed to my database, but I also get this at startup:

2017-06-20 14:41:24.311  INFO 3741 --- [           main] c.h.i.cluster.impl.MulticastJoiner       : [10.10.0.125]:5702 [dev] [3.8.1] Trying to join to discovered node: [10.10.0.127]:5702
2017-06-20 14:41:34.870  INFO 3741 --- [ached.thread-14] c.hazelcast.nio.tcp.InitConnectionTask   : [10.10.0.125]:5702 [dev] [3.8.1] Connecting to /10.10.0.127:5702, timeout: 0, bind-any: true
2017-06-20 14:41:34.972  INFO 3741 --- [ached.thread-14] c.h.nio.tcp.TcpIpConnectionManager       : [10.10.0.125]:5702 [dev] [3.8.1] Established socket connection between /10.10.0.125:54917 and /10.10.0.127:5702
2017-06-20 14:41:41.181  INFO 3741 --- [thread-Acceptor] c.h.nio.tcp.SocketAcceptorThread         : [10.10.0.125]:5702 [dev] [3.8.1] Accepting socket connection from /10.10.0.146:60449
2017-06-20 14:41:41.183  INFO 3741 --- [ached.thread-21] c.h.nio.tcp.TcpIpConnectionManager       : [10.10.0.125]:5702 [dev] [3.8.1] Established socket connection between /10.10.0.125:5702 and /10.10.0.146:60449
2017-06-20 14:41:41.185  INFO 3741 --- [ration.thread-0] com.hazelcast.system                     : [10.10.0.125]:5702 [dev] [3.8.1] Cluster version set to 3.8
2017-06-20 14:41:41.187  INFO 3741 --- [ration.thread-0] c.h.internal.cluster.ClusterService      : [10.10.0.125]:5702 [dev] [3.8.1] 

Members [3] {
    Member [10.10.0.127]:5702 - e02dd47f-7bac-42d6-abf9-eeb62bdb1884
    Member [10.10.0.146]:5702 - 9239d33e-3b60-4bf5-ad81-da14524197ca
    Member [10.10.0.125]:5702 - 847d0008-6540-438d-bea6-7d8b19b8141a this
}

Anyone got ideas?


Solution

  • The problem I was having was with Apache Camel and their HazelcastComponent. It doesn't automatically pick up your Hazelcast instance. When I configured the HazelcastComponent like this it started using the correct HazelcastInstance:

    @Bean(name = "hazelcast")
    HazelcastComponent hazelcastComponent() {
        HazelcastComponent hazelcastComponent = new HazelcastComponent();
        hazelcastComponent.setHazelcastInstance(hazelcastInstance);
        return hazelcastComponent;
    }