Author |
Message
|
jpcampot |
Posted: Wed Dec 15, 2004 4:36 am Post subject: Channels remain active after queue connection is closed |
|
|
Novice
Joined: 15 Dec 2004 Posts: 10
|
Hi, I am using MQ 5.3 and MQ Classes for Java as my client. The client application is running on a Oracle 9.0.4 Application Server. The problem is that after the client application sends a message, closes the queue and disconnects the MQManager, the channel connection remains active and is never closed unless the application server shuts down. As new clients arrive, new channel connections are created but never closed until the max number of active connections is reached.
Any ideas why the channel remains open after calling the close and disconnect methods?
Thanks in advance |
|
Back to top |
|
 |
slaupster |
Posted: Wed Dec 15, 2004 5:58 am Post subject: |
|
|
Apprentice
Joined: 17 Nov 2004 Posts: 41
|
that sounds strange - you haven't written your own connection manager that is not function properly ?? Normally the channel will only stay active if there is a connection pool token in the MQEnvironment, but upon new instatiations of the MQQueueManager object, the active channel is reused.
Does the number of channels grow exactly according to the number of messages sent ? |
|
Back to top |
|
 |
jpcampot |
Posted: Wed Dec 15, 2004 6:36 am Post subject: |
|
|
Novice
Joined: 15 Dec 2004 Posts: 10
|
First of all thank you for such a fast response.
No, the number of channels grow exactly according to the number of times I open a queue . This is a piece of code of the class that I implemented:
public MQManager(){
private com.ibm.mq.MQQueueManager qMgr;
private MQQueue cola;
private boolean abrirCola(String hostname, int port, String channel, String manejadorCola, String nombreCola) {
try {
MQEnvironment.hostname = hostname;
MQEnvironment.channel = channel;
MQEnvironment.port = port;
qMgr = new MQQueueManager(manejadorCola);
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_OUTPUT ;
cola = qMgr.accessQueue(nombreCola ,openOptions,null, null, null); // no alternate user ID
return(true);
}
catch (MQException ex){
logger.error("An MQ error occurred : Completion code " +
ex.completionCode + " Reason code " + ex.reasonCode,ex);
}
return(false);
}
public boolean cerrarCola() {
try{
cola.close();
qMgr.disconnect();
return (true);
}
catch (MQException ex){
logger.error("An MQ error occurred : Completion code " +
ex.completionCode + " Reason code " + ex.reasonCode,ex);
}
return (false);
}
public String encolarMensaje(Mensaje msg) {
String msgContenido = msg.getContenido();
String id = msg.getId();
MQMessage mensaje = new MQMessage();
try{
mensaje.writeBytes(msgContenido) ;
String res = "";
if (id != null){
byte[] mid = id.getBytes(); //{Byte.parseByte(id)};
mensaje.messageId = mid;
res = id;
}
MQPutMessageOptions pmo = new MQPutMessageOptions();
cola.put(mensaje,pmo);
if (id == null){
byte[] mid = mensaje.messageId;
res=new String(mid);
}
return res;
}
catch (java.io.IOException ex){
logger.error("An error occurred while writing to the message buffer: ",ex);
return new String(mensaje.messageId);
}
catch (MQException ex){
logger.error("An MQ error occurred : Completion code " +
ex.completionCode + " Reason code " + ex.reasonCode,ex);
return new String(mensaje.messageId);
}
}
}
Example of usage:
…
MQManager mq = new MQManager();
mq.abrirCola(…..)
mq.encolarMensaje(….)
mq.cerrarCola()
mq.abrirCola(…..)
mq.encolarMensaje(….)
mq.cerrarCola()
...
After this code is executed, two channel connection remain open in MQ and are never closed until the JVM where the client application is running shuts down. |
|
Back to top |
|
 |
slaupster |
Posted: Wed Dec 15, 2004 6:48 am Post subject: |
|
|
Apprentice
Joined: 17 Nov 2004 Posts: 41
|
Do you check the value of the boolean returned by the abrirCola and cerrarCola calls ? as if there were any exceptions then this returns false, but if you don't check that then you lose that info. If the accessQueue failed, the MQQueueManager object would be created, but not the MQQueue. Closing the queue would then also fail, and still the MQQueueManager object exists, which could explain your channel instances.
Last edited by slaupster on Wed Dec 15, 2004 8:43 am; edited 1 time in total |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Dec 15, 2004 8:16 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
What CSD/FixPack level do you have applied to your WMQ code? I have a vague remembrance of a problem that was fixed in a CSD. |
|
Back to top |
|
 |
jpcampot |
Posted: Wed Dec 15, 2004 9:02 am Post subject: |
|
|
Novice
Joined: 15 Dec 2004 Posts: 10
|
I am really new to Webshpere MQ and I really do not know how to find out which CSD/FixPack is installed in my system. To explain a little more about may problem, this is another test I ran.
int tot=200;
for(int i=0;i<tot;i++){
System.out.println("-------------- " + i + " --------------");
System.out.println(mq.abrirCola(...));
Mensaje msg = new Mensaje("MSGID","MSG");
mq.encolarMensaje(msg);
System.out.println(mq.cerrarCola());
System.out.println("-------------------------------");
try{
Thread.sleep(200);
}
catch (InterruptedException e){
e.printStackTrace();
}
}
Everything works great until i reaches 100. After that, everytime I call abrirCola(…) I get the following error message:
MQJE001: Se ha producido una excepción de MQ: Código de terminación 2, Razón 2009
MQJE016: El gestor de colas MQ cerró el canal inmediatamente durante la conexión
Motivo del cierre = 2009
MQJE001: Código de terminación 2, Razón 2009
Is this the normal behaviour?
Thanks |
|
Back to top |
|
 |
RogerLacroix |
Posted: Wed Dec 15, 2004 10:22 am Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
Hi,
First off, you should separate the connect / open code from the close / disconnect code. And if you writing to the same queue, do not keep on re-opening it.
Here are 2 scenarios to think about:
Code: |
connect
...
open Q1
put to Q1
close Q1
...
open Q2
put to Q2
close Q2
...
disconnect |
Code: |
connect
...
open Q1
open Q2
open Q3
...
loop
put to Q1
put to Q2
put to Q3
endloop
...
close Q3
close Q2
close Q1
...
disconnect |
In both cases above, all interactions with the queue manager uses only ONE connection. The second scenario is important if your application we will be writting to the same queue over and over again. (i.e. in a loop).
Also, do NOT convert MessageIDs or CorrelationIDs to string. They contain binary data and you will NOT be able to do a get-by-correlID if you convert them to string. Keep them as byte array and just return byte[] from encolarMensaje().
Hope that helps.
Regards,
Roger Lacroix _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Dec 15, 2004 10:31 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
mqver will give you the fixpack that you are running. If you are encountering errors after 100 iterations, I'd bet that you are using the default for the MaxChannels, MaxActiveChannels. The default value is 100. You might need to increase this value. |
|
Back to top |
|
 |
jpcampot |
Posted: Thu Dec 16, 2004 4:29 am Post subject: |
|
|
Novice
Joined: 15 Dec 2004 Posts: 10
|
Finally!!! I separated the connect, open, close and disconnect code as RogerLacroix suggested and now it works great.
Thanks to everyone who helped me with this issue. I hope some day I can return the favour .
Happy Holidays |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Dec 16, 2004 6:04 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
jpcampot wrote: |
I hope some day I can return the favour . |
Come to the next Transaction&Messaging conference, and buy a round...  _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|