最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Cannot Connect to ActiveMQ Artemis JMX When Running in Docker Container - Stack Overflow

programmeradmin0浏览0评论

I have a Java client that successfully connects to ActiveMQ Artemis JMX when both are running on the same machine. The client uses the following code:

public static void main(String[] args) throws IOException, MalformedObjectNameException, ReflectionException, AttributeNotFoundException, InstanceNotFoundException, MBeanException 
{    
    private static final String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
    System.out.println("Hello, Artemis!");
    HashMap env = new HashMap();
    String[] creds = {"artemis", "artemis"};
    env.put(JMXConnector.CREDENTIALS, creds);
    JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), env);  
    MBeanServerConnection mBeanServer = connector.getMBeanServerConnection();    
    System.out.println("Connected to the server");
}

ISSUE: When I move ActiveMQ Artemis into a Docker container with necessary ports exposed, I get the following error:

java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment;

What we tried:

  • Exposed JMX Ports in Docker
  • Added Java Argument in artemis.profile (-Djava.rmi.server.hostname=localhost)
  • Enabled Connector Element in management.xml ( <connector connector-port="1099" connector-host="localhost"/> ). Also tried replacing localhost with 0.0.0.0, but the issue persists.
  • After building and running the Docker image locally, I confirmed that RMI registry is listening on port 1099, but I still cannot connect.

I have a Java client that successfully connects to ActiveMQ Artemis JMX when both are running on the same machine. The client uses the following code:

public static void main(String[] args) throws IOException, MalformedObjectNameException, ReflectionException, AttributeNotFoundException, InstanceNotFoundException, MBeanException 
{    
    private static final String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
    System.out.println("Hello, Artemis!");
    HashMap env = new HashMap();
    String[] creds = {"artemis", "artemis"};
    env.put(JMXConnector.CREDENTIALS, creds);
    JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), env);  
    MBeanServerConnection mBeanServer = connector.getMBeanServerConnection();    
    System.out.println("Connected to the server");
}

ISSUE: When I move ActiveMQ Artemis into a Docker container with necessary ports exposed, I get the following error:

java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment;

What we tried:

  • Exposed JMX Ports in Docker
  • Added Java Argument in artemis.profile (-Djava.rmi.server.hostname=localhost)
  • Enabled Connector Element in management.xml ( <connector connector-port="1099" connector-host="localhost"/> ). Also tried replacing localhost with 0.0.0.0, but the issue persists.
  • After building and running the Docker image locally, I confirmed that RMI registry is listening on port 1099, but I still cannot connect.
Share Improve this question edited Feb 6 at 15:15 Justin Bertram 35k6 gold badges26 silver badges49 bronze badges asked Feb 6 at 5:15 Ananya HandeAnanya Hande 112 bronze badges 1
  • Any feedback here? – Justin Bertram Commented Feb 10 at 3:12
Add a comment  | 

1 Answer 1

Reset to default 2

I recommend you try setting the rmi-registry-port attribute on the connector, e.g.:

<connector connector-port="1099" rmi-registry-port="1100" connector-host="localhost"/>

Then ensure that port is exposed by Docker.

发布评论

评论列表(0)

  1. 暂无评论