2

I have a java application for monitoring the individual queues on Active MQ (version 5.13.0). The Objective of this application is to connect to the Active MQ broker and find out the in flight message count for specific queues. If the in flight message count is more than 50 then it sends an alert. This application performs this check every 10 minutes (Using Quartz Scheduler). When I am connecting to the AMQ broker which uses the IP address to connect to the AMQ, I receive the IOException with the following stack trace -

    java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
        java.net.ConnectException: Connection refused: connect
        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
        at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
        at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
        at sun.rmi.server.UnicastRef.invoke(Unknown Source)
        at javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
        at javax.management.remote.rmi.RMIConnector.getConnection(Unknown Source)
        at javax.management.remote.rmi.RMIConnector.connect(Unknown Source)
        at javax.management.remote.JMXConnectorFactory.connect(Unknown Source)
        at javax.management.remote.JMXConnectorFactory.connect(Unknown Source)
        at com.globalcharge.quartz.job.CheckPendingConsumer.execute(CheckPendingConsumer.java:51)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
        at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
        at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
        at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
        ... 12 more

I am using the following code to connect to the AMQ broker over JMX

JMXServiceURL url = new     JMXServiceURL("service:jmx:rmi:///jndi/rmi://192.168.11.72:1099/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url);
MBeanServerConnection conn = jmxc.getMBeanServerConnection(); 

ObjectName activeMq = new ObjectName("org.apache.activemq:Type=Broker,BrokerName=localhost");

BrokerViewMBean mbean = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(conn, activeMq, BrokerViewMBean.class, true);
//for each queue 
for(ObjectName name : mbean.getQueues())
{
    if(("dbg.notmanager.netsizeDelivery".equals(name)))
    {
        //obtain an instance of QueueViewMBean 
        QueueViewMBean queueMbean = (QueueViewMBean)MBeanServerInvocationHandler.newProxyInstance(conn, name, QueueViewMBean.class, true);
        long inFlight = queueMbean.getInFlightCount(); 
        if(inFlight >= 50)
        {
            sender.sendPassiveCriticalAlert(hostname, "Passive.GCDBG", "InFlight Messages for a consumer on " + name);
        }           
}

Notes: 1. If I install the AMQ on my local machine and deploy the code above on Tomcat running on my local machine it works. What I mean is, when both (Java Client and AMQ ) are on same machine, it works.
2. I have done the necessary configurations on AMQ server as mentioned here configure JMX for ActiveMQ for remoting access 3. I have checked the connectivity to IP and port mentioned in the code through telnet and it works. 4. I have also recorded the TCP dump on the AMQ server machine and I can see the request reaching there. 5. Both machines (where Tomcat and AMQ run) are not virtual machines, but are dedicated physical machines in the same network.

Please help :)

Community
  • 1
  • 1

2 Answers2

0

as logs say Connection refused, i think connection configs error. you need these credentials too

JMXServiceURL url = ...;
Map env = ...;
String[] creds = {"admin", "activemq"};
env.put(JMXConnector.CREDENTIALS, creds);
JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
Hassen Bennour
  • 3,885
  • 2
  • 12
  • 20
  • Thanks a lot Hassen. But still no luck :( – abhijit kulkarni Sep 13 '16 at 14:07
  • can you post broker logs. you say **Both machines (where Tomcat and AMQ run) are not virtual machines, but are dedicated physical machines in the same network.** but jmx try to connect to localhost (127.0.0.1) , are you sur of ip here `JMXServiceURL("service:jmx:rmi:///jndi/rmi://192.168.11.72:1099/jmxrmi");` – Hassen Bennour Sep 13 '16 at 14:34
  • Hassen thanks for your reply. I see two WARN log lines in the broker log as follows – abhijit kulkarni Sep 14 '16 at 10:26
  • 2016-09-14 11:20:42,423 | WARN | Transport Connection to: tcp://192.168.11.219:10587 failed: org.apache.activemq.transport.InactivityIOException: Cannot send, channel has already failed: tcp://192.168.11.219:10587 | org.apache.activemq.broker.TransportConnection.Transport | Async Exception Handler – abhijit kulkarni Sep 14 '16 at 10:29
  • - 2016-09-14 11:20:42,346 | WARN | Transport Connection to: tcp://192.168.11.219:10587 failed: java.net.SocketException: Connection reset | org.apache.activemq.broker.TransportConnection.Transport | ActiveMQ Transport: tcp:///192.168.11.219:10587@61616 – abhijit kulkarni Sep 14 '16 at 10:29
  • are you sur of broker ip here `JMXServiceURL("service:jmx:rmi:///jndi/rmi://192.168.11.72:1‌​099/jmxrmi");` can you post `activemq.xml` jmx config , this is strange java.rmi.ConnectException: Connection refused **to host: 127.0.0.1**; try to execute this code without quartz directly from editor – Hassen Bennour Sep 14 '16 at 11:36
  • try to connect to broker with jconsole too – Hassen Bennour Sep 14 '16 at 11:48
0

I am able to connect now using the JConsole as well as the Java Code I have written. The Problem was in the env file (under amqHome/bin/) had a property java.rmi.server.hostname which had a value 127.0.0.1 I changed this value to 192.168.11.72 (the IP of the machine) and it worked ....

Thanks all for the support ....