简体   繁体   中英

How to properly close connection to MQ Manager?

I made an Java app to connect to an MQ Queue and send a message. It uses a timer to invoke the function many times, so when there's a message recorded in another queue, gets it and sends it to the other.

            mensajeHost = dataqueue.read(Constantes.CRITERIO_LECTURA_DQ,Constantes.DQGET_TIEMPO_MAXIMO, "GE");

            if (mensajeHost != null) {

                comando = mensajeHost.getString();

                key = comando.substring(Constantes.S_IND_KEY_ENT_EE, Constantes.E_IND_KEY_ENT_EE);

                qmgr = comando.substring(Constantes.S_IND_QMGR_ENT_EE, Constantes.E_IND_QMGR_ENT_EE);

                qr = comando.substring(Constantes.S_IND_QR_ENT_EE, Constantes.E_IND_QR_ENT_EE);

                ql = comando.substring(Constantes.S_IND_QL_ENT_EE, Constantes.E_IND_QL_ENT_EE);

                codigo = comando.substring(Constantes.S_IND_CODIGO_ENT_EE, Constantes.E_IND_CODIGO_ENT_EE);

                mensaje2 = comando.substring(Constantes.S_IND_MENSAJE_ENT_EE, Constantes.E_IND_MENSAJE_ENT_EE);
                mensaje2 = mensaje2.trim();

                timeout = comando.substring(Constantes.S_IND_TIMEOUT_ENT_EE, Constantes.E_IND_TIMEOUT_ENT_EE);

                dest = func.obtenerPorKey(destinos, Constantes.KEY_COLA_REQ + codigo); //Obteniendo par de colas necesarias!!

                if(dest == null)
                    throw new Exception(Constantes.DEST_ERROR);

                salida = manager.accessQueue(dest.getQueue(), MQC.MQOO_OUTPUT); //Seteando cola de response!!


                mensaje.writeBytes(mensaje2);
                mensaje.messageId = mensajeHost.getKeyString().getBytes();
                mensaje.correlationId = mensajeHost.getKeyString().getBytes();


                mensaje.format = MQC.MQFMT_STRING;

                salida.put(mensaje);



                salida.close();
                manager.disconnect();

            }

I close the connection to the queue at the end of each invoke of the timer, but seems that too many channel connections are opened and then it overloads it. So, I wanted to know how can I do to manage this?

Where is your try/catch logic? Your disconnect() is correct but either the put() or closr() is throwing an exception and your disconnect() is not being executed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM