|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
C++ MQCONNX not works as expected |
« View previous topic :: View next topic » |
Author |
Message
|
xeonix |
Posted: Fri Oct 25, 2013 1:33 am Post subject: C++ MQCONNX not works as expected |
|
|
 Apprentice
Joined: 02 Apr 2013 Posts: 32
|
Greetings to everyone!
Since there are no standard command-line utility to get current queue depth and output it to stdout, I decided to write my own.
OS: Windows 2008 R2 (which is 64 bit)
Compiler: Microsoft Visual C++ 2012
Target app is Win32 though.
Since my app should be able to connect to remote queue managers, I have to use MQCONNX function from "cmqcfc.h" header. For the sample I took "amqscnxc.c" from "<install_path>\WebSphere MQ\tools\c\Samples", which fits my requirements best and simple enough to quickly inspect the code and understand, how the API should be used.
So first I created simple app to play around with the MQ C API. First, I need to establish connection to the queue manager "MYQM":
Code: |
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmqc.h>
#include <cmqxc.h>
int _tmain(int argc, _TCHAR* argv[]) {
MQLONG completionCode, resonCode;
MQHCONN connectionHandle;
MQCD connectionDescriptor = { MQCD_CLIENT_CONN_DEFAULT };
connectionDescriptor.TransportType = MQXPT_TCP;
connectionDescriptor.Version = MQCD_VERSION_4;
strcpy(connectionDescriptor.ChannelName, "SYSTEM.DEF.SVRCONN");
strcpy(connectionDescriptor.ConnectionName, "<IP_OF_MQSERVER>(1414)");
MQCNO connectionOptions = { MQCNO_DEFAULT };
connectionOptions.Version = MQCNO_VERSION_2;
connectionOptions.ClientConnPtr = &connectionDescriptor;
MQCONNX("MYQM", &connectionOptions, &connectionHandle, &completionCode, &resonCode);
return 0;
}
|
Quite simple, right? But when running on remote machine (comparing to <IP_OF_MQSERVER>) with another MQ installation of the same version (which means, that all client components are installed with it too) I'm getting:
completionCode = 2
resonCode = 2058
All permissions are granted, and MQ Explorer is able to connect to remote QMgr with same settings (IP, port, channel and queue manager name) I provided in code above.
What is interesting - "amqscnxc" sample app is able to connect with same settings (when passing arguments: -x <IP_OF_MQSERVER>(1414) -c SYSTEM.DEF.SVRCONN MYQM). The way it uses the API is the same I posted above. So I decided to create project from "amqscnxc.c" and to build sample app "amqscnxc" myself. After successful build I ran the app with arguments I passed earlier to it's original version... and got same "Completion Code : 2, Reason Code: 2058". I didn't modify any line of code in "amqscnxc.c" file, just created "Win32 Console Application", configured includes and lib imports, copied file "amqscnxc.c" into the project and build, but got COMPLETELY DIFFERENT BEHAVIOR OF THE SAME CODE.
MQ version is 7.5.0.2 on both machines, if that matters.
So, how do I connect to remote queue manage in the same way MQ Explorer do? |
|
Back to top |
|
 |
smdavies99 |
Posted: Fri Oct 25, 2013 1:52 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
I think that might be incorrect when you state that you must use the MQCONNX function. (I'm a little rusty here)
You can use the standard MQCONN, MQOPEN etc functions. All you need to do to make you app a client app (as opposed to a server app) is to change the libraries you link to. Well, that is how it used to be done with the "C" bindings.
Get your app working as a direct connection then relink as a client. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
xeonix |
Posted: Fri Oct 25, 2013 4:08 am Post subject: |
|
|
 Apprentice
Joined: 02 Apr 2013 Posts: 32
|
smdavies99 wrote: |
I think that might be incorrect when you state that you must use the MQCONNX function. (I'm a little rusty here)
You can use the standard MQCONN, MQOPEN etc functions. All you need to do to make you app a client app (as opposed to a server app) is to change the libraries you link to. Well, that is how it used to be done with the "C" bindings.
Get your app working as a direct connection then relink as a client. |
The reason I decided to use MQCONNX is because I can specify IP(PORT) and CHANNEL thru MQCNO.MQCD structure, while MQCONN has no such option.
As far as I understand, functions to work with MQ's objects, such as MQOPEN, MQINQ, etc. doesn't care how do I connect to queue manager (using MQCONN or MQCONNX), the just need valid MQHCONN (connection handle).
AND NOW IT'S TIME FOR WOW!
As you suggested to check linked libs, I've inspected "amqscnxc.pdb" which is located in "<install_path>\WebSphere MQ\tools\c\Samples\Bin\symbols\exe", and yes, it links to "mqic.Lib", not to "mqm.Lib" like I did! So after I changed the library my app is linked to - it's worked like a charm!
Many thanks to you, man! |
|
Back to top |
|
 |
gbaddeley |
Posted: Sun Oct 27, 2013 3:12 pm Post subject: |
|
|
 Jedi Knight
Joined: 25 Mar 2003 Posts: 2538 Location: Melbourne, Australia
|
2058 usually means the queue manager name specified in the connection does not exactly match the queue manager name that is accepting the connection. _________________ Glenn |
|
Back to top |
|
 |
xeonix |
Posted: Tue Oct 29, 2013 5:29 am Post subject: |
|
|
 Apprentice
Joined: 02 Apr 2013 Posts: 32
|
gbaddeley wrote: |
2058 usually means the queue manager name specified in the connection does not exactly match the queue manager name that is accepting the connection. |
Typically yes, but in my case the problem was completely different. That's why I was stuck with that error until smdavies99's incredibly useful hint. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|