在同一个jvm中部署的多个战争中使用cassandra驱动程序时出现jmx错误

Bha*_*ath 3 tomcat spring-mvc cassandra datastax-java-driver spring-data-cassandra

我有app1.war和app2.war部署在同一个tomcat jvm中.这两个应用程序都有自己的上下文xmls - app1.xml和app2.xml.这两个应用程序都包含连接到Cassandra的数据存储驱动程序依赖项.它们在单独部署时运行良好.但是当两者都部署在同一个jvm中时,我在日志中看到了以下JMX异常:

[DEBUG] [TokenId=] [2015-07-29 20:54:35.177] [DefaultListableBeanFactory] - [Eagerly caching bean 'cluster' to allow for resolving potential circular references]
[DEBUG] [TokenId=] [2015-07-29 20:54:35.191] [DefaultListableBeanFactory] - [Invoking afterPropertiesSet() on bean with name 'cluster']
[DEBUG] [TokenId=] [2015-07-29 20:54:35.199] [SystemProperties] - [com.datastax.driver.NEW_NODE_DELAY_SECONDS is undefined, using default value 1]
[DEBUG] [TokenId=] [2015-07-29 20:54:35.199] [SystemProperties] - [com.datastax.driver.NON_BLOCKING_EXECUTOR_SIZE is undefined, using default value 16]
[DEBUG] [TokenId=] [2015-07-29 20:54:35.205] [SystemProperties] - [com.datastax.driver.NOTIF_LOCK_TIMEOUT_SECONDS is undefined, using default value 60]
[WARN ] [TokenId=] [2015-07-29 20:54:35.217] [FrameCompressor] - [Cannot find Snappy class, you should make sure the Snappy library is in the classpath if you intend to use it. Snappy compression
will not be available for the protocol.]
[WARN ] [TokenId=] [2015-07-29 20:54:35.219] [FrameCompressor] - [Cannot find LZ4 class, you should make sure the LZ4 library is in the classpath if you intend to use it. LZ4 compression will not
be available for the protocol.]
[DEBUG] [TokenId=] [2015-07-29 20:54:35.356] [Cluster] - [Starting new cluster with contact points [xxxxx1.com/10.63.162.182:9042, xxxx2.com/10.63.162.177:9042, xxxx3.com/10.63.162.183:9042]]
[DEBUG] [TokenId=] [2015-07-29 20:54:35.556] [JmxReporter] - [Unable to register gauge]
javax.management.InstanceAlreadyExistsException: cluster1-metrics:name=open-connections
        at com.sun.jmx.mbeanserver.Repository.addMBean(Unknown Source) ~[?:1.7.0_45]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(Unknown Source) ~[?:1.7.0_45]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(Unknown Source) ~[?:1.7.0_45]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(Unknown Source) ~[?:1.7.0_45]
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(Unknown Source) ~[?:1.7.0_45]
        at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(Unknown Source) ~[?:1.7.0_45]
        at com.codahale.metrics.JmxReporter$JmxListener.onGaugeAdded(JmxReporter.java:494) [metrics-core-3.0.2.jar:3.0.2]
        at com.codahale.metrics.MetricRegistry.notifyListenerOfAddedMetric(MetricRegistry.java:344) [metrics-core-3.0.2.jar:3.0.2]
        at com.codahale.metrics.MetricRegistry.addListener(MetricRegistry.java:187) [metrics-core-3.0.2.jar:3.0.2]
        at com.codahale.metrics.JmxReporter.start(JmxReporter.java:697) [metrics-core-3.0.2.jar:3.0.2]
        at com.datastax.driver.core.Metrics.<init>(Metrics.java:77) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster$Manager.<init>(Cluster.java:1204) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster$Manager.<init>(Cluster.java:1144) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster.<init>(Cluster.java:121) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster.<init>(Cluster.java:108) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster.buildFrom(Cluster.java:177) [cassandra-driver-core-2.1.4.jar:?]
        at com.datastax.driver.core.Cluster$Builder.build(Cluster.java:1109) [cassandra-driver-core-2.1.4.jar:?]
Run Code Online (Sandbox Code Playgroud)

该应用程序在功能上运行.我只关心为什么我看到这个错误以及如何避免这种情况.

And*_*ert 7

正如您所指出的,除了不注册Cluster的度量标准MBean之外,这不会引起任何问题.要防止出现此消息/问题,您可以为群集实例指定唯一的名称,这些名称可能与应用程序本身的名称相关联.

    Cluster cluster = Cluster.builder().withClusterName("myapplication")
            .build();
Run Code Online (Sandbox Code Playgroud)

这将在您的mbean名称前加上'myapplication-1'.

否则,您可以使用withoutJMXReportingwithoutMetrics禁用JMX指标,以禁用指标报告.

  • 你把它打败了Andy ...通常驱动程序自己用一个计数器(cluster1,cluster2 ......)处理它,但是在那种情况下失败,因为计数器存储在静态字段中,每个应用程序都有自己的类加载器.MBeans服务器是唯一的,因此碰撞. (2认同)