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…

     

如果这文章对你有帮助,请扫左上角微信支付-支付宝,给于打赏,以助博客运营

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注