Интеграция приложений на основе WebSphere MQ


Example.9.2


/* Листинг программы transmit */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <io.h> #include <cmqc.h> char queue_input[48] = ""; char queue_output[48] = ""; char queue_reply[48] = ""; char reply_time[48] = ""; char buf[48]; time_t tmr; int queuenamelen; FILE *fptr;

int main(int argc, char **argv) { MQOD odG = {MQOD_DEFAULT}; MQOD odP = {MQOD_DEFAULT}; MQOD odR = {MQOD_DEFAULT}; MQOD odI = {MQOD_DEFAULT}; MQMD md = {MQMD_DEFAULT}; MQBO mbo = {MQBO_DEFAULT}; MQGMO gmo = {MQGMO_DEFAULT}; MQPMO pmo = {MQPMO_DEFAULT}; MQCHAR48 QManager; MQHCONN Hcon; MQHOBJ Hobj; MQHOBJ Hout; MQHOBJ Hrep; MQLONG O_options; MQLONG C_options; MQLONG CompCode; MQLONG Reason; MQLONG CReason; MQBYTE buffer[8001]; MQLONG buflen; MQLONG replylen; MQLONG messlen; static MQBYTE24 LastMsgId;

if ( (fptr=fopen ("transmit.ini","r" )) == NULL ) {printf("Cannot open transmit.ini file" ); exit(1); } else{ fgets(queue_input, 48, fptr); queuenamelen = strlen(queue_input) - 1; queue_input[queuenamelen] = ' '; strcpy(odG.ObjectName, queue_input);

fgets(queue_output, 48, fptr); queuenamelen = strlen(queue_output) - 1; queue_output[queuenamelen] = ' '; strcpy(odP.ObjectName, queue_output);

fgets(queue_reply, 48, fptr); queuenamelen = strlen(queue_reply) - 1; queue_reply[queuenamelen] = ' '; strcpy(odR.ObjectName, queue_reply);

fgets(reply_time, 48, fptr); queuenamelen = strlen(reply_time) - 1; reply_time[queuenamelen] = ' '; fclose (fptr); } strcpy(QManager, ""); /* Работаем с менеджером очередей по умолчанию */ MQCONN(QManager, &Hcon, &CompCode, &CReason); if (CompCode == MQCC_FAILED) { printf("MQCONN to %s ended with reason code %ld\n", QManager, CReason); exit(CReason); }

O_options = MQOO_BROWSE + MQOO_INPUT_SHARED ; MQOPEN(Hcon, &odG, O_options, &Hobj, &CompCode, &Reason); if (Reason != MQRC_NONE) { printf("MQOPEN %s ended with reason code %ld\n", queue_input, Reason); } if (CompCode == MQCC_FAILED) { exit(Reason); }

O_options = MQOO_BROWSE + MQOO_INPUT_SHARED ; MQOPEN(Hcon, &odR, O_options, &Hrep, &CompCode, &Reason); if (Reason != MQRC_NONE) { printf("MQOPEN %s ended with reason code %ld\n", queue_reply, Reason); } if (CompCode == MQCC_FAILED) { exit(Reason); }

O_options = MQOO_OUTPUT ; MQOPEN(Hcon, &odP, O_options, &Hout, &CompCode, &Reason); if (Reason != MQRC_NONE) { printf("MQOPEN %s ended with reason code %ld\n", queue_output, Reason); } if (CompCode == MQCC_FAILED) { exit(Reason); }

while (CompCode == MQCC_OK) { buflen = sizeof(buffer) - 1; memcpy(md.MsgId, MQMI_NONE, sizeof(md.MsgId)); memcpy(md.CorrelId, MQCI_NONE, sizeof(md.CorrelId)); gmo.Options = MQGMO_ACCEPT_TRUNCATED_MSG + MQGMO_WAIT + MQGMO_SYNCPOINT; gmo.WaitInterval = 3000 ;

MQBEGIN (Hcon, &mbo, &CompCode, &Reason); MQGET(Hcon, Hobj, &md, &gmo, buflen, buffer, &messlen, &CompCode, &Reason); //if (Reason != MQRC_NONE) { printf("MQGET from %s ended with reason code %ld\n", queue_input, Reason); }

if ((CompCode == MQCC_OK) || (CompCode == MQCC_WARNING)) { buffer[messlen] = '\0'; /* заносим символ конец строки в буфер с прочитанным сообщением */ buflen = messlen; md.MsgType = MQMT_REQUEST; md.Report = MQRO_EXCEPTION_WITH_DATA; strncpy(md.ReplyToQ, queue_reply, MQ_Q_NAME_LENGTH); memcpy(md.Format, MQFMT_STRING, MQ_FORMAT_LENGTH);

MQPUT(Hcon, Hout, &md, &pmo, buflen, buffer, &CompCode, &Reason); if (Reason != MQRC_NONE) { printf("MQPUT to %s ended ended unsuccessfully with reason code %ld CompCode %ld\n", queue_output, Reason, CompCode ); MQBACK( Hcon, &CompCode, &Reason ) ; CompCode = MQCC_FAILED ; } else {

while (CompCode != MQCC_FAILED) { /** осуществляется проверка queue_reply **/ gmo.Options = MQGMO_ACCEPT_TRUNCATED_MSG + MQGMO_WAIT ; gmo.WaitInterval = 3000 ; memcpy(md.MsgId, MQMI_NONE, sizeof(md.MsgId)); memcpy(md.CorrelId, MQCI_NONE, sizeof(md.CorrelId)); MQGET(Hcon, Hrep, &md, &gmo, buflen, buffer, &replylen, &CompCode, &Reason); if (CompCode != MQCC_FAILED) { if (md.MsgType == MQMT_REPLY) /* report feedback */ { printf("Transaction % s=> %s successfully: %s\n", queue_input, queue_output, buffer); MQCMIT( Hcon, &CompCode, &Reason ) ; } else { printf("Transaction % s=> %s successfully, REPLY message not deliver, reason code %ld CompCode %ld\n", queue_input, queue_output, queue_reply, Reason, CompCode ); MQBACK( Hcon, &CompCode, &Reason ) ; CompCode = MQCC_FAILED ; } }

if (Reason == MQRC_NO_MSG_AVAILABLE) { printf("Transaction % s=> %s UNsuccessfully, REPLY message not deliver\n", queue_input, queue_output ); MQBACK( Hcon, &CompCode, &Reason ) ; CompCode = MQCC_FAILED ; } } } } } C_options = 0; MQCLOSE(Hcon, &Hobj, C_options, &CompCode, &Reason); if (Reason != MQRC_NONE){printf("MQCLOSE %s ended with reason code %ld\n", queue_input, Reason); } MQCLOSE(Hcon, &Hout, C_options, &CompCode, &Reason); if (Reason != MQRC_NONE){printf("MQCLOSE %s ended with reason code %ld\n", queue_output, Reason); } MQCLOSE(Hcon, &Hrep, C_options, &CompCode, &Reason); if (Reason != MQRC_NONE){printf("MQCLOSE %s ended with reason code %ld\n", queue_reply, Reason); }

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

Листинг 9.2. Программа transmit.cpp для Microsoft Visual C++ ver.6.0.

Закрыть окно




Начало  Назад  Вперед



Книжный магазин