ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Channels remain active after queue connection is closed

Post new topic  Reply to topic
 Channels remain active after queue connection is closed « View previous topic :: View next topic » 
Author Message
jpcampot
PostPosted: Wed Dec 15, 2004 4:36 am    Post subject: Channels remain active after queue connection is closed Reply with quote

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
View user's profile Send private message
slaupster
PostPosted: Wed Dec 15, 2004 5:58 am    Post subject: Reply with quote

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
View user's profile Send private message
jpcampot
PostPosted: Wed Dec 15, 2004 6:36 am    Post subject: Reply with quote

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
View user's profile Send private message
slaupster
PostPosted: Wed Dec 15, 2004 6:48 am    Post subject: Reply with quote

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
View user's profile Send private message
bower5932
PostPosted: Wed Dec 15, 2004 8:16 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
jpcampot
PostPosted: Wed Dec 15, 2004 9:02 am    Post subject: Reply with quote

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
View user's profile Send private message
RogerLacroix
PostPosted: Wed Dec 15, 2004 10:22 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
bower5932
PostPosted: Wed Dec 15, 2004 10:31 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
jpcampot
PostPosted: Thu Dec 16, 2004 4:29 am    Post subject: Reply with quote

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
View user's profile Send private message
jefflowrey
PostPosted: Thu Dec 16, 2004 6:04 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Channels remain active after queue connection is closed
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.