MQ Serie and JDE One World on Unix

marc_pfa

Member
Hi list,

I'm new to MQ serie and i want to send a message from Unix to MQ using a JDE batch program(bsfn).
I have a custom business fonction in C called by a batch program on a Unix server. The purpose of this function is simply to put a message in a MQ queue. My function is based on the one founded in MQ sample. I tried to do a connect(MQCONN), a open(MQOPEN) and a put(MQPUT), without succes. I found that i need to load or read libmqm.a on Unix server to found the MQ functions. I try two different ways and it doesn't works.

Here's what i tried and the result :

1. I tried with a load library
hLib = LoadLibrary("/usr/mqm/lib64/libmqm.a");

2. Then i tried with a dlopen
strcpy(dlLib, "libmqm.a(libmqm.o)");
so = dlopen(dlLib, RTLD_MEMBER | RTLD_GLOBAL | RTLD_NOW);

this time, the params returned by the MQCONN and MQOPEN was looking like that:
0U!x¨
ñptX/ñ÷0****Ó‚ô\********ñqkl/ñò(ñpx(/ñ÷äñpvL0fà

Maybe i'm not looking at the good library(libmqm.a) on the server.

Sécurity:
-We run batch program with JDE account,
-JDE have full access on Queue manager and queues
-MQ and JDE are installed on the same box

Any ideas ?

thks,

Marc



JDE B7333 SP24, Unix Aix, MQSerie 6.0.0

here's my fucntion code's

#include <b5901001.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmqc.h>
#include <dlfcn.h> /* This exists on AIX 4.2 or later */


/**************************************************************************
* Business Function: SendXMLtoMQSeries
*
* Description: Send XML Message to MQ Series
*
* Parameters:
* LPBHVRCOM lpBhvrCom Business Function Communications
* LPVOID lpVoid Void Parameter - DO NOT USE!
* LPDSD5901001 lpDS Parameter Data Structure Pointer
*
*************************************************************************/

JDEBFRTN (ID) JDEBFWINAPI SendXMLtoMQSeries (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5901001 lpDS)
{
/************************************************************************
* Variable declarations
************************************************************************/


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 */
MQLONG messlen; /* message length */
MQBYTE buffer[101]; /* message buffer */
MQLONG buflen; /* buffer length */

char QMName[50]; /* queue manager name */
char MainMessage[200];
char szErrorMessageId[11];
char szTimeDescription[27];
char StrHcon[30];
char StrHobj[30];
char StrCompCode[30];
char StrCReason[30];
char StrReason[30];
char StrOpenCode[30];
char StrO_Options[30];
/************************************************************/
/* The next set of variables will be used to get the shared */
/* library and the entry points into the shared library. */
/************************************************************/
char dlLib[50]; /* name of the MQSeries library to load */
void *so ;
void (*sconn)(char *, MQHCONN *, MQLONG *, MQLONG *);
void (*sopen)(MQHCONN, MQOD *, MQLONG, MQHOBJ *, MQLONG *, MQLONG *);
void (*sget) (MQHCONN, MQHOBJ, MQMD *, MQGMO *, MQLONG, MQBYTE *, MQLONG *, MQLONG *, MQLONG *);
void (*sclose)(MQHCONN, MQHOBJ *, MQLONG, MQLONG *, MQLONG *);
void (*sdisc)(MQLONG *, MQLONG *, MQLONG *);
char cError;
/************************************************************************
* Declare structures
************************************************************************/
/* Declare MQI structures needed */
MQOD od = {MQOD_DEFAULT}; /* Object Descriptor */
MQMD md = {MQMD_DEFAULT}; /* Message Descriptor */
/* MQPMO pmo = {MQPMO_DEFAULT}; /* put message options */
MQGMO gmo = {MQGMO_DEFAULT}; /* get message options */
/** note, sample uses defaults where it can **/

/************************************************************************
* Declare pointers
************************************************************************/
/************************************************************************
* Check for NULL pointers
************************************************************************/
if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
(lpVoid == (LPVOID) NULL) ||
(lpDS == (LPDSD5901001) NULL))
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, "4363", (LPVOID) NULL);
return ER_ERROR;
}
/************************************************************************
* Set pointers
************************************************************************/

/************************************************************************
* Main Processing
************************************************************************/

strcpy(dlLib, "libmqm.a(libmqm.o)");
so = dlopen(dlLib, RTLD_MEMBER | RTLD_GLOBAL | RTLD_NOW);

jdeWriteLog("B5901001", 2, "Apres call LIBMQM\n");


if (!so)
{
printf("MQSeries does not exist on this system.\n");
printf("Program exiting.\n");
exit(0);

jdeWriteLog("B5901001", 3, "Erreur so\n");
}
else
{
jdeWriteLog("B5901001", 4, "Pas d'Erreurs sur so\n");

sconn = (void(*)(char *, MQHCONN *, MQLONG *, MQLONG *))dlsym(so , "MQCONN");

ltoa(Hcon, StrHcon, 30);
ltoa(CompCode, StrCompCode, 30);
ltoa(CReason, StrCReason, 30);
jdeWriteLog("B5901001 Conn", 5, QMName );
jdeWriteLog("B5901001 Conn", 6, StrHcon );
jdeWriteLog("B5901001 Conn", 7, StrCompCode );
jdeWriteLog("B5901001 Conn", 8, StrCReason );


if (!sconn)
{
jdeWriteLog("B5901001", 9, "Erreur sur sconn\n");

printf("sconn call failed.\n");
exit(0);
}
else
{
printf("sconn symbol resolved\n");
}

sopen = (void(*)(MQHCONN, MQOD *, MQLONG, MQHOBJ *, MQLONG *, MQLONG *))dlsym (so, "MQOPEN");

ltoa(Hcon, StrHcon, 30);
ltoa(o_Options, StrO_Options, 30); /* o_Options*/
ltoa(Hobj, StrHobj, 30);
ltoa(CompCode, StrOpenCode, 30);
ltoa(CReason, StrReason, 30);

jdeWriteLog("B5901001 Open", 10, StrHcon );
jdeWriteLog("B5901001 Open", 11, StrO_Options );
jdeWriteLog("B5901001 Open", 11, StrHobj );
jdeWriteLog("B5901001 Open", 12, StrCompCode );
jdeWriteLog("B5901001 Open", 13, StrCReason );

if (!sopen)
{
jdeWriteLog("B5901001", 14, "Erreur sur sopen\n");

printf("sopen call failed.\n");
exit(0);
}
else
{
printf("sopen symbol resolved\n");
}

sget = (void(*)(MQHCONN, MQHOBJ, MQMD *, MQGMO *,
MQLONG, MQBYTE *, MQLONG *, MQLONG *, MQLONG *))dlsym(so, "MQGET");
if (!sget)
{
printf("sget call failed.\n");
exit(0);
}
else
{
printf("sget symbol resolved\n");
}

sclose = (void(*)(MQHCONN, MQHOBJ *, MQLONG, MQLONG *, MQLONG *))dlsym(so, "MQCLOSE");

if (!sclose)
{
printf("sclose call failed.\n");
exit(0);
}
else
{
printf("sclose symbol resolved\n");
}

sdisc = (void(*)(MQLONG *, MQLONG *, MQLONG *))dlsym(so, "MQDISC");
if (!sdisc)
{
printf("sdisc call failed.\n");
exit(0);
}
else
{
printf("sdisc symbol resolved\n");
}
}


/******************************************************************/
/* */
/* Connect to queue manager */
/* */
/******************************************************************/


sconn(QMName, &Hcon, &CompCode, &CReason);

if (CompCode == MQCC_FAILED)
{
printf("MQCONN ended with reason code %d\n", CReason);
exit ((int)CReason);
}

/******************************************************************/
/* */
/* Use parameter as the name of the target queue */
/* */
/*******************************************************************/

strncpy(od.ObjectName, lpDS->szMessageQueue, (size_t)MQ_Q_NAME_LENGTH);

/******************************************************************/
/* */
/* Open the target message queue for input */
/* */
/******************************************************************/


o_Options = MQOO_INPUT_AS_Q_DEF /* open queue for output */
| MQOO_FAIL_IF_QUIESCING; /* but not if MQM stopping */
sopen(Hcon, &od, o_Options, &Hobj, &OpenCode, &Reason);

if (Reason != MQRC_NONE)
{
printf("MQOPEN ended with reason code %d\n", Reason);
}

if (OpenCode == MQCC_FAILED)
{
printf("Unable to Open queue for \n");
}

/******************************************************************/

memcpy(md.Format, /* character string format */
MQFMT_STRING, (size_t)MQ_FORMAT_LENGTH);

/******************************************************************/
/* */
/* Put each buffer to the message queue */
/* */
/******************************************************************/

messlen = strlen(lpDS->szMainMessage); /* length without null */

/**************************************************************/
/* The following two statements are not required if the */
/* MQPMO_NEW_MSG_ID and MQPMO_NEW _CORREL_ID options are used */
/**************************************************************/

strcpy(MainMessage, lpDS->szMainMessage);
buflen = sizeof(buffer) - 1; /* buffer size available for GET */
memcpy(md.MsgId, /* reset MsgId to get a new one */
MQMI_NONE, sizeof(md.MsgId) );
memcpy(md.CorrelId, /* reset CorrelId to get a new one */
MQCI_NONE, sizeof(md.CorrelId) );
gmo_Options = MQGMO_WAIT /* wait for new messages */
+ MQGMO_CONVERT;/* convert if necessary */
gmo.WaitInterval = 15000; /* 15 second limit for waiting */


md.Encoding = MQENC_NATIVE;
md.CodedCharSetId = MQCCSI_Q_MGR;


sget(Hcon, Hobj, &md, &gmo, buflen, buffer, &messlen, &CompCode, &Reason);

if (Reason != MQRC_NONE)
{
printf("MQGET ended with reason code %d\n", Reason);
}

/******************************************************************/
/* */
/* Close the target queue (if it was opened) */
/* */
/******************************************************************/

if (OpenCode != MQCC_FAILED)
{
C_options = 0; /* no close options */

sclose(Hcon, &Hobj, C_options, &CompCode, &Reason);

if (Reason != MQRC_NONE)
{
printf("MQCLOSE ended with reason code %d\n", Reason);
}

}

/******************************************************************/
/* */
/* Disconnect from MQM if not already connected */
/* */
/******************************************************************/


if (CReason != MQRC_ALREADY_CONNECTED)
{


sdisc(&Hcon, &CompCode, &Reason);
if (Reason != MQRC_NONE)
{
printf("MQDISC ended with reason code %d\n", Reason);
}

}

else


/************************************************************************
* Function Clean Up
************************************************************************/

return (ER_SUCCESS);

}
 
Back
Top