Search code examples
apachetcpconnectionactivemq-classicwso2-esb

ActiveMQ Dead Connection issue


Hi am working on ActiveMQ 5.10.0 they are curtain process which will connect through a TCP connection and send messages to a queue and also topic subscriptions,Total max connections are around 10000.

After some usage am facing error as max connections exceeded in activeMQ,i have gone through activemq console and found a lot of the TCP connections are still alive with active status as true and this connections pileup to 10000 and ActiveMQ throws error as max connection exceeded.

why are this connections are staying forever with status true how to get rid of this connections is there any way to kill this dead connections or make connection expire after some duration.

Thank You..!


Solution

  • Whenever a JMS client wants to connect with the a MQ broker then typical code is like this:

    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    connection = connectionFactory.createConnection();
    

    Now, once JMS client (producer/consumer) is done if it doesn't close the connection then that JMS client will still remain connected with the MQ broker and will occupy a connection with the MQ broker. Now, in your case looks like your JMS client code "could be faulty" and not closing the connection, so you need to check your JMS client code and get the connections closed like below.

    if (connection != null) {
          connection.close();
    }
    

    Now, having said that if you have message listeners in your JMS client then it is expected that connection would remain open, but in case if those connections are totally inactive after some time then you can specify maximum inactivity duration for the connections using wireFormat.maxInactivityDuration, for this when you are creating a connection with MQ broker then you should create like this cf = new ActiveMQConnectionFactory( "tcp://localhost:61616?wireFormat=openwire&wireFormat.maxInactivityDuration=<<whatever_value_you_want>>");

    Read this ActiveMQ documentation for more details.


    As a FYI - maximum number of connections in a ActiveMQ broker is defined using its configuration file activemq.xml, inside that you have transportConnectors element where you defined maximum connection (?maximumConnections=1000) as shown below, so just in case if you have appropriate system resources and you have capacity to get more client connections then you can increase.

    <transportConnectors>
                <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
                <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
                <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    </transportConnectors>