【问题标题】:How to connect JBoss 7.1.1 remoting -jmx via java code?如何通过java代码连接JBoss 7.1.1 remoting -jmx?
【发布时间】:2014-03-25 06:38:37
【问题描述】:

我有一个 JBoss 7.1.1 服务器,我想为其编写 jmx 客户端。据我了解,jboss 7.1.1 没有使用典型的基于 rmi 的 jmx,他们在本地管理上提供了一层远程处理 jmx。我正在使用以下代码:

JMXServiceURL address = new JMXServiceURL("service:jmx:remoting-jmx://localhost:9999");

Map env = JMXConnectorConfig.getEnvironment(paramtbl);

JMXConnector connector = JMXConnectorFactory.connect(address, env);

但它给出了以下异常:

java.net.MalformedURLException: Unsupported protocol: remoting-jmx

我用谷歌搜索了它,以下线程似乎相关: https://community.jboss.org/thread/204653?tstart=0

它要求将 jboss 的库添加到我的类路径中。我也试过了,但仍然遇到同样的异常。

【问题讨论】:

    标签: jboss jmx


    【解决方案1】:

    我在尝试获取 JmxServiceUrl 时遇到了同样的异常。 确保在您的standalone.xml 中有以下内容:

    <subsystem xmlns="urn:jboss:domain:jmx:1.1"> <show-model value="true"/> <remoting-connector use-management-endpoint="true" /> </subsystem>

    您应该在项目类路径中包含名为:jboss-client.jar 的 jar,它可以在 JBOSS_DIRECTORY/bin/client 中找到。事实上,JMX 客户端必须在其类路径中包含该 jar。

    这个技巧为我解决了这个问题..希望它对你有帮助

    【讨论】:

    • 我的问题是因为 jboss-client.jar 而已。我的类路径中有这个 jar 的重复条目,第一个来自早期的 jboss 版本。
    【解决方案2】:

    尝试在 JBoss AS7 上的 Arquillian 测试中做同样的事情,最后不得不使用:

    import org.jboss.remotingjmx.RemotingConnectorProvider;
    
    RemotingConnectorProvider s = new RemotingConnectorProvider();
    JMXConnector connector = s.newJMXConnector(url, credentials);
    connector.connect();
    

    无法让“module name="org.jboss.remoting-jmx" services="import"" 工作

    也适用于

    environment.put("jmx.remote.protocol.provider.pkgs", "org.jboss.remotingjmx");
    JMXConnector connector = JMXConnectorFactory.connect(url, environment);
    connector.connect();
    

    【讨论】:

      【解决方案3】:

      我使用此代码连接到远程服务器中的 JBoss

      ModelControllerClient client = null;
      try {
       client = createClient(InetAddress.getByName("172.16.73.12"), 9999,
           "admin", "pass", "ManagementRealm");
          } 
      catch (UnknownHostException e) {
       e.printStackTrace();
      }
      

      createClient 是我写的一个方法——

      private ModelControllerClient createClient(final InetAddress host,
        final int port, final String username, final String password,
        final String securityRealmName) {
      
       final CallbackHandler callbackHandler = new CallbackHandler() {
      
        public void handle(Callback[] callbacks) throws IOException,
          UnsupportedCallbackException {
         for (Callback current : callbacks) {
          if (current instanceof NameCallback) {
           NameCallback ncb = (NameCallback) current;
           ncb.setName(username);
          } else if (current instanceof PasswordCallback) {
           PasswordCallback pcb = (PasswordCallback) current;
           pcb.setPassword(password.toCharArray());
          } else if (current instanceof RealmCallback) {
           RealmCallback rcb = (RealmCallback) current;
           rcb.setText(rcb.getDefaultText());
          } else {
           throw new UnsupportedCallbackException(current);
          }
         }
        }
       };
       return ModelControllerClient.Factory
         .create(host, port, callbackHandler);
      }
      

      有关如何使用 Java/Google 可视化 API 读取从服务器获取的数据或完整项目的更多信息(每 10 秒后在 Graph 中显示统计信息),请参阅本教程 -

      http://javacodingtutorial.blogspot.com/2014/05/reading-jboss-memory-usage-using-java.html

      【讨论】:

        【解决方案4】:

        将以下内容添加到您的 jboss-deployment-structure

           <dependencies>
                 <module name="org.jboss.remoting3.remoting-jmx" services="import"/>
           </dependencies>
        

        【讨论】:

          【解决方案5】:

          通过在standalone.xml 中添加以下条目来激活JMX 远程处理子系统

          <subsystem xmlns="urn:jboss:domain:ee:1.1">
            <!-- Activate JMX remoting -->
            <global-modules>
              <module name="org.jboss.remoting-jmx" slot="main"/>
            </global-modules>
            ...
          </subsystem>
          

          【讨论】:

            【解决方案6】:

            似乎“jboss-client.jar”在运行时无法用于 JMX 连接,因此请确保您在类路径中添加了“jboss-client.jar”。 而且您正在使用已弃用的协议“remoting-jmx”而不是“remote”。

            即“服务:jmx:remote://localhost:9999”

            希望对你有帮助。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2017-09-18
              • 2012-02-18
              • 1970-01-01
              • 1970-01-01
              • 2014-11-21
              • 2013-06-20
              • 1970-01-01
              • 2014-12-22
              相关资源
              最近更新 更多