no message

更新时间:2023-01-03 11:31:52 阅读: 评论:0


2023年1月3日发(作者:致命伴侣下载)

WebSphereMQForJAVA编程实例----实现MQtrigger---配置篇

首先做如下配置定义:

Urunmqsctocreatethefollowingobjects:

obetriggered.

DEFINEQLOCAL('')REPLACE+

DESCR('Applicationqueuetotesttriggering')+

SHARE+

TRIGGER+

TRIGTYPE(FIRST)+

INITQ('')+

PROCESS('S')

tionqueue.

DEFINEQLOCAL('')REPLACE+

DESCR('Initiationqueuetotesttriggering')

s.**

DEFINEPROCESS('S')REPLACE+

DESCR('Processtotesttriggering')+

APPLICID('java-

cp.;c:mqmjavalib;c:;c:;c:mqmjavali

aTrigger')

hetriggermonitorwith

**Note:

anbeloadedfromthe

currentdirectoryandresolvedby"."intheclasspath.

Ifyourjavacodeisincludedinapackage,thenthejarmay

beaddedtotheclasspathandthelocationwhererunmqtrmis

starteddoesnotmatter.

ggerinformationalong

withthefirst20charactersofthemessageisdisplayedinthe

windowwhererunmqtrmisactive.

WebSphereMQForJAVA编程实例----实现MQtrigger---样例

源码如下:

.*;

.*;

.*;

classMQTrigger

{

privateStringstructId;

privateStringversion;

privateStringqName;

privateStringprocessName;

privateStringtriggerData;

privateStringapplType;

privateStringapplId;

privateStringenvData;

privateStringurData;

privateStringqMgrName;

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

/*ConstructortopartheMQTMC2stuctureandt*/

/*theclassattributes.*/

/*Valuesderivedfromfielddefinitionsgivenfor*/

/*MQTMC2intheWebSphereApplicationProgramming*/

/*Reference.*/

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

publicMQTrigger(StringtmcStruct)throwsStringIndexOutOfBoundsException

{

structId=ing(0,3).trim();

version=ing(4,8).trim();

qName=ing(8,55).trim();

processName=ing(56,103).trim();

triggerData=ing(104,167).trim();

applType=ing(168,171).trim();

applId=ing(172,427).trim();

envData=ing(428,555).trim();

urData=ing(556,683).trim();

qMgrName=ing(684,730).trim();

}

publicStringgetStructId()

{

return(structId);

}

publicStringgetVersion()

{

return(version);

}

publicStringgetQueueName()

{

return(qName);

}

publicStringgetProcessName()

{

return(processName);

}

publicStringgetTriggerData()

{

return(triggerData);

}

publicStringgetApplicationType()

{

return(applType);

}

publicStringgetApplicationId()

{

return(applId);

}

publicStringgetEnvironmentData()

{

return(envData);

}

publicStringgetUrData()

{

return(urData);

}

publicStringgetQueueManagerName()

{

return(qMgrName);

}

}

源码如下:

ption;

;

ption;

essageOptions;

age;

e;

eManager;

publicclassJavaTrigger

{

privateMQQueueManagerqMgr;

publicstaticvoidmain(Stringargs[])throwsIOException

{

if(<1)

{

n("Thismustbeatriggeredapplication");

}

el

{

JavaTriggerjt=newJavaTrigger();

(args);

}

(0);

}

publicvoidstart(Stringargs[])

{

try

{

=null;

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

/*CreateaMQTriggerclassobjecttoreadtheMQTMC2*/

/*structureintothecorrectattribute.*/

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

MQTriggertmc=newMQTrigger(args[0]);

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

/*Connecttothequeuemanageridentifiedbythe*/

/*trigger.*/

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

qMgr=newMQQueueManager(ueManagerName());

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

/*Openthequeueidentifiedbythetrigger.*/

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

intopenOptions=_INPUT_AS_Q_DEF

|_FAIL_IF_QUIESCING;

MQQueuetriggerQueue=Queue(ueName(),

openOptions,

null,null,null);

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

/*Setupouroptionstogetthefirstmessage*/

/*Wait5condstobecetainallmessagesare*/

/*procesd.*/

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

MQGetMessageOptionsgmo=newMQGetMessageOptions();

s=_WAIT|_CONVERT;

terval=5000;

MQMessagetriggerMessage=newMQMessage();

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

/*Readeachmessagefromthequeueuntilthereare*/

/*nomoremessagestoget.*/

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

longrc=0;

do

{

rc=0;

try

{

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

/*SetthemessageIdandcorrelationIdtonone*/

/*togetallmessageswithnomessage*/

/*lection.*/

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

essage();

ationId=_NONE;

eId=_NONE;

(triggerMessage,gmo);

Stringmsg=ring(sageLength());

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

/*Inrtbusinesslogicforthemessagehere.*/

/*Forthissample,echothefirst20*/

/*charactersofthemessage.*/

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

if(()>20)

{

n("Message:"+ing(0,20));

}

el

{

n("Message:"+msg);

}

}

catch(MQExceptionmqEx)

{

rc=Code;

if(rc!=_NO_MSG_AVAILABLE)

{

n("PUTMessagefailedwithrc="

+rc);

}

}

catch(Exceptionex)

{

n("Genericexception:"+ex);

rc=1;

}

}while(rc==0);

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

/*CleanupMQresourcespriortoexiting.*/

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

();

nect();

}

catch(MQExceptionmqEx)

{

n("MQfailedwithcompletioncode="

+tionCode

+"andreasoncode="+Code);

}

}

}

WebSphereMQForJAVA编程实例----请求/回复---样例

源码:

.*;

publicclassRequester{

publicstaticvoidmain(Stringargs[]){

try{

StringhostName="127.0.0.1";

Stringchannel="CHAN1";

StringqManager="QM1";

StringrequestQueue="QL1";

StringreplyToQueue="REPLYQ";

StringreplyToQueueManager="QM1";

//SetuptheMQEnvironmentpropertiesforClientConnections

me=hostName;

l=channel;

(ORT_PROPERTY,

ORT_MQSERIES);

=1381;

//ConnectionTotheQueueManager

MQQueueManagerqMgr=newMQQueueManager(qManager);

intopenOptions=_OUTPUT|_FAIL_IF_QUIESCING;

//Openthequeue

MQQueuequeue=Queue(requestQueue,openOptions,null,

null,null);

//Settheputmessageoptions,wewilluthedefaulttting.

MQPutMessageOptionspmo=newMQPutMessageOptions();

s=s+_NEW_MSG_ID;

s=s+_SYNCPOINT;

MQMessageoutMsg=newMQMessage();

//Createthemessagebuffer

=_STRING;

//SettheMQMDformatfield.

eFlags=_REQUEST;

oQueueName=replyToQueue;

oQueueManagerName=replyToQueueManager;

//Preparemessagewithurdata

StringmsgString="TestRequestMessagefromRequesterprogram";

tring(msgString);

//NowweputThemessageontheQueue

(outMsg,pmo);

//Committhetransaction.

();

.println("ThemessagehasbeenSussfullyputnn

#");

//ClothetheRequestQueue

();

//SetopenOptionforresponqueue

openOptions=_INPUT_SHARED|_FAIL_IF_QUIESCING;

MQQueuerespQueue=Queue(replyToQueue,openOptions,

null,null,null);

MQMessagerespMessage=newMQMessage();

MQGetMessageOptionsgmo=newMQGetMessageOptions();

s=s+_SYNCPOINT;

//Getmessagesundersyncpointcontrol

s=s+_WAIT;

//WaitforResponMessage

ptions=_MATCH_CORREL_ID;

terval=10000;

ationId=eId;

n("TheresponmessagecorrelID:"+ationId);

//Gettheresponmessage.

(respMessage,gmo);

Stringrespon=ring(respMessage

.getMessageLength());

n("Theresponmessageis:"+respon);

();

();

nect();

}catch(MQExceptionex){

n("AnMQErrorOccurred:CompletionCodeis:t"

+tionCode+"nnTheReasonCodeis:t"

+Code);

tackTrace();

}catch(Exceptione){

tackTrace();

}

}

}

源码如下:

.*;

publicclassResponder{

publicstaticvoidmain(Stringargs[]){

try{

StringhostName="127.0.0.1";

Stringchannel="CHAN1";

StringqManager="QM1";

StringqName="QL1";

//SetuptheMQEnvironmentpropertiesforClient

//Connections

me=hostName;

l=channel;

(ORT_PROPERTY,

ORT_MQSERIES);

=1381;

//ConnectionTotheQueueManager

MQQueueManagerqMgr=newMQQueueManager(qManager);

/*

*Setuptheopenoptionstoopenthequeueforoutputand

*additionallywehavettheoptiontofailifthequeuemanager

*isquiescing.

*/

intopenOptions=_INPUT_SHARED

|_FAIL_IF_QUIESCING;

//Openthequeue

MQQueuequeue=Queue(qName,openOptions,null,null,

null);

//Settheputmessageoptions.

MQGetMessageOptionsgmo=newMQGetMessageOptions();

s=s+_SYNCPOINT;

//Getmessagesundersyncpointcontrol

s=s+_WAIT;

//WaitifnomessagesontheQueue

s=s+_FAIL_IF_QUIESCING;

//FailifQeueManagerQuiescing

terval=3000;

//Setsthetimelimitforthewait.

/*

*NextweBuildamessageTheMQMessageclasncapsulatesthedata

*bufferthatcontainstheactualmessagedata,togetherwithall

*theMQMDparametersthatdescribethemessage.

*To

*Buildanewmessage,createanewinstanceofMQMessageclassand

*uwritxxx(wewillbeusingwriteStringmethod).Theput()

*methodofMQQueuealsotakesaninstanceofthe

*MQPutMessageOptionsclassasaparameter.

*/

MQMessageinMsg=newMQMessage();

//CreatethemessagebufferGetthemessagefromthequeueontothemessagebuffer.

(inMsg,gmo);

//ReadtheUrdatafromthemessage.

StringmsgString=ring(sageLength());

n("TheMessagefromtheQueueis:"+msgString);

//Checkifmessageifoftyperequestmessageandreplytothe

//request.

if(eFlags==_REQUEST){

n("PreparingToReplyTotheRequest");

StringreplyQueueName=oQueueName;

n("Thereplyqueue:"+replyQueueName);

openOptions=_OUTPUT|_FAIL_IF_QUIESCING;

MQQueuerespQueue=Queue(replyQueueName,

openOptions,oQueueManagerName,null,null);

MQMessagerespMessage=newMQMessage();

ationId=eId;

n("TheresponCorrelID"+ationId);

MQPutMessageOptionspmo=newMQPutMessageOptions();

=_STRING;

eFlags=_REPLY;

Stringrespon="ReplyfromtheResponderProgram";

tring(respon);

(respMessage,pmo);

n("TheresponSuccessfullynd");

();

();

}

();

nect();

}catch(MQExceptionex){

n("AnMQErrorOccurred:CompletionCodeis:t"

+tionCode+"nnTheReasonCodeis:t"

+Code);

tackTrace();

}catch(Exceptione){

tackTrace();

}

}

}

WebSphereMQ编程实例--------JMS

源码:

ble;

.*;

.*;

ory.*;

publicclasssample{

protectedQueueConnectionFactoryfactory=null;

protectedQueueConnectionconnection;

protectedQueueSessionqueueSession;

protectedTextMessageoutMessage;

protectedQueueSenderqueueSender;

protectedQueueReceiverqueueReceiver;

publicstaticfinalStringqcfLookup="QCFC";

publicstaticfinalStringqLookup="Q1";

publicstaticfinalStringicf="ontextFactory";

publicStringurl="file:/d:/testmq/ctx/";

publicvoidsampleInit()throwsException{

Hashtableenvironment=newHashtable();

(L_CONTEXT_FACTORY,icf);

(ER_URL,url);

(AL,"throw");

Contextctx=newInitialDirContext(environment);

factory=(QueueConnectionFactory)(qcfLookup);

Queueq1=null;

q1=(Queue)(qLookup);

connection=QueueConnection();

queueSession=QueueSession(fal,

_ACKNOWLEDGE);

queueSender=Sender(q1);

iveryMode(_PERSISTENT);

outMessage=TextMessage();

queueReceiver=Receiver(q1);

();

}

publicvoidndMessageOut(Stringmessage)throwsJMSException{

t(message);

(outMessage);

}

publicStringreceiveMessage()throwsException{

return((TextMessage)e()).getText();

}

publicvoidsampleClo()throwsJMSException{

();

();

}

publicstaticvoidmain(String[]args){

Stringrec;

samplesp=newsample();

try{

Init();

ssageOut("Thisisatest!");

(4000);

rec=eMessage();

n("Receivetextis:"+rec);

Clo();

}catch(Exceptione){

tackTrace();

}

}

}

本文发布于:2023-01-03 11:31:52,感谢您对本站的认可!

本文链接:http://www.wtabcd.cn/fanwen/fan/90/84174.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:no message
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图