WebSphere MQ出口程序編寫和配置3

4.1 創建出口程序的動態鏈接庫

以消息出口程序msgexit.c為例創建相應的鏈接庫。

    編譯連接:cl /MT /LD msgexit.c msgexit.def

    將生成的msgexit.dll文件放在exit程序專用的目錄下,c:\mqm\exits

4.2 環境設置

1) 創建隊列管理器,設置通道

假設我們在兩台Windows2000系統上,各建一個隊列管理器QMA和QMB,並且在QMA上建立發送通道A.TO.B,在QMB上建立接收通道A.TO.B,以及所需的本地隊列,傳輸隊列和遠程隊列。消息將從QMA發送到QMB。

2)增加通道消息出口定義

在接收端定義接收通道中的消息出口:

ALTER CHANNEL(A.TO.B) CHLTYPE(RCVR) +

MSGEXIT(‘c:\mqm\exits\MSGEXIT(MsgExit)’)


 

 

在發送端定義發送通道中的消息出口:

ALTER CHANNELL(A.TO.B) CHLTYPE(SDR) +

MSGEXIT(‘c:\mqm\exits\MSGEXIT(MsgExit)’)


 

 

4.3 出口程序的驗證

4.3.1 安全出口程序的驗證方法:

    首先,在沒有調用安全出口的情況下,使用PING CHANNEL命令檢查通道是否可用。

    在創建了庫文件、配置完畢後,可以在有出口的情況下測試系統。首先還是應使用PING CHANNEL命令檢查通道是否可用。

    如果在編譯出口程序時選擇DEBUG編譯模式,則可以對PING通道的初始化、中斷的過程進行跟蹤。

    然後,定義遠程隊列,向其中放入消息,觀察通道的狀態,並在目的端從其接收隊列中取出消息。

    以上步驟通過後,並且消息傳輸無誤,則出口程序驗證成功。

4.3.2 消息出口程序的驗證方法:

    在MQA端上,用 amqsput <遠程隊列名> 向遠程隊列中放入若干文本消息。

    在MQB端上,用 amqsget <本地隊列名> 從接收隊列取出這些消息。

    比較放入的文本與取出的文本,雙方一致說明消息出口程序處理正確。

    查看c:\msgexit.log文件,以了解msgexit的運行日誌。

附件:消息出口源程序msgexit.c

/* standard headers */

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <errno.h>

#include <locale.h>

/*#ifdef AIX*/

#include <langinfo.h>

/*#endif*/

#include <sys/types.h>

#include <sys/timeb.h>

#include <time.h>

/* MQSeries headers */

#include <cmqc.h>

#include <cmqxc.h>

char timebuf[130];

char Channel_Logfile[129]=”msgexit.log”;

FILE * OST = 0;

 

/* define output file and statement prototype */

#define DBGPRINTF(x) { \

OST=fopen(Channel_Logfile,”a+”); \

if(OST) fprintf x; \

fclose(OST); \

}

void encrypt(long *, char *); /* prototype for file encrypting function */

/* dummy function used as entry point to exit, only needed for AIX boxes */

void MQENTRY MQStart(void) {;}

void MQENTRY MsgExit( PMQCXP pChannelExitParams,

PMQCD pChannelDefinition,

PMQLONG pDataLength,

PMQLONG pAgentBufferLength,

PMQBYTE AgentBuffer,

PMQLONG pExitBufferLength,

PMQPTR pExitBufferAddr)

{

struct timeb t;

char millisec[25];

 

/*** Get time string to use in all messages ***/

time_t clock = time( (time_t*) NULL);

struct tm *tmptr = localtime(&clock);

strcpy(timebuf, asctime(tmptr));

ftime( &t );

memset( millisec, 0, sizeof( millisec ) );

sprintf( millisec, ” Time:%ld.%d”, t.time, t.millitm );

strcat( timebuf, millisec );

/*** Check call type – initialization, message, or exit ***/

/* */

switch( pChannelExitParams-> ExitReason )

{

case MQXR_INIT:

DBGPRINTF((OST,”\nChannel message exit called at MCA initialization %s”,timebuf));

break;

case MQXR_MSG:

/*** Call subroutine to encrypt the message ***/

/* */

encrypt(pDataLength, (char *)AgentBuffer);

DBGPRINTF((OST,”\nMessage Transfering, length = %li %s \n”,*pDataLength, timebuf));

break;

case MQXR_TERM:

DBGPRINTF((OST, “\nMessage channel exit called at MCA termination %s\n”,timebuf));

break;

default:

DBGPRINTF((OST,”\nMessage channel exit called with invalid reason code: %d %s”,

pChannelExitParams-> ExitReason, timebuf));

break;

} /* switch */

 

/*** Set exit response = OK in all circumstances ***/

pChannelExitParams -> ExitResponse = MQXCC_OK;

return;

 

}/* end exit */

/*——————————————————————

encrypt() – encrypt a MQSeries message with user-defined algorithm.

——————————————————————-*/

void encrypt(long *lngth, char *bf)

{

long i,j;

unsigned char ch;

long temp = sizeof(MQXQH);

j = * lngth;

/*DBGPRINTF((OST,”\nMQXQH length : %d\n”,temp));*/

for(i = temp; i < j; i++)

{

ch = bf[i];

ch = 0 – ch;

bf[i] = ch;

/*DBGPRINTF((OST,”\nMessage number: %d”,i));*/

}

} /* end writer */


 

以下文章點擊率最高

Loading…

     

如果這文章對你有幫助,請掃左上角微信支付-支付寶,給於打賞,以助博客運營