【问题标题】:Hazelcast MBean is missingHazelcast MBean 丢失
【发布时间】:2018-05-29 15:27:37
【问题描述】:

我将一个应用程序迁移到 Spring Boot,包括从 XML 迁移到 Java 配置。该应用程序使用 Hazelcast 并且确实有效。但是,我再也看不到 JConsole 中的 Hazelcast MBean。关于启用 JMX,我唯一能找到的就是属性

properties.put("hazelcast.jmx", true);

但这无济于事。这是迁移前的配置:

<hz:hazelcast id="hzInstance">
    <hz:config>
        <hz:group name="gsynth" password="gsynth"/>
        <hz:properties>
            <hz:property name="hazelcast.logging.type">slf4j</hz:property>
            <hz:property name="hazelcast.jmx">true</hz:property>
            <hz:property name="hazelcast.version.check.enabled">false</hz:property>
            <hz:property name="hazelcast.icmp.enabled">true</hz:property>
            <hz:property name="hazelcast.shutdownhook.enabled">true</hz:property>
            <hz:property name="hazelcast.max.operation.timeout">60000</hz:property>
            <hz:property name="hazelcast.restart.on.max.idle">true</hz:property>
        </hz:properties>
        <hz:network port="5701" port-auto-increment="false">
            <hz:join>
                <hz:multicast enabled="false"/>
                <hz:tcp-ip enabled="true">
                    <hz:members>${members.list}</hz:members>
                </hz:tcp-ip>
            </hz:join>
        </hz:network>
    </hz:config>
</hz:hazelcast>
<hz:map id="serviceHash" instance-ref="hzInstance" name="service-hash"/>
<hz:map id="persisterHash" instance-ref="hzInstance" name="persister-hash"/>

现在看起来像这样:

public class HazelcastConfig
{

    @Bean
    public HazelcastInstance hzInstance(Config hzConfig)
    {
        return Hazelcast.newHazelcastInstance(hzConfig);
    }

    @Bean
    public Config hzConfig(@Value("${members.list}") String membersList)
    {
        Properties properties = new Properties();
        properties.put("hazelcast.logging.type", "slf4j");
        properties.put("hazelcast.jmx", true);
        properties.put("hazelcast.version.check.enabled", false);
        properties.put("hazelcast.icmp.enabled", true);
        properties.put("hazelcast.shutdownhook.enabled", true);
        properties.put("hazelcast.max.operation.timeout", 60000);
        properties.put("hazelcast.restart.on.max.idle", true);

        return new Config().setGroupConfig(new GroupConfig().setName("gsynth").setPassword("gsynth")).setProperties(
                properties).setNetworkConfig(
                new NetworkConfig().setPort(5701).setPortAutoIncrement(false).setJoin(
                        new JoinConfig().setMulticastConfig(new MulticastConfig().setEnabled(false)).setTcpIpConfig(
                                new TcpIpConfig().setEnabled(true).addMember(membersList))));
    }

    @Bean
    public IMap serviceHash(HazelcastInstance hzInstance)
    {
        return hzInstance.getMap("service-hash");
    }

    @Bean
    public IMap persisterHash(HazelcastInstance hzInstance)
    {
        return hzInstance.getMap("persister-hash");
    }

}

感谢您的帮助!

【问题讨论】:

    标签: java spring spring-boot jmx hazelcast


    【解决方案1】:

    最后,我发现了问题:问题是我使用的属性是这样的:

        Properties properties = new Properties();
        properties.put("hazelcast.logging.type", "slf4j");
        properties.put("hazelcast.jmx", true);
        ...
    

    所以true 被设置为布尔值。 Hazelcast 的源代码内部在第 752 行的文件 GroupProperties.java 中变为空:

    String configValue = (config != null) ? config.getProperty(name) : null;
    

    如果您深入挖掘,您会发现 config.getProperty(name) 将返回 null,因为 Properties.java 文件第 969 行的这个奇特的东西(如在 JDK 1.8.0_102 中):

    Object oval = super.get(key);
    String sval = (oval instanceof String) ? (String)oval : null;
    

    oval 在这种情况下对应于“hazelcast.jmx”键,因此是 true 但作为 BOOLEAN 而不是 String 是必需的。

    修复很简单:

    Properties properties = new Properties();
    properties.put("hazelcast.logging.type", "slf4j");
    properties.put("hazelcast.jmx", "true");
    ...
    

    只需将所有非字符串值设为字符串即可。

    希望它对某人有所帮助!

    【讨论】:

      【解决方案2】:

      您能否通过如下设置系统属性来确保您已启用 JMX 代理

          -Dcom.sun.management.jmxremote
          -Dcom.sun.management.jmxremote.port=_portNo\_ (to specify JMX port, the default is 1099) (optional)
          -Dcom.sun.management.jmxremote.authenticate=false
      

      然后您尝试如下更简单的设置以确保它是否有效,如果有效,则检查程序中配置的构造。

      Config config = new Config();
      config.setProperty("hazelcast.jmx", "true");
      HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
      

      【讨论】:

      • 这就是我的做法。我可以通过 JConsole 验证其他 JMX bean 是否存在。但我没有从 Hazelcast 中看到一个
      • 你使用的是哪个版本的 hazelcast?
      • 版本为3.5
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 1970-01-01
      • 2016-08-31
      相关资源
      最近更新 更多