日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[性能测试]:关于MQ协议脚本开发

發布時間:2023/12/20 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [性能测试]:关于MQ协议脚本开发 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

消息隊列(MQ)是一種應用程序對應用程序的通信方法。應用程序通過寫和檢索出入列隊的針對應用程序的數據(消息)來通信,而無需專用連接來鏈接它們。

銀行腳本使用MQ通信的較多,下面介紹一個MQ的腳本:

MQ的腳本分為SEND和RECIVE兩部分

send部分:

import com.ibm.mq.*; import lrapi.lr;public class Actions {String PutQueueManagerName = "QMCPG1"; // 發送隊列管理器String PutQueueName = "HVPSBANK"; // 發送隊列名,相當于前置機的接收隊列String QueueChannel = "xn_rcv"; // 通道名,要用服務器通道int PutPort = 1428; // 發送端口號,相當于前置機的接收端口int CCSID = 1381; // 客戶端Unix用819,windows用1381int OpenOptions = MQC.MQOO_INPUT_AS_Q_DEF|MQC.MQOO_OUTPUT|MQC.MQOO_INQUIRE; // 連接參數int PutDepth = 0; // 發送隊列深度String SndTime = ""; // 當前發送時間 MQQueueManager PutQueueManager = null; // 創建發送隊列管理器對象MQQueue PutQueue = null; // 創建發送隊列對象MQMessage PutMessage = new MQMessage(); // 創建發送消息對象MQPutMessageOptions PMO = new MQPutMessageOptions(); // 創建發送消息選項隊列public int init() throws Throwable{// 發送隊列的參數**********************************************MQEnvironment.hostname = lr.eval_string("<HostIP>"); // 設置環境參數MQEnvironment.port = PutPort;MQEnvironment.CCSID = CCSID; MQEnvironment.channel = QueueChannel;PutQueueManager = new MQQueueManager(PutQueueManagerName); // 連接發送隊列管理器PutQueue = PutQueueManager.accessQueue(PutQueueName, OpenOptions, null, null, null); // 建立訪問發送隊列PutMessage.format = MQC.MQFMT_STRING; // 設置消息中應用數據的格式PutMessage.characterSet = 1381; // 設置字符集PutMessage.expiry = -1; // 設置消息為不過期return 0;}//end of initpublic int action() throws Throwable{SndTime = String.valueOf(System.currentTimeMillis()); // 獲取當前發送時間,13位lr.start_transaction("02_CP2I111_大額來帳_發送");PutQueueMessage("{H:" +"02" +"309391000011 " +"HVPS" +"306581000003 " +"HVPS" +"<Date>" + // 報文發起日期"<Time>" + // 報文發起時間"XML" +"hvps.111.001.01 " +SndTime + "<Num>" + // 通信級標識號,CNAPS2SIMU0000088212,20位,接收方根據OrigSender+OrigSendDate+MesgID唯一確定一個報文,該三項重復的報文作為通信級重復報文;SndTime + "<Num>" + // 通信級參考號,CNAPS2SIMU0000030415,20位,標識本報文的關聯報文,由OrigSender設置,后續節點應保持該域不變,并在通信回應報文中帶回該值,以便OrigSender匹配原報文;"3" +"D" +" " +"}\r\n" +"{S:" + // 數字簽名域起始標識"2016110700130322|2016-11-07T14:25:01|1|2016110700130322|A100|CNY10.05|NORM|309391000011|309391000011|306581000003|306588000016|321|123|309391000011|306588000016|xingneng|6214620421000208396|02102|" + // 數字簽名內容"}\r\n" + // 數字簽名域結束標識"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02\">" + "<FIToFICstmrCdtTrf>" + "<GrpHdr>" + "<MsgId>" + "<Date>" + "<Time>" + "<MsgNum>" + "</MsgId>" + // 報文標識號,最大35位,最好是8位日期+8位流水,否則二代后臺會處理異常,2016111015130018"<CreDtTm>2016-11-07T14:25:01</CreDtTm>" + "<NbOfTxs>1</NbOfTxs>" + "<SttlmInf>" + "<SttlmMtd>CLRG</SttlmMtd>" + "</SttlmInf>" + "</GrpHdr>" + "<CdtTrfTxInf>" + "<PmtId>" + "<EndToEndId>1</EndToEndId>" + "<TxId>" + SndTime + "<Num>" + "</TxId>" + // 交易標識號,最大35位,2016110700130322"</PmtId>" + "<PmtTpInf>" + "<CtgyPurp>" + "<Prtry>A100</Prtry>" + "</CtgyPurp>" +"</PmtTpInf>" +"<IntrBkSttlmAmt Ccy=\"CNY\">0.02</IntrBkSttlmAmt>" + // 金額"<SttlmPrty>NORM</SttlmPrty>" +"<ChrgBr>DEBT</ChrgBr>" +"<InstgAgt>" +"<FinInstnId>" +"<ClrSysMmbId>" +"<MmbId>309391000011</MmbId>" + // 付款清算行行號"</ClrSysMmbId>" +"</FinInstnId>" +"<BrnchId>" +"<Id>309391000011</Id>" + // 收款行行號"</BrnchId>" +"</InstgAgt>" +"<InstdAgt>" +"<FinInstnId>" +"<ClrSysMmbId>" +"<MmbId>306581000003</MmbId>" + // 收款清算行行號"</ClrSysMmbId>" +"</FinInstnId>" +"<BrnchId>" +"<Id>306588000016</Id>" + // 收款行行號"</BrnchId>" +"</InstdAgt>" +"<Dbtr>" +"<Nm>沈監</Nm>" + // 付款人名稱"</Dbtr>" +"<DbtrAcct>" +"<Id>" +"<Othr>" +"<Id>6225684352000160189</Id>" + // 付款人賬號"</Othr>" +"</Id>" +"</DbtrAcct>" +"<DbtrAgt>" +"<FinInstnId>" +"<ClrSysMmbId>" +"<MmbId>309391000011</MmbId>" + // 付款人開戶行行號"</ClrSysMmbId>" +"</FinInstnId>" +"</DbtrAgt>" +"<CdtrAgt>" +"<FinInstnId>" +"<ClrSysMmbId>" +"<MmbId>306588000016</MmbId>" + // 收款人開戶行行號"</ClrSysMmbId>" +"</FinInstnId>" +"</CdtrAgt>" +"<Cdtr>" +"<Nm>燕凈</Nm>" + // 收款人名稱"</Cdtr>" +"<CdtrAcct>" +"<Id>" +"<Othr>" +"<Id>6225684341000008415</Id>" + // 收款人賬號"</Othr>" +"</Id>" +"</CdtrAcct>" +"<Purp>" +"<Prtry>02102</Prtry>" + // 業務種類編碼"</Purp>" +"<RmtInf>" +"<Ustrd>/C00/2016-11-07</Ustrd>" + // 備注"</RmtInf>" +"</CdtTrfTxInf>" +"</FIToFICstmrCdtTrf>" +"</Document>");lr.end_transaction("02_CP2I111_大額來帳_發送",lr.PASS);return 0;}//end of actionpublic int end() throws Throwable{try{PutQueue.close();PutQueueManager.close();PutQueueManager.disconnect();}catch (MQException ex){lr.error_message("02_CP2I111_大額來帳_發送退出關閉隊列時出現錯誤,完成代碼為:" + ex.completionCode + ",原因為:" + ex.reasonCode);ex.printStackTrace();}catch(Exception e){e.printStackTrace();}return 0;}// end of end// 發送消息++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++public void PutQueueMessage(String MyStr){try{PutMessage = new MQMessage();PutMessage.write(MyStr.getBytes("UTF-8")); // 呵呵PutQueue.put(PutMessage, PMO);// 將消息放入隊列PutQueueManager.commit(); // 提交事務處理//PutDepth = PutQueue.getCurrentDepth(); // 獲取發送隊列的深度//System.out.println("++++++發送隊列當前深度為:"+ PutDepth);//System.out.println("=======發送報文是:" + MyStr); PutMessage.clearMessage();PutMessage = null;}catch (MQException ex){lr.end_transaction("02_CP2I111_大額來帳_發送",lr.FAIL);lr.error_message("02_CP2I111_大額來帳_發送_發送消息時出錯,完成代碼為:" + ex.completionCode + ",原因為:" + ex.reasonCode + "流水號為:" + SndTime);lr.exit(lr.EXIT_ITERATION_AND_CONTINUE, lr.FAIL);//System.out.println("發送消息時出現錯誤,完成代碼為:" + ex.completionCode + ",原因為:" + ex.reasonCode);//ex.printStackTrace(); }catch(Exception e){e.printStackTrace();} } }

RECIVE部分:

/** LoadRunner Java script. (Build: _build_number_)* * Script Description: * */ import java.util.Date; import com.ibm.mq.*; import lrapi.lr;public class Actions {String GetQueueManagerName = "QMCPG1"; // 接收隊列管理器String GetQueueName = "306581000003.MBFEA.PBCTOBANK"; // 接收隊列名,相當于前置機的發送隊列String QueueChannel = "xn_rsp"; // 通道名,要用服務器通道//String HostName = lr.eval_string("<HostIP>"); // ip 地址int GetPort = 1428; // 接收端口號,相當于前置機的發送端口int CCSID = 1381; // 客戶端Unix用819,windows用1381int OpenOptions = MQC.MQOO_INPUT_AS_Q_DEF|MQC.MQOO_OUTPUT|MQC.MQOO_INQUIRE; // 連接參數int GetDepth = 0; // 接收隊列深度 MQQueueManager GetQueueManager = null; // 創建接收隊列管理器對象MQQueue GetQueue = null; // 創建接收隊列對象MQMessage GetMessage = new MQMessage(); // 創建接收消息對象MQGetMessageOptions GMO = new MQGetMessageOptions(); // 創建接收消息選項對象public int init() throws Throwable{// 接收隊列的參數***********************************************MQEnvironment.hostname = lr.eval_string("<HostIP>"); // 設置環境參數MQEnvironment.port = GetPort;MQEnvironment.CCSID = CCSID;MQEnvironment.channel = QueueChannel;GetQueueManager = new MQQueueManager(GetQueueManagerName); // 連接接收隊列管理器GetQueue = GetQueueManager.accessQueue(GetQueueName, OpenOptions, null , null, null); // 建立訪問接收隊列GetMessage.format = MQC.MQFMT_STRING; // 設置消息體參數GetMessage.characterSet = 1381;GetMessage.expiry = -1;GMO.waitInterval = 20000; // 等待時間限制GMO.options = MQC.MQGMO_NO_WAIT; // 如果隊列沒有消息則立即返回return 0;}//end of initpublic int action() throws Throwable{String Msg = null;String NowTime = null;try{GetMessage = new MQMessage(); // 必須新建實例,否則無法多次迭代無法繼續接收消息GetDepth = GetQueue.getCurrentDepth(); // 獲取接收隊列的深度 if(GetDepth > 0) //接收隊列深度不為0則打印消息 {GetQueue.get(GetMessage, GMO);GetQueueManager.commit();//System.out.println("======接收隊列當前深度為:"+ GetDepth);NowTime = String.valueOf(System.currentTimeMillis()); // 記錄當前時間戳作為接收時間,13位Msg = GetMessage.readString(GetMessage.getMessageLength());CompResult(Msg,NowTime); // 記錄接收時間、流水、交易碼(所接收的交易返回信息不一定為當前程序發出的交易)//System.out.println("======接收消息的內容為:\n" + Msg); GetMessage.clearMessage();GetMessage = null;}else{System.out.println("++++++接收隊列無消息++++++");}}catch(MQException ex){if(ex.reasonCode == 2033){// 2033是沒有消息,不做處理 }else{ lr.error_message("02_CP2I111_大額來帳_接收接收消息時出錯,完成代碼為:" + ex.completionCode + ",原因為:" + ex.reasonCode + ",流水號為:" + NowTime);ex.printStackTrace();}}catch(Exception e){e.printStackTrace();}return 0;}//end of actionpublic int end() throws Throwable{try{GetQueue.close(); // 關閉隊列GetQueueManager.close(); // 關閉隊列管理器GetQueueManager.disconnect(); // 斷開連接 }catch (MQException ex){lr.error_message("02_CP2I111_大額來帳_接收關閉隊列時出現錯誤,完成代碼為:" + ex.completionCode + ",原因為:" + ex.reasonCode);ex.printStackTrace();}return 0;}// end of end// 統計交易結果public void CompResult(String MSG, String RecTime){boolean Result = true; // 交易是否成功String StartTime = null;double DurTime = 0; // 交易處理時間int FlowIndex = -1; // 位置String FlowNo = null;int ErrIndex = -1; // 錯誤碼位置String ErrCode = null;FlowIndex = MSG.indexOf("<MsgId>"); // 流水號的位置StartTime = MSG.substring(FlowIndex+7, FlowIndex+7+13); // 從流水號獲取開始時間DurTime = (Double.parseDouble(RecTime) - Double.parseDouble(StartTime))/1000; // 單位秒//lr.error_message("======處理時間是:" + DurTime + "發送時間是:" + StartTime + "接收時間是:" + RecTime + "返回報文是:" + MSG);ErrIndex = MSG.indexOf("<MsgPrcCd>"); // 錯誤碼的位置ErrCode = MSG.substring(ErrIndex+10, ErrIndex+10+8); // 錯誤碼if(!ErrCode.equals("CU0I0000")) // 成功狀態碼是CU0I0000,交易失敗則獲取流水號 {Result = false;FlowNo = MSG.substring(FlowIndex+7, FlowIndex+7+13); // 流水號lr.error_message("02_CP2I111_大額來帳_接收交易失敗!出錯流水號是:" + FlowNo + ",錯誤碼是:" + ErrCode + ",完整出錯信息是:" + MSG);}// 統計事務響應時間和成功率if(Result){lr.set_transaction("02_CP2I111_大額來帳_接收", DurTime, lr.PASS);//lr.error_message("======02_CP2I111_DELZ交易事務處理時間是:" + DurTime); }else{lr.set_transaction("02_CP2I111_大額來帳_接收", DurTime, lr.FAIL);}} }// 正確返回報文: //{H:02306581000003 HVPS309391000011 HVPS20161110164516XMLccms.990.001.02 20161110HVPS00062057012016111016501100013U } //<?xml version="1.0" encoding="UTF-8"?> //<Document xmlns="urn:cnaps:std:ccms:2010:tech:xsd:ccms.990.001.02"><ComConf><ConfInf><OrigSndr>309391000011</OrigSndr><OrigSndDt>20161110</OrigSndDt><MT>hvps.111.001.01</MT><MsgId>01201611101650110001</MsgId><MsgRefId>01201611101650110001</MsgRefId><MsgPrcCd>CU0I0000</MsgPrcCd></ConfInf></ComConf></Document>

?

轉載于:https://www.cnblogs.com/fy--/p/8966233.html

總結

以上是生活随笔為你收集整理的[性能测试]:关于MQ协议脚本开发的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。