JMX Connection refused

381 views
Skip to first unread message

Glenn Sheasby

unread,
Jun 3, 2015, 6:31:17 AM6/3/15
to cassandra-...@googlegroups.com

I'm incorporating cassandra-unit into our test suite, but I get the following error when I hit code that attempts to connect to cassandra via JMX. Should I be able to connect via JMX to the embedded cassandra server? Do I have to change some configuration to enable it?

The exception I get is:

java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is: 

java.net.ConnectException: Connection refused]

When executing the following:

    private static final String URL_TEMPLATE = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi";

    private static JMXConnector getConnector(String jmxHost, int jmxPort) {

        String urlString = String.format(URL_TEMPLATE, jmxHost, jmxPort);

        try {

            JMXServiceURL url = new JMXServiceURL(urlString);

            return JMXConnectorFactory.connect(url, null);

       } ....


jmxHost is localhost, and jmxPort is 7199 (Cassandra's default), but running netstat doesn't show this port as open.

Nate McCall

unread,
Jun 3, 2015, 10:56:22 AM6/3/15
to cassandra-...@googlegroups.com
JMX engine should be started, but it won't error out if it's not. Take
a look at:
https://github.com/apache/cassandra/blob/cassandra-2.0/src/java/org/apache/cassandra/service/CassandraDaemon.java#L147-L196

If any of those error or warn messages show up in the logs, you'll
need to set the corresponding system properties.

Also, this could be a race condition depending on when/how your code
is called in the lifecycle? Make sure it is after
https://github.com/jsevellec/cassandra-unit/blob/master/cassandra-unit/src/main/java/org/cassandraunit/utils/EmbeddedCassandraServerHelper.java#L95
as that will block until everything starts.
> --
> Vous recevez ce message, car vous êtes abonné au groupe Google Groupes
> "cassandra-unit-users".
> Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le
> concernant, envoyez un e-mail à l'adresse
> cassandra-unit-u...@googlegroups.com.
> Pour obtenir davantage d'options, consultez la page
> https://groups.google.com/d/optout.

Glenn Sheasby

unread,
Jun 3, 2015, 11:55:25 AM6/3/15
to cassandra-...@googlegroups.com
Thanks for your response.

My CassandraDaemon looks different - it does not have the maybeInitJmx function.

I'm using cassandra-all-2.1.3 and cassandra-unit-2.1.3.1.

Nate McCall

unread,
Jun 3, 2015, 1:27:45 PM6/3/15
to cassandra-...@googlegroups.com
Ok, some of that was moved around recently on 2.0, 2.1 and trunk.
Update to 2.1.5 (you should anyway, there have been a ton of fixes)
and you should see those messages.

Also, you may just need to set the following to get this to work with
your current:
com.sun.management.jmxremote.port=7199
com.sun.management.jmxremote.rmi.port=7199
com.sun.management.jmxremote.ssl=false
com.sun.management.jmxremote.authenticate=false

NOTE: this will allow JMX access to anything able to see that machine
on the network.

Glenn Sheasby

unread,
Jun 4, 2015, 9:08:47 AM6/4/15
to cassandra-...@googlegroups.com
Thanks! Updating to cassandra-all 2.1.5 fixed it for me,

Since I'm using cassandra-unit, I don't have a cassandra-env.sh file to play with, but I added the following to my build.gradle:

Dependencies:
      testCompile ('org.cassandraunit:cassandra-unit:2.1.3.1') {
        exclude module: 'org.apache.cassandra:cassandra-all'
      }
      testCompile 'org.apache.cassandra:cassandra-all:2.1.5'

System properties (in task test):
      systemProperties['com.sun.management.jmxremote.port'] = 7199
      systemProperties['com.sun.management.jmxremote.rmi.port'] = 7199
      systemProperties['com.sun.management.jmxremote.ssl'] = false
      systemProperties['com.sun.management.jmxremote.authenticate'] = false

Note for others who have this problem: I also had to increate the MaxPermSize to 196m to get my entire test suite to run. If you get OOMs, you need to find and kill the test worker process (via jps) in order to free the port up.
Reply all
Reply to author
Forward
0 new messages