我有以下 Java 文件可以连接到 Wildfly 服务器:
import java.util.Arrays;
import javax.management.JMX;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
import org.jboss.messaging.jms.server.management.JMSServerControl;
public class sampleRun3 {
public static void main(String[] args) throws Exception {
JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi://"+"ServerIP"+":"+"9990"+"/jmxrmi" );
JMXConnector connector = JMXConnectorFactory.connect( url );
MBeanServerConnection server = connector.getMBeanServerConnection();
ObjectName objectName = ObjectNameBuilder.DEFAULT.getActiveMQServerObjectName();
//JMSSessionMode session = (JMSSessionMode) JMX.newMBeanProxy(server, objectName, JMSSessionMode.class, true);
JMSServerControl controller = (JMSServerControl) JMX.newMBeanProxy(server,objectName,JMSServerControl.class,true );
//System.out.println("Topics :->"+Arrays.asList(controller.getTopicNames()));
//System.out.println("Queues :->"+Arrays.asList(controller.getQueueNames()));
System.out.println("Conn Ids :->"+Arrays.asList(controller.listConnectionIDs()));
System.out.println("Remote Addr:->"+Arrays.asList(controller.listRemoteAddresses()));
}
}
我收到以下错误:
Exception in thread "main" java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketTimeoutException: Read timed out]
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:369)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:270)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:229)
at sampleRun3.main(sampleRun3.java:15)
Caused by: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketTimeoutException: Read timed out]
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:136)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:205)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1955)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1922)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:287)
... 3 more
Caused by: java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketTimeoutException: Read timed out
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:307)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:343)
at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:116)
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:132)
... 8 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
at java.io.DataInputStream.readByte(DataInputStream.java:265)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:246)
... 12 more
我有另一个 java 文件,我在其中使用 JMXServiceURL 来检索活动 mbean 的数量及其工作正常。请在这方面提供帮助。我有用户 Server_IP、localhost 和 127.0.0.1 来连接,但都给出相同的结果,我在服务器本身上运行它。