hilman muhtadi
hilman muhtadi

Reputation: 3

Vertx Hazelcast Cluster Error "There is no discovery strategy factory to create ..." when using AWS Join Strategy

I am trying to setup a simple vertx cluster in aws.(you can find all the code here)

In the pom file I already add all the depedency I need, including vertx-hazelcast and hazelcast plugin for aws.

As for The Main Class it is quite simple and all the hazelcast setup is prepared in the main class.

public class Main {
    public static void main(String[] args) {
        Logger log = Logger.getLogger(Main.class.getSimpleName());
        Config hazelcastConfig = new Config();


        hazelcastConfig.getNetworkConfig().getInterfaces().
                 setEnabled(true).addInterface("10.0.*.*");
        JoinConfig joinConfig = hazelcastConfig.getNetworkConfig().getJoin();
        joinConfig.getMulticastConfig().setEnabled(false);
        joinConfig.getAwsConfig()
                .setEnabled(true)
                .setProperty("region", "ap-southeast-1")
                .setProperty("tag-key", "aws:cloudformation:stack-name")
                .setProperty("tag-value", "EC2ContainerService-test-cluster");
        hazelcastConfig.getNetworkConfig().setJoin(joinConfig);


        ClusterManager mgr = new HazelcastClusterManager(hazelcastConfig);
        String hostAddress = getAddress();

        VertxOptions options = new VertxOptions()
                .setClusterManager(mgr)
                .setHAEnabled(true);

        EventBusOptions ebOptions = new EventBusOptions()
                .setClustered(true)
                .setHost(hostAddress);

        options.setEventBusOptions(ebOptions);

        Vertx.clusteredVertx(options, handler->{
            if(handler.succeeded()){
                DeploymentOptions containerOption = new DeploymentOptions().setHa(false); 
                handler.result().deployVerticle(Verticle.class,containerOption,deployHandler->{
                    if(handler.succeeded()){
                        log.info("Verticle Deployed");
                    }else{
                        log.severe("Verticle Deployment Failed");
                    }
                });
            } else{
                log.severe(handler.cause().getMessage());
            }
        });

    }
}

I always run into this error whenever I run the fat jar.

Caused by: com.hazelcast.config.properties.ValidationException: There is no discovery strategy factory to create 'D
iscoveryStrategyConfig{properties={tag-value=EC2ContainerService-test-cluster, region=ap-southeast-1, tag-key=aws:c
loudformation:stack-name}, className='com.hazelcast.aws.AwsDiscoveryStrategy', discoveryStrategyFactory=null}' Is i
t a typo in a strategy classname? Perhaps you forgot to include implementation on a classpath?

Is there anything missing in my code ?

Upvotes: 0

Views: 1303

Answers (1)

Rafał Leszko
Rafał Leszko

Reputation: 5531

The error message usually means that you don't have hazelcast-aws.jar plugin in your classpath.

I see that you have it in your Maven dependencies, but please make sure that:

  1. You use the compatible hazelcast-aws version with your hazelcast version (you can find the compatibility information here).
  2. Your JAR really includes classes from the com.hazelcast.aws package.
  3. Your JAR includes the file resources/META-INF/services/com.hazelcast.spi.discovery.DiscoveryStrategyFactory.
  4. Your resources/META-INF/services/com.hazelcast.spi.discovery.DiscoveryStrategyFactory does contain the entry com.hazelcast.aws.AwsDiscoveryStrategyFactory

If anything of above is not correct, then you need to revisit how your fat JAR is built. One of the solutions of having it all in place is to have a dependency to hazelcast-all (not hazelcast). This will release you from all these issues.

Upvotes: 2

Related Questions