|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
MQ C/C++ api for linux |
« View previous topic :: View next topic » |
Author |
Message
|
tarangsethia |
Posted: Thu Oct 30, 2008 8:58 am Post subject: MQ C/C++ api for linux |
|
|
Newbie
Joined: 30 Oct 2008 Posts: 3
|
I have a c/c++ legacy app which connects to the local queue manager using MQCONN and processes messages.
I want to convert this app to connect to remote MQ on a different box. How do I change my code to specify the remote hostname, port and type of connection while not changing the flow of the program.
Currently the code uses the following functions. Please let me know if I can change the MQ options to connect to a remote queue manager and remote queue using the same api.
// Declare MQI structures needed
MQOD od = {MQOD_DEFAULT}; // Object Descriptor
MQMD md = {MQMD_DEFAULT}; // Message Descriptor
MQGMO gmo = {MQGMO_DEFAULT}; // get message options
MQHCONN Hcon; // connection handle
MQHOBJ Hobj; // object handle
MQLONG O_options; // MQOPEN options
MQLONG C_options; // MQCLOSE options
MQLONG CompCode; // completion code
MQLONG OpenCode; // MQOPEN completion code
MQLONG Reason; // reason code
MQLONG CReason; // reason code for MQCONN
MQBYTE buffer[512000]; // message buffer
MQLONG buflen; // buffer length
MQLONG messlen; // message length received
char QMName[50]; // queue manager name
O_options = MQOO_INPUT_AS_Q_DEF // open queue for input
+ MQOO_FAIL_IF_QUIESCING; // but not if MQM stopping
MQCONN(QMName, &Hcon, &CompCode, &CReason);
if (CompCode == MQCC_FAILED)
{
//printf("if MQCC_FAILED\n");
}
MQOPEN(Hcon, &od, O_options, &Hobj, &OpenCode, &Reason);
//printf("after MQOPEN\n");
if (Reason != MQRC_NONE)
{
//printf("if Reason != MQRC_NONE\n");
MQDISC(&Hcon, &CompCode, &Reason);
}
MQGET(Hcon, Hobj, &md, &gmo, buflen, buffer, &messlen, &CompCode,&Reason);
MQCMIT(Hcon, &CompCode, &Reason);
MQBACK(Hcon, &CompCode, &Reason); |
|
Back to top |
|
 |
bower5932 |
Posted: Thu Oct 30, 2008 9:48 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
Take a look at the MQCONNX call. It has an additional parameter that allows you to specify client connect information. |
|
Back to top |
|
 |
tarangsethia |
Posted: Thu Oct 30, 2008 10:38 am Post subject: |
|
|
Newbie
Joined: 30 Oct 2008 Posts: 3
|
If I use MQCONNX, will I be able to connect to a queue manager on a different machine specifying the hostname and channel configuration. Can somebody provide an example of that. If yes can I use the existing MQGET etc api. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Oct 30, 2008 11:04 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
tarangsethia wrote: |
If I use MQCONNX, will I be able to connect to a queue manager on a different machine specifying the hostname and channel configuration. |
Your lack of faith in the previous poster is disturbing.
You can also obtain the same effect by setting the hostname etc in one of the client configuration methods laid out in the Client manual. If you do that you can stay with the MQCONN call.
tarangsethia wrote: |
Can somebody provide an example of that. |
There are examples with the product and on the IBM site.
tarangsethia wrote: |
If yes can I use the existing MQGET etc api. |
Once you've established a connection (using MQCONNX or MQCONN in either of it's forms) and obtained a connection handle that's all the other calls need. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
bower5932 |
Posted: Thu Oct 30, 2008 12:46 pm Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
tarangsethia wrote: |
If I use MQCONNX, will I be able to connect to a queue manager on a different machine specifying the hostname and channel configuration. Can somebody provide an example of that. If yes can I use the existing MQGET etc api. |
The WMQ product already provides a sample - amqscnxc.c. |
|
Back to top |
|
 |
tarangsethia |
Posted: Fri Oct 31, 2008 11:34 am Post subject: |
|
|
Newbie
Joined: 30 Oct 2008 Posts: 3
|
I use the below code and I get 2058 when connecting from a different machine. When I connect from the same machine, it works fine. Can somebody please help.
////////////////////////////////////////////////////////////////
// Declare MQI structures needed
MQOD od = {MQOD_DEFAULT}; // Object Descriptor
MQMD md = {MQMD_DEFAULT}; // Message Descriptor
MQGMO gmo = {MQGMO_DEFAULT}; // get message options
MQHCONN Hcon; // connection handle
MQHOBJ Hobj; // object handle
MQLONG O_options; // MQOPEN options
MQLONG C_options; // MQCLOSE options
MQLONG CompCode; // completion code
MQLONG OpenCode; // MQOPEN completion code
MQLONG Reason; // reason code
MQLONG CReason; // reason code for MQCONN
MQBYTE buffer[512000]; // message buffer
MQLONG buflen; // buffer length
MQLONG messlen; // message length received
char QMName[50]; // queue manager name
//new MQI structures defined
MQCNO Connect_options = {MQCNO_DEFAULT};
/* MQCONNX options */
MQCD ClientConn = {MQCD_CLIENT_CONN_DEFAULT};
char *p_argConnName = "10.58.165.39(1416)"; /* connection name from user */
char *p_argChannelName = "EDPODS.SVRCONN";/* channel name from user */
//p_argConnName = "10.58.165.38(1416)"; /* connection name from user */
//p_argChannelName = "EDPODS.SVRCONN";/* channel name from user */
MQLONG Selector; /* selector for inquiry */
////////////////////////////////////////////////////////////////
O_options = MQOO_INPUT_AS_Q_DEF // open queue for input
+ MQOO_FAIL_IF_QUIESCING; // but not if MQM stopping
iterations = 0; //count total pnrs processed
int errors = 0; //start count of errors
int successes = 0; //start success count between errors
strcpy(QMName, manager);
strcpy(od.ObjectName, queue);
////MQ connection name and channnel name configuration added.
strcpy(ClientConn.ConnectionName,
p_argConnName);
strcpy(ClientConn.ChannelName,
p_argChannelName);
/* Point the MQCNO to the client connection definition */
Connect_options.ClientConnPtr = &ClientConn;
/* Client connection fields are in the version 2 part of the
MQCNO so we must set the version number to 2 or they will
be ignored */
Connect_options.Version = MQCNO_VERSION_2;
MQCONNX(QMName, /* queue manager */
&Connect_options, /* options for connection */
&Hcon, /* connection handle */
&CompCode, /* completion code */
&CReason); /* reason code */ |
|
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
|
|
|
|