如何处理ClusterListenerThread在我的Hazelcast客户端bean实例化(通过Spring)期间抛出的错误?

如何处理ClusterListenerThread在我的Hazelcast客户端bean实例化(通过Spring)期间抛出的错误?,hazelcast,Hazelcast,我正在使用Spring配置一个(延迟加载的)Hazelcast客户端,该客户端连接到一个由两个成员组成的集群 <hz:client id="hazelcast" lazy-init="true"> <hz:group name="${HzName}" password="${HzPassword}"/> <hz:properties> <hz:property name="hazelcast.client.connecti

我正在使用Spring配置一个(延迟加载的)Hazelcast客户端,该客户端连接到一个由两个成员组成的集群

<hz:client id="hazelcast" lazy-init="true">
    <hz:group name="${HzName}" password="${HzPassword}"/>
    <hz:properties>
        <hz:property name="hazelcast.client.connection.timeout">10000</hz:property>
        <hz:property name="hazelcast.client.retry.count">600</hz:property>
        <hz:property name="hazelcast.jmx">true</hz:property>
        <hz:property name="hazelcast.logging.type">slf4j</hz:property>
    </hz:properties>
    <hz:network smart-routing="true" redo-operation="true" connection-attempt-period="5000"
                connection-attempt-limit="2">
        <hz:member>${HzMember1}</hz:member>
        <hz:member>${HzMember2}</hz:member>
    </hz:network>
</hz:client>
…这会导致我的Hazelcast客户端bean没有被实例化,因此依赖它存在的所有下游都会崩溃

SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hazelcast': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static com.hazelcast.core.HazelcastInstance com.hazelcast.client.HazelcastClient.newHazelcastClient(com.hazelcast.client.config.ClientConfig)] threw exception; nested exception is java.lang.IllegalStateException: Cannot get initial partitions!
在Hazelcast客户机bean的实例化(通过Spring)期间,如何检测和处理ClusterListenerThread抛出的错误


注意。客户端bean没有被构造(尽管没有可用的成员),这让我很沮丧,因为我知道,一个已经构造好的客户端可以处理它的所有成员都不可用的问题,并且当一个或多个成员再次可用时,它将愉快地重新开始工作

您需要做的是配置ConnectionAttributeLimit和ConnectionAttributePeriod

如果您将ConnectionAttentinLimit设置为INT_MAX并选择一个合理的ConnectionAttemptPeriod,那么客户端实际上会尝试每X秒永远连接到给定的成员列表。这目前更像是一种解决方法,因为当您第一次打开HazelcastClient时,它将一直阻止,直到其中一个成员可用为止。另一种解决方法是,您可以尝试在另一个专用线程中打开客户端

关于制作一个完全受支持的功能,hazelcast团队正在这里进行讨论。

我想补充一个问题,作为对这个问题的参考

SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hazelcast': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static com.hazelcast.core.HazelcastInstance com.hazelcast.client.HazelcastClient.newHazelcastClient(com.hazelcast.client.config.ClientConfig)] threw exception; nested exception is java.lang.IllegalStateException: Cannot get initial partitions!