gpt4 book ai didi

java - 使用 AWS 加入策略时 Vertx Hazelcast 集群错误 "There is no discovery strategy factory to create ..."

转载 作者:行者123 更新时间:2023-12-01 20:04:47 25 4
gpt4 key购买 nike

我正在尝试在aws中设置一个简单的vertx集群。(你可以找到所有代码here)

在 pom 文件中,我已经添加了所需的所有依赖项,包括 vertx-hazelcast 和 aws 的 hazelcast 插件。

至于主类,它非常简单,所有 hazelcast 设置都在主类中准备好。

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());
}
});

}
}

每当我运行 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?

我的代码中是否缺少任何内容?

最佳答案

错误消息通常意味着您没有 hazelcast-aws.jar插件在你的类路径中。

我发现您的 Maven 依赖项中有它,但请确保:

  1. 您使用与您的 hazelcast 版本兼容的 hazelcast-aws 版本(您可以找到兼容性信息 here)。
  2. 您的 JAR 确实包含 com.hazelcast.aws 包中的类。
  3. 您的 JAR 包含文件 resources/META-INF/services/com.hazelcast.spi.discovery.DiscoveryStrategyFactory .
  4. 您的 resources/META-INF/services/com.hazelcast.spi.discovery.DiscoveryStrategyFactory 确实包含条目 com.hazelcast.aws.AwsDiscoveryStrategyFactory

如果上述任何内容不正确,那么您需要重新审视 Fat JAR 的构建方式。实现这一切的解决方案之一是依赖hazelcast-all(而不是hazelcast)。这将使您摆脱所有这些问题。

关于java - 使用 AWS 加入策略时 Vertx Hazelcast 集群错误 "There is no discovery strategy factory to create ...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58989424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com