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 » General IBM MQ Support » How to check connection status with C APIs

Post new topic  Reply to topic
 How to check connection status with C APIs « View previous topic :: View next topic » 
Author Message
koushikt
PostPosted: Fri Jul 24, 2015 3:37 pm    Post subject: How to check connection status with C APIs Reply with quote

Novice

Joined: 26 Jan 2015
Posts: 14

I have a mq listener written in C. I use MQCONN to connect to the Queue Manager and MQGET to listen for messages. But my messages are not that much. So, when my connection gets disconnected often and I error out on get.
How do I check if I have an active connection before I read/publish.
Thanks.
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Fri Jul 24, 2015 4:44 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7717

You don't. Because 1 nanosecond after you get a response that the connection is there, it can be gone.

You don't call your friend on the phone, and when he answers say "OK good, you are there. I'm going to hang up now and call you back so we can talk, because now I know you are there."
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
vsathyan
PostPosted: Fri Jul 24, 2015 7:26 pm    Post subject: Reply with quote

Centurion

Joined: 10 Mar 2014
Posts: 121

A simple step you can do is to check if the queue manager object in your program is not null before you call the open/put/get/calls on the queue.

Hope my understanding is not wrong from your question.

Thanks,
vsathyan
_________________
Custom WebSphere MQ Tools Development C# & Java
WebSphere MQ Solution Architect Since 2011
WebSphere MQ Admin Since 2004
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Sat Jul 25, 2015 7:18 am    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7717

vsathyan wrote:
A simple step you can do is to check if the queue manager object in your program is not null before you call the open/put/get/calls on the queue.

Hope my understanding is not wrong from your question.

Thanks,
vsathyan


It is pointless to do that. Just because the connection is valid when you check it doesn't mean it will be valid a split second later when you actually try and use it.

Establish your connections and assume they are good and use them. MQ will give you a very specific reason code on your failed get or put or open or close or commit or backout or set or inq or etc, etc, etc if the connection is no longer valid. It is a waste of CPU cycles to check the connection before trying to use the connection.
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
bruce2359
PostPosted: Sat Jul 25, 2015 7:52 am    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9396
Location: US: west coast, almost. Otherwise, enroute.

PeterPotkay wrote:
You don't. Because 1 nanosecond after you get a response that the connection is there, it can be gone.

You don't call your friend on the phone, and when he answers say "OK good, you are there. I'm going to hang up now and call you back so we can talk, because now I know you are there."

The same type of questions have been asked regarding how to check to see (inquire on queue depth) if there are messages in a queue before doing an MQGET, and how to check to see if a sender channel is RUNNING before issuing an MQPUT.

The answer remains the same: You don't. You don't need to.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
tczielke
PostPosted: Sat Jul 25, 2015 8:26 am    Post subject: Reply with quote

Guardian

Joined: 08 Jul 2010
Posts: 939
Location: Illinois, USA

If your C code is using a client connection, then just use client auto reconnection -> http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.con.doc/q017800_.htm?lang=en

If the connection is broken when you do your MQGET, the MQ client code will reconnect you under the covers.
_________________
Working with MQ since 2010.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Jul 27, 2015 4:33 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

If your gets are infrequent, you should consider using triggering instead of sitting in a wait loop.
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Mon Jul 27, 2015 4:09 pm    Post subject: Reply with quote

Jedi

Joined: 25 Mar 2003
Posts: 2494
Location: Melbourne, Australia

mqjeff wrote:
If your gets are infrequent, you should consider using triggering instead of sitting in a wait loop.

Yes. If the MQ Client connection only exists when it is needed, it is less likely to suffer from random network glitches. This is the rationale behind DISCINT on SENDER channels etc. If the channel is not running when its not actually needed, it is less prone to random n/w or comms stack errors.
_________________
Glenn
Back to top
View user's profile Send private message
zpat
PostPosted: Mon Jul 27, 2015 9:52 pm    Post subject: Reply with quote

Jedi Council

Joined: 19 May 2001
Posts: 5849
Location: UK

Set keepalive yes and socket timeout to 15 seconds in mqclient.ini
_________________
Well, I don't think there is any question about it. It can only be attributable to human error. This sort of thing has cropped up before, and it has always been due to human error.
Back to top
View user's profile Send private message
koushikt
PostPosted: Thu Jul 30, 2015 3:50 pm    Post subject: Reply with quote

Novice

Joined: 26 Jan 2015
Posts: 14

Thanks everyone. I used the auto reconnect parameter from MQCONNX. I was using MQCONN so far and I never knew about the possibility of passing options.
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 » General IBM MQ Support » How to check connection status with C APIs
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.