简体   繁体   English

如何获取 Wildfly 21 上的集群节点信息?

[英]How to get cluster nodes information on Wildfly 21?

I am trying to get the cluster information (esp nodes list) with the below Application code.我正在尝试使用以下应用程序代码获取集群信息(尤其是节点列表)。

MBeanServer server = ManagementFactory.getPlatformMBeanServer();

String clusterMembers = (String) (server.getAttribute(new ObjectName("jboss.infinispan:type=CacheManager,name=\"ejb\",component=CacheManager"), "clusterMembers"));
      (or)
Object obj = server.getAttribute(ObjectName.getInstance("jgroups:type=channel,cluster=\"web\""), "View");

Both are throwing InstanceNotFoundExceptions.两者都在抛出 InstanceNotFoundExceptions。

javax.management.InstanceNotFoundException: jgroups:type=channel,cluster="web"
2021-02-08 15:39:59,046 ERROR [stderr:71] (default task-1) javax.management.InstanceNotFoundException: jgroups:type=channel,cluster="web"
2021-02-08 15:39:59,047 ERROR [stderr:71] (default task-1)  at org.jboss.as.jmx.PluggableMBeanServerImpl.findDelegate(PluggableMBeanServerImpl.java:1113)
2021-02-08 15:39:59,047 ERROR [stderr:71] (default task-1)  at org.jboss.as.jmx.PluggableMBeanServerImpl.getAttribute(PluggableMBeanServerImpl.java:389)

There are a number of ways to do this.有很多方法可以做到这一点。 Programmatically, perhaps the simplest way is to use WildFly's clustering API.以编程方式,也许最简单的方法是使用 WildFly 的集群 API。 For details, see: https://github.com/wildfly/wildfly/blob/master/docs/src/main/asciidoc/_high-availability/Clustering_API.adoc#group-membership详情参见: https://github.com/wildfly/wildfly/blob/master/docs/src/main/asciidoc/_high-availability/Clustering_API.adoc#group-membership

Alternatively, you can also use WildFly's CLI to obtain cluster information.或者,您也可以使用 WildFly 的 CLI 来获取集群信息。 eg例如

[standalone@embedded /] /subsystem=jgroups/channel=ee:read-attribute(name=view)
{
    "outcome" => "success",
    "result" => "[localhost|0] (1) [localhost]"
}

Alternatively, you can obtain cluster information using Infinispan or JGroups APIs directly.或者,您可以直接使用 Infinispan 或 JGroups API 获取集群信息。 eg例如

@Resource(lookup = "java:jboss/infinispan/cache-container/web")
private EmbeddedCacheManager manager;

@Resource(lookup = "java:jboss/jgroups/channel/default")
private JChannel channel;

public void foo() {
   System.out.println(this.manager.getMembers());
   System.out.println(this.channel.getView());
}

Lastly, if you prefer to go the JMX route, ensure that your WildFly configuration defines a JMX subsystem, otherwise no mbeans will be registered.最后,如果您更喜欢 go JMX 路由,请确保您的 WildFly 配置定义了 JMX 子系统,否则不会注册任何 mbean。

Infinispan mbeans are registered using the domain: "org.wildfly.clustering.infinispan". Infinispan mbean 使用以下域注册:“org.wildfly.clustering.infinispan”。 Make sure you are using 22.0.1.Final which includes a fix for https://issues.redhat.com/browse/WFLY-14286确保您使用的是 22.0.1.Final,其中包含对https://issues.redhat.com/browse/WFLY-14286的修复

Your jgroups jmx code name is almost correct - using the default configuration, each Infinispan cache manager uses a distinct ForkChannel based on a common JChannel, named "ee".您的 jgroups jmx 代码名称几乎是正确的 - 使用默认配置,每个 Infinispan 缓存管理器都使用基于公共 JChannel 的不同 ForkChannel,名为“ee”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM