DAA
DAA

Reputation: 19

Hazelcast caching provider - How to set the config smart routing programmatically?

I updated the Hazelcast version of my java project from 3.12.X to 5.3.5. However when I run the application locally I receive this error:

[WARNING ] _hzinstance_jcache_shared [dev] [5.3.5] Exception during initial connection to [127.0.0.1]:5703: com.hazelcast.core.HazelcastException: java.io.IOException: Connection refused: no further information to address /127.0.0.1:5703

When looking up the error, it seems like I need to set the smart routing to FALSE. I am wondering how I can set it up programmatically when creating the config as a MutableConfiguration ? Here is a snippet of my code:

@PostConstruct
private void initialize() {
  // Get the default cache service.
  final CachingProvider cachingProvider = Caching.getCachingProvider();
  final CacheManager cacheManager = cachingProvider.getCacheManager();

  // Configure the cache.
  final MutableConfiguration<Integer, MyCustomResponse> config = new MutableConfiguration<>();
  config.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(HOURS, 2)));
  config.setTypes(Integer.class, MyCustomResponse.class);

  // Now create the cache.
  Cache<Integer, MyCustomResponse> myCache = cacheManager.createCache("myCache", config);
}

I have tried solving my error by setting the smart routing to FALSE: config.getNetworkConfig().setSmartRouting(false)

Upvotes: -1

Views: 102

Answers (1)

Or&#231;un &#199;olak
Or&#231;un &#199;olak

Reputation: 702

MutableConfiguration is used to configure JCache. You can set timeout duration of a cache just like your example.

However, how the client connects to a cluster is set by ClientConfig. You need to configure a ClientConfig bean, like the example below:

@Bean
public ClientConfig clientConfig() {
  ClientConfig clientConfig = new ClientConfig();
  ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
  networkConfig.setSmartRouting(true);
  // other configuration for the client
  return clientConfig;
}

Upvotes: 0

Related Questions