/// <summary> /// tb_aURLresult 테이블 결과 업데이트 /// </summary> /// <param name="Result">전달받은 결과값</param> private void UpdateResult(libMyUtil.pageCallingInfo callingInfo, string Result) { libCommon.clsDB objDB = new libCommon.clsDB(); System.Data.SqlClient.SqlConnection dbCon; System.Data.SqlClient.SqlTransaction TRX; string updateResult; if (System.Text.Encoding.Default.GetByteCount(Result) > 1000) { Result = Result.Substring(0, 500); } try { dbCon = objDB.GetConnection(); TRX = dbCon.BeginTransaction(); updateResult = libMyUtil.clsCmnDB.UPDATE_DB(dbCon, TRX, "tb_aURLresult", "RESULT", Result, "aURLidx|FKEY", callingInfo.aURLset_Idx + "|" + callingInfo.FKEY); if (updateResult.Equals("FAIL")) { TRX.Rollback(); objUtil.writeLog(string.Format("FAIL UPDATE URL RESULT\r\nFKEY:{0}\r\nResult:{1}", callingInfo.FKEY, Result)); } else { TRX.Commit(); } dbCon.Close(); } catch (Exception ex) { objUtil.writeLog("ERR UPDATE URL CALL RESULT : " + ex.ToString()); } }
/// <summary> /// 재시도 함수 /// </summary> private void tryAgain() { libMyUtil.clsMSMQ objMSMQ = new libMyUtil.clsMSMQ(); System.Diagnostics.Stopwatch objWatch = new System.Diagnostics.Stopwatch(); int retryMsgCnt; int i; while (objMSMQ.canReadQueue(qPath_retry)) { retryMsgCnt = objMSMQ.queueMsgCnt(this.qPath_retry); for (i = 0; i < retryMsgCnt; i++) { libMyUtil.pageCallingInfo rcvObj = (libMyUtil.pageCallingInfo)objMSMQ.peekData(this.qPath_retry, this.objType, this.rcvTimeOut); if ((System.DateTime.Now - rcvObj.lastTry).Duration().TotalMilliseconds < this.retryInterval) { break; } prcRcvObject(objMSMQ.receiveData(this.qPath_retry, this.objType, this.rcvTimeOut)); } System.Threading.Thread.Sleep(this.retryInterval); } libMyUtil.clsThread.SetLabel(RetryCallerState, "오류"); MessageBox.Show(string.Format("해당큐({0})에 접근할 수 없습니다.", qPath_retry)); }
/// <summary> /// 수신된 메시지 처리, null수신시 sleep /// </summary> private void prcRcvObject(object rcvObj) { if (rcvObj != null) { System.Diagnostics.Stopwatch objWatch = new System.Diagnostics.Stopwatch(); objWatch.Start(); libMyUtil.clsMSMQ objMSMQ = new libMyUtil.clsMSMQ(); libMyUtil.pageCallingInfo callingInfo = (libMyUtil.pageCallingInfo)rcvObj; string Result; string url = callingInfo.url; string postData = callingInfo.postData; int timeOut = callingInfo.timeOut; if (callingInfo.httpMethod.Equals("POST")) { Result = libMyUtil.clsWeb.SendPostData(postData, url, this.encodeType, timeOut * 1000); } else if (callingInfo.httpMethod.Equals("GET")) { Result = libMyUtil.clsWeb.SendQueryString(postData, url, timeOut * 1000); } else { Result = "UNKNOWN HTTP METHOD"; } objUtil.writeLog(string.Format("CALL RESULT : {0}\r\nFKEY:{1}\r\nURL:{2}", Result, callingInfo.FKEY, callingInfo.url)); if (Result.Equals(callingInfo.callresult)) { UpdateResult(callingInfo, Result);//성공 결과 DB에 저장 } else if (Result.Equals("FAIL")) { //재시도 callingInfo.failCnt++; //실패 카운트 증가 callingInfo.lastTry = System.DateTime.Now; //시간 기록 if (callingInfo.failCnt < this.MaxCallingFailCnt) //설정한 횟수만큼 재시도 { objMSMQ.sendData(qPath_retry, callingInfo); //재시도 큐에 저장 } else { callingInfo.writeLog(Result); //최종 실패 메시지 로그 기록 UpdateResult(callingInfo, Result); //실패 결과 DB에 저장 } } else { callingInfo.writeLog(Result); //최종 실패 메시지 로그 기록 UpdateResult(callingInfo, Result); //실패 결과 DB에 저장 } objWatch.Stop(); if (System.DateTime.Now.Millisecond > 500) { objUtil.writeLog(string.Format("TIME SPAN : {0} millisecond", objWatch.Elapsed.TotalMilliseconds.ToString())); } } else { System.Threading.Thread.Sleep(this.sleep);//큐에 메시지 없으면 슬립 } }