diff --git a/.github/workflows/issue-translator.yml b/.github/workflows/issue-translator.yml new file mode 100644 index 0000000..d9fdac8 --- /dev/null +++ b/.github/workflows/issue-translator.yml @@ -0,0 +1,15 @@ +name: Issue Translator +on: + issue_comment: + types: [created] + issues: + types: [opened] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: usthe/issues-translate-action@v2.7 + with: + IS_MODIFY_TITLE: false + CUSTOM_BOT_NOTE: Bot detected the issue body's language is not English, translate it automatically. \ No newline at end of file diff --git a/.github/workflows/linuxbuild.yml b/.github/workflows/linuxbuild.yml index 932e144..2d9766d 100644 --- a/.github/workflows/linuxbuild.yml +++ b/.github/workflows/linuxbuild.yml @@ -3,8 +3,9 @@ name: ubuntu build workflows on: push: branches: [ "develop" ] - pull_request: - branches: [ "develop" ] + paths: + - 'XEngine_Source/**' + - 'XEngine_Release/**' permissions: contents: read @@ -17,7 +18,7 @@ jobs: matrix: include: - os: ubuntu-22.04 - - os: ubuntu-24.04 + #- os: ubuntu-24.04 runs-on: ${{ matrix.os }} steps: @@ -61,4 +62,10 @@ jobs: - name: test run: | cd XEngine_Release - ./XEngine_MQServiceApp -t \ No newline at end of file + ./XEngine_MQServiceApp -t + + - name: Upload folder as artifact with ubuntu + uses: actions/upload-artifact@v4 + with: + name: XEngine_MQServiceApp-x86_64-Ubuntu + path: XEngine_Release/ \ No newline at end of file diff --git a/.github/workflows/macbuild.yml b/.github/workflows/macbuild.yml index 37a16b1..f1008f2 100644 --- a/.github/workflows/macbuild.yml +++ b/.github/workflows/macbuild.yml @@ -3,8 +3,9 @@ name: macos build workflows on: push: branches: [ "develop" ] - pull_request: - branches: [ "develop" ] + paths: + - 'XEngine_Source/**' + - 'XEngine_Release/**' permissions: contents: read @@ -62,3 +63,9 @@ jobs: run: | cd XEngine_Release ./XEngine_MQServiceApp -t + + - name: Upload folder as artifact with mac + uses: actions/upload-artifact@v4 + with: + name: XEngine_MQServiceApp-x86_64-Mac + path: XEngine_Release/ \ No newline at end of file diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index 6cb9efa..dea86cb 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -3,8 +3,9 @@ name: windows build workflows on: push: branches: [ "develop" ] - pull_request: - branches: [ "develop" ] + paths: + - 'XEngine_Source/**' + - 'XEngine_Release/**' permissions: contents: read @@ -60,18 +61,31 @@ jobs: run: | cp -r XEngine_Source/Release/*.dll XEngine_Release/ cp -r XEngine_Source/Release/*.exe XEngine_Release/ - cp -r XEngine_Source/VSCopy-x86.bat XEngine_Release/ + cp -r XEngine_Source/VSCopy_x86.bat XEngine_Release/ cd XEngine_Release - ./VSCopy-x86.bat + ./VSCopy_x86.bat ./XEngine_MQServiceApp.exe -t shell: pwsh - name: Conditional Step for x86 Debug - if: matrix.configuration == 'Debug' && matrix.platform == 'x86' + if: matrix.configuration == 'Release' && matrix.platform == 'x64' run: | - cp -r XEngine_Source/Debug/*.dll XEngine_Release/ - cp -r XEngine_Source/Debug/*.exe XEngine_Release/ - cp -r XEngine_Source/VSCopy-x86.bat XEngine_Release/ + cp -r XEngine_Source/x64/Release/*.dll XEngine_Release/ + cp -r XEngine_Source/x64/Release/*.exe XEngine_Release/ + cp -r XEngine_Source/VSCopy_x64.bat XEngine_Release/ cd XEngine_Release - ./VSCopy-x86.bat - ./XEngine_MQServiceApp.exe -t + ./VSCopy_x64.bat shell: pwsh + + - name: Upload folder as artifact with x86 + if: matrix.configuration == 'Release' && matrix.platform == 'x86' + uses: actions/upload-artifact@v4 + with: + name: XEngine_MQServiceApp-x86_32-Windows + path: XEngine_Release/ + + - name: Upload folder as artifact with x64 + if: matrix.configuration == 'Release' && matrix.platform == 'x64' + uses: actions/upload-artifact@v4 + with: + name: XEngine_MQServiceApp-x86_64-Windows + path: XEngine_Release/ \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a52b626 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,89 @@ +name: release packet + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + # 检出代码并包含标签 + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Download linuxbuild + uses: dawidd6/action-download-artifact@v6 + with: + workflow: linuxbuild.yml + workflow_conclusion: success + check_artifacts: false + skip_unpack: true + if_no_artifact_found: fail + path: ./XRelease/ + - name: Download macbuild + uses: dawidd6/action-download-artifact@v6 + with: + workflow: macbuild.yml + workflow_conclusion: success + check_artifacts: false + skip_unpack: true + if_no_artifact_found: fail + path: ./XRelease/ + - name: Download msbuild + uses: dawidd6/action-download-artifact@v6 + with: + workflow: msbuild.yml + workflow_conclusion: success + check_artifacts: false + skip_unpack: true + if_no_artifact_found: fail + path: ./XRelease/ + + - name: Display structure of downloaded files + run: ls -al ./XRelease/ + + - name: Get current version and increment X + id: versioning + run: | + latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) + echo "Latest tag: $latest_tag" + # 提取 X 的值并递增 + major=$(echo $latest_tag | cut -d '.' -f 1) + minor=$(echo $latest_tag | cut -d '.' -f 2) + patch=$(echo $latest_tag | cut -d '.' -f 3) + build=$(echo $latest_tag | cut -d '.' -f 4) + + new_minor=$((minor + 1)) + new_version="$major.$new_minor.$patch.$build" + echo "New version: $new_version" + echo "new_tag=$new_version" >> $GITHUB_OUTPUT + echo "prev_tag=$latest_tag" >> $GITHUB_OUTPUT + + - name: Create and push new tag + run: | + git tag ${{ steps.versioning.outputs.new_tag }} + git push origin ${{ steps.versioning.outputs.new_tag }} + + - name: Generate release notes + run: | + logs=$(git log ${{ steps.versioning.outputs.prev_tag }}..${{ steps.versioning.outputs.new_tag }} --pretty=format:"* %h - %s - %an" --no-merges) + release_notes=$(echo "$logs" | sed 's/ qyt$/ @xengine-qyt/') + echo "$release_notes" + echo "$release_notes" > release_notes.txt + + - name: Release + uses: softprops/action-gh-release@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + draft: false + prerelease: false + tag_name: ${{ steps.versioning.outputs.new_tag }} + name: XEngine_MQService ${{ steps.versioning.outputs.new_tag }} + body_path: release_notes.txt + files: ./XRelease/*.zip diff --git a/CHANGELOG b/CHANGELOG index 81606a6..abf0fa7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,23 @@ +XEngine_MQService V3.13.0.1001 + +增加:为DATA消息数据库增加高速缓存支持 +增加:coredump的windows支持 +更新:工作流自动发布支持 +更新:依赖库 +优化:启动参数解析 +修正:某些时候退出崩溃问题 +修正:发布消息时候获取在线用户不正确的问题 +修正:通知用户处理问题 + +added:memory cache module for Data DB +added:coredump file support on windows +update:release workflows supported +update:depend library +improved:start parameter parse +fixed:sometime crashed when exist +fixed:get online user is incorrect when publish message +fixed:immediate notify user process is incorrect +====================================================================================== XEngine_MQService V3.12.0.1001 增加:编译CI工作流支持 diff --git a/README.en.md b/README.en.md index 53a0c16..7ff4846 100644 --- a/README.en.md +++ b/README.en.md @@ -33,6 +33,8 @@ this software support following features 17. binary message 18. http interface management 19. message attritube +20. point to point message +21. Memory Database ## install @@ -113,6 +115,7 @@ Address:app.xyry.org Port:TCP 5200,WEBSOCKET 5201,HTTP Management Interface 5202 2. Create new Feat_xxx branch 3. Submit the code 4. New Pull Request +5. Submit develop branch ## Follow us If you think this software is helpful to you, please give us a START diff --git a/README.md b/README.md index 07d9c04..adc954b 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ c c++Message Service 17. 二进制消息 18. http接口管理 19. 消息属性 +20. 点对点消息 +21. 高速缓存 ## 安装教程 @@ -119,6 +121,7 @@ make FLAGS=CleanAll 清理编译 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request +5. 提交到develop分支 ## 关注我们 如果你觉得这个软件对你有帮助,请你给我们一个START吧 diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index d35b3c0..e271651 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -25,7 +25,7 @@ "SQLAddr":"10.0.3.154", "SQLPort":3306, "SQLUser":"root", - "SQLPass":"123123" + "SQLPass":"123123aa" }, "XPass":{ "nTimeout":2, @@ -34,6 +34,12 @@ "tszPassLogin":"", "tszPassLogout":"" }, + "XMemory":{ + "bDataQueryEnable":true, + "bDataInsertEnable":true, + "nTimeLast":3600, + "nTimeStart":0 + }, "XReport":{ "bEnable":true, "tszServiceName":"XEngine_MQService", diff --git a/XEngine_Release/XEngine_Config/XEngine_VerConfig.json b/XEngine_Release/XEngine_Config/XEngine_VerConfig.json index 38a5d78..09e04b5 100644 --- a/XEngine_Release/XEngine_Config/XEngine_VerConfig.json +++ b/XEngine_Release/XEngine_Config/XEngine_VerConfig.json @@ -1,5 +1,6 @@ { "XVer":[ + "3.13.0.1001 Build20241129", "3.12.0.1001 Build20240919", "3.11.0.1001 Build20240517", "3.10.0.1001 Build20240305", diff --git a/XEngine_Release/XEngine_Log/.gitignore b/XEngine_Release/XEngine_Coredump/keepfile similarity index 100% rename from XEngine_Release/XEngine_Log/.gitignore rename to XEngine_Release/XEngine_Coredump/keepfile diff --git a/XEngine_Release/XEngine_Log/keepfile b/XEngine_Release/XEngine_Log/keepfile new file mode 100644 index 0000000..e69de29 diff --git a/XEngine_Source/MQCore_ConfigModule/Config_Define.h b/XEngine_Source/MQCore_ConfigModule/Config_Define.h index bb2b912..9636b4c 100644 --- a/XEngine_Source/MQCore_ConfigModule/Config_Define.h +++ b/XEngine_Source/MQCore_ConfigModule/Config_Define.h @@ -55,6 +55,13 @@ typedef struct XCHAR tszPassLogout[MAX_PATH]; int nTimeout; }st_XPass; + struct + { + bool bDataQueryEnable; + bool bDataInsertEnable; + int nTimeLast; + int nTimeStart; + }st_XMemory; struct { bool bEnable; diff --git a/XEngine_Source/MQCore_ConfigModule/Config_Error.h b/XEngine_Source/MQCore_ConfigModule/Config_Error.h index e4c57df..c0aa55d 100644 --- a/XEngine_Source/MQCore_ConfigModule/Config_Error.h +++ b/XEngine_Source/MQCore_ConfigModule/Config_Error.h @@ -21,4 +21,5 @@ #define ERROR_MQ_MODULE_CONFIG_JSON_XSQL 0x0020006 #define ERROR_MQ_MODULE_CONFIG_JSON_XPASS 0x0020007 #define ERROR_MQ_MODULE_CONFIG_JSON_XVER 0x0020008 -#define ERROR_MQ_MODULE_CONFIG_JSON_XREPORT 0x0020009 \ No newline at end of file +#define ERROR_MQ_MODULE_CONFIG_JSON_XREPORT 0x0020009 +#define ERROR_MQ_MODULE_CONFIG_JSON_XMEMORY 0x0020010 \ No newline at end of file diff --git a/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp b/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp index 56d3146..7cf026c 100644 --- a/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp +++ b/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp @@ -123,6 +123,18 @@ bool CConfig_Json::Config_Json_File(LPCXSTR lpszConfigFile,XENGINE_SERVERCONFIG _tcsxcpy(pSt_ServerConfig->st_XPass.tszPassRegister, st_JsonXPass["tszPassRegister"].asCString()); _tcsxcpy(pSt_ServerConfig->st_XPass.tszPassUNReg, st_JsonXPass["tszPassUNReg"].asCString()); + if (st_JsonRoot["XMemory"].empty() || (4 != st_JsonRoot["XMemory"].size())) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_MQ_MODULE_CONFIG_JSON_XMEMORY; + return false; + } + Json::Value st_JsonXMemory = st_JsonRoot["XMemory"]; + pSt_ServerConfig->st_XMemory.bDataQueryEnable = st_JsonXMemory["bDataQueryEnable"].asBool(); + pSt_ServerConfig->st_XMemory.bDataInsertEnable = st_JsonXMemory["bDataInsertEnable"].asBool(); + pSt_ServerConfig->st_XMemory.nTimeLast = st_JsonXMemory["nTimeLast"].asInt(); + pSt_ServerConfig->st_XMemory.nTimeStart = st_JsonXMemory["nTimeStart"].asInt(); + if (st_JsonRoot["XReport"].empty() || (3 != st_JsonRoot["XReport"].size())) { Config_IsErrorOccur = true; diff --git a/XEngine_Source/MQCore_DBModule/DBModule_Define.h b/XEngine_Source/MQCore_DBModule/DBModule_Define.h index 45316f1..7e1377e 100644 --- a/XEngine_Source/MQCore_DBModule/DBModule_Define.h +++ b/XEngine_Source/MQCore_DBModule/DBModule_Define.h @@ -71,12 +71,22 @@ extern "C" XLONG DBModule_GetLastError(int *pInt_SysError = NULL); 类型:数据结构指针 可空:N 意思:数据MYSQL数据库连接信息 + 参数.二:bMemoryQuery + In/Out:In + 类型:逻辑型 + 可空:Y + 意思:是否启用查询缓存支持 + 参数.三:bMemoryInsert + In/Out:In + 类型:逻辑型 + 可空:Y + 意思:是否启用插入缓存支持 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector); +extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryQuery = true, bool bMemoryInsert = true); /******************************************************************** 函数名称:DBModule_MQData_Destory 函数功能:销毁数据库管理器 diff --git a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp index f621880..a4d373e 100644 --- a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp +++ b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp @@ -30,12 +30,22 @@ CDBModule_MQData::~CDBModule_MQData() 类型:数据结构指针 可空:N 意思:数据MYSQL数据库连接信息 + 参数.二:bMemoryQuery + In/Out:In + 类型:逻辑型 + 可空:Y + 意思:是否启用查询缓存支持 + 参数.三:bMemoryInsert + In/Out:In + 类型:逻辑型 + 可空:Y + 意思:是否启用插入缓存支持 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -bool CDBModule_MQData::DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector) +bool CDBModule_MQData::DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryQuery /* = true */, bool bMemoryInsert /* = true */) { DBModule_IsErrorOccur = false; @@ -45,6 +55,8 @@ bool CDBModule_MQData::DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBCo DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_PARAMENT; return false; } + m_bMemoryQuery = bMemoryQuery; + m_bMemoryInsert = bMemoryInsert; //连接数据库 _tcsxcpy(pSt_DBConnector->tszDBName, _X("XEngine_MQData")); if (!DataBase_MySQL_Connect(&xhDBSQL, pSt_DBConnector)) @@ -53,6 +65,10 @@ bool CDBModule_MQData::DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBCo DBModule_dwErrorCode = DataBase_GetLastError(); return false; } + if (m_bMemoryInsert) + { + MemoryCache_DBData_SetHandle(xhDBSQL); + } return true; } /******************************************************************** @@ -109,12 +125,23 @@ bool CDBModule_MQData::DBModule_MQData_Insert(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo memcpy(tszSQLStatement + nRet, tszSQLCoder, nLen); nRet += nLen; - if (!DataBase_MySQL_Execute(xhDBSQL, tszSQLStatement, &nRet)) - { - DBModule_IsErrorOccur = true; - DBModule_dwErrorCode = DataBase_GetLastError(); - return false; - } + if (m_bMemoryInsert) + { + MemoryCache_DBData_QueueInsert(tszSQLStatement, pSt_DBInfo); + } + else + { + if (!DataBase_MySQL_Execute(xhDBSQL, tszSQLStatement, &nRet)) + { + DBModule_IsErrorOccur = true; + DBModule_dwErrorCode = DataBase_GetLastError(); + return false; + } + } + if (m_bMemoryQuery) + { + MemoryCache_DBData_DataInsert(pSt_DBInfo); + } return true; } /******************************************************************** @@ -140,6 +167,14 @@ bool CDBModule_MQData::DBModule_MQData_Query(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo) DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_PARAMENT; return false; } + + if (m_bMemoryQuery) + { + if (MemoryCache_DBData_DataQuery(pSt_DBInfo)) + { + return true; + } + } //查询 XNETHANDLE xhTable = 0; __int64u nllLine = 0; @@ -216,6 +251,11 @@ bool CDBModule_MQData::DBModule_MQData_Query(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo) _tcsxcpy(pSt_DBInfo->tszQueueCreateTime, pptszResult[nPos]); } DataBase_MySQL_FreeResult(xhDBSQL, xhTable); + + if (m_bMemoryQuery) + { + MemoryCache_DBData_DataInsert(pSt_DBInfo); + } return true; } /******************************************************************** @@ -270,6 +310,10 @@ bool CDBModule_MQData::DBModule_MQData_Modify(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_NOTFOUND; return false; } + if (m_bMemoryQuery) + { + MemoryCache_DBData_DataInsert(pSt_DBInfo); + } return true; } /******************************************************************** @@ -575,6 +619,15 @@ bool CDBModule_MQData::DBModule_MQData_DeleteTable(LPCXSTR lpszQueueName) DBModule_dwErrorCode = DataBase_GetLastError(); return false; } + + if (m_bMemoryQuery) + { + XENGINE_DBMESSAGEQUEUE st_MessageQueue = {}; + + st_MessageQueue.nQueueSerial = -1; + _tcsxcpy(st_MessageQueue.tszQueueName, lpszQueueName); + MemoryCache_DBData_DataDelete(&st_MessageQueue); + } return true; } /******************************************************************** diff --git a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h index 492cfbc..18c696b 100644 --- a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h +++ b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h @@ -17,7 +17,7 @@ class CDBModule_MQData CDBModule_MQData(); ~CDBModule_MQData(); public: - bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector); + bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryQuery = true, bool bMemoryInsert = true); bool DBModule_MQData_Destory(); bool DBModule_MQData_Insert(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo); bool DBModule_MQData_Query(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo); @@ -29,5 +29,7 @@ class CDBModule_MQData bool DBModule_MQData_ShowTable(XCHAR*** pppszTableName, int* pInt_ListCount); bool DBModule_MQData_GetLeftCount(LPCXSTR lpszTableName, int nSerial, int* pInt_Count); private: - XNETHANDLE xhDBSQL; + bool m_bMemoryQuery = false; + bool m_bMemoryInsert = false; + XNETHANDLE xhDBSQL = 0; }; \ No newline at end of file diff --git a/XEngine_Source/MQCore_DBModule/Makefile b/XEngine_Source/MQCore_DBModule/Makefile index e7217a8..cb608ab 100644 --- a/XEngine_Source/MQCore_DBModule/Makefile +++ b/XEngine_Source/MQCore_DBModule/Makefile @@ -6,8 +6,8 @@ FILEEXT = LIBFLAG = RELEASE = 0 LOADHDR = -I ./ -LOADSO = -LIB = -lXEngine_BaseLib -lHelpComponents_DataBase +LOADSO = -L ../MQCore_MemoryCache +LIB = -lXEngine_BaseLib -lHelpComponents_DataBase -lMQCore_MemoryCache LIBEX = OBJECTS = DBModule_MQData.o DBModule_MQUser.o pch.o diff --git a/XEngine_Source/MQCore_DBModule/pch.cpp b/XEngine_Source/MQCore_DBModule/pch.cpp index 9f58222..a2707e4 100644 --- a/XEngine_Source/MQCore_DBModule/pch.cpp +++ b/XEngine_Source/MQCore_DBModule/pch.cpp @@ -31,9 +31,9 @@ extern "C" XLONG DBModule_GetLastError(int* pInt_SysError) /************************************************************************* 消息队列导出函数 **************************************************************************/ -extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO * pSt_DBConnector) +extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO * pSt_DBConnector, bool bMemoryQuery, bool bMemoryInsert) { - return m_DBData.DBModule_MQData_Init(pSt_DBConnector); + return m_DBData.DBModule_MQData_Init(pSt_DBConnector, bMemoryQuery, bMemoryInsert); } extern "C" bool DBModule_MQData_Destory() { diff --git a/XEngine_Source/MQCore_DBModule/pch.h b/XEngine_Source/MQCore_DBModule/pch.h index 45ca327..3fbb3a7 100644 --- a/XEngine_Source/MQCore_DBModule/pch.h +++ b/XEngine_Source/MQCore_DBModule/pch.h @@ -30,6 +30,8 @@ using namespace std; #include #include "DBModule_Define.h" #include "DBModule_Error.h" +#include "../MQCore_MemoryCache/MemoryCache_Define.h" +#include "../MQCore_MemoryCache/MemoryCache_Error.h" /******************************************************************** // Created: 2022/02/23 16:14:35 // File Name: D:\XEngine_MQService\XEngine_Source\MQCore_DBModule\pch.h @@ -47,4 +49,17 @@ extern XLONG DBModule_dwErrorCode; #ifdef _MSC_BUILD #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_DataBase.lib") +#ifdef _DEBUG +#ifdef _WIN64 +#pragma comment(lib,"../x64/Debug/MQCore_MemoryCache.lib") +#else +#pragma comment(lib,"../Debug/MQCore_MemoryCache.lib") +#endif +#else +#ifdef _WIN64 +#pragma comment(lib,"../x64/Release/MQCore_MemoryCache.lib") +#else +#pragma comment(lib,"../Release/MQCore_MemoryCache.lib") +#endif +#endif #endif \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.def b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.def new file mode 100644 index 0000000..a5881ce --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.def @@ -0,0 +1,12 @@ +LIBRARY + +EXPORTS + MemoryCache_GetLastError + + MemoryCache_DBData_Init + MemoryCache_DBData_SetHandle + MemoryCache_DBData_Destory + MemoryCache_DBData_DataInsert + MemoryCache_DBData_DataQuery + MemoryCache_DBData_DataDelete + MemoryCache_DBData_QueueInsert \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj new file mode 100644 index 0000000..49b13b3 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj @@ -0,0 +1,193 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {8c55d3e0-fec2-4a6c-a374-651516ed8f99} + MQCoreMemoryCache + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(XEngine_Include);..\MQCore_MemoryCache;$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + $(ReferencePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + + Level3 + true + WIN32;_DEBUG;MQCOREMEMORYCACHE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp20 + stdc17 + + + Windows + true + false + MQCore_MemoryCache.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;MQCOREMEMORYCACHE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp20 + stdc17 + + + Windows + true + true + true + false + MQCore_MemoryCache.def + + + + + Level3 + true + _DEBUG;MQCOREMEMORYCACHE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp20 + stdc17 + + + Windows + true + false + MQCore_MemoryCache.def + + + + + Level3 + true + true + true + NDEBUG;MQCOREMEMORYCACHE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp20 + stdc17 + + + Windows + true + true + true + false + MQCore_MemoryCache.def + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.filters b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.filters new file mode 100644 index 0000000..da7be03 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.filters @@ -0,0 +1,56 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {4c036899-9b97-4388-94f1-12e980800877} + + + {d3182e9a-8f45-4138-b4e2-a793c976d18d} + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件\MemoryCache_DBData + + + + + 源文件 + + + 源文件 + + + 源文件\MemoryCache_DBData + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.user b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/Makefile b/XEngine_Source/MQCore_MemoryCache/Makefile new file mode 100644 index 0000000..03b11ce --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/Makefile @@ -0,0 +1,69 @@ +CC = g++ -Wall -std=c++17 -fPIC +PLATFORM = linux +PLATVER = +PLATDIR = +FILEEXT = +LIBFLAG = +RELEASE = 0 +LOADHDR = -I ./ +LOADSO = +LIB = -lHelpComponents_DataBase +LIBEX = +OBJECTS = MemoryCache_DBData.o pch.o + +ifeq ($(RELEASE),1) +FLAGS = -c +DEBUG = +else + ifeq ($(PLATFORM),mac) + FLAGS = -c + DEBUG = -g + else + FLAGS = -c -lc_p + DEBUG = -g -pg + endif +endif + +ifeq ($(PLATFORM),linux) + ifeq (/etc/redhat-release,$(wildcard /etc/redhat-release)) + PLATVER = -D __CENTOS__ + PLATDIR = XEngine_Linux/Centos + else + PLATVER = -D __UBUNTU__ + PLATDIR = XEngine_Linux/Ubuntu + endif + FILEEXT = so + LIBFLAG = -shared + LIBEX = -lpthread -lrt -ldl + LOADBIN = -Wl,-rpath=./,--disable-new-dtags +else ifeq ($(PLATFORM),mac) + CC += -Wno-deprecated-declarations + PLATVER = -D __MACOS__ + PLATDIR = XEngine_Mac + FILEEXT = dylib + LIBFLAG = -dynamiclib + LIBEX = -lpthread -ldl + LOADBIN = -Wl,-rpath,@loader_path/./ +endif + + +all:$(OBJECTS) + $(CC) $(DEBUG) $(OBJECTS) -o libMQCore_MemoryCache.$(FILEEXT) $(LIBFLAG) $(LIB) $(LIBEX) $(LOADSO) $(LOADBIN) + +MemoryCache_DBData.o:./MemoryCache_DBData/MemoryCache_DBData.cpp + $(CC) $(DEBUG) $(FLAGS) $(PLATVER) $(LOADHDR) ./MemoryCache_DBData/MemoryCache_DBData.cpp + +pch.o:./pch.cpp + $(CC) $(DEBUG) $(FLAGS) $(PLATVER) $(LOADHDR) ./pch.cpp + + +InstallAll:InstallSo +InstallSo:./libMQCore_MemoryCache.$(FILEEXT) + cp ./libMQCore_MemoryCache.$(FILEEXT) ../../XEngine_Release/libMQCore_MemoryCache.$(FILEEXT) + + +CleanAll:CleanObj CleanMk +CleanObj: + rm *.o +CleanMk: + rm *.$(FILEEXT) \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp new file mode 100644 index 0000000..772a61f --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp @@ -0,0 +1,352 @@ +#include "pch.h" +#include "MemoryCache_DBData.h" +/******************************************************************** +// Created: 2024/11/21 16:35:54 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_DBData\MemoryCache_DBData.cpp +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_DBData +// File Base: MemoryCache_DBData +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 数据库高速缓存 +// History: +*********************************************************************/ +CMemoryCache_DBData::CMemoryCache_DBData() +{ +} +CMemoryCache_DBData::~CMemoryCache_DBData() +{ + +} +////////////////////////////////////////////////////////////////////////// +// 公有函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:MemoryCache_DBData_Init +函数功能:初始化高速缓存管理器 + 参数.一:nTimeLast + In/Out:In + 类型:整数型 + 可空:N + 意思:允许的最后更新时间存在秒数 + 参数.二:nTimeStart + In/Out:In + 类型:整数型 + 可空:N + 意思:允许的最大保留时间 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_Init(int nTimeLast, int nTimeStart, CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE fpCall_MemoryCache, XPVOID lParam /* = NULL */) +{ + MemoryCache_IsErrorOccur = false; + + bIsRun = true; + + m_nTimeLast = nTimeLast; + m_nTimeStart = nTimeStart; + m_lParam = lParam; + lpCall_MemoryCache = fpCall_MemoryCache; + + pSTDThread_Query = std::make_unique(DBModule_MQUser_TimeThread, this); + if (NULL == pSTDThread_Query) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_THREAD; + return false; + } + pSTDThread_Insert = std::make_unique(DBModule_MQUser_InsertThread, this); + if (NULL == pSTDThread_Insert) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_THREAD; + return false; + } + return true; +} +/******************************************************************** +函数名称:MemoryCache_DBData_SetHandle +函数功能:设置句柄 + 参数.一:xhDBSQL + In/Out:In + 类型:句柄 + 可空:N + 意思:数据库句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_SetHandle(XNETHANDLE xhDBSQL) +{ + MemoryCache_IsErrorOccur = false; + + m_xhDBSQL = xhDBSQL; + + return true; +} +/******************************************************************** +函数名称:MemoryCache_DBData_Destory +函数功能:销毁高速缓存管理器 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_Destory() +{ + MemoryCache_IsErrorOccur = false; + + bIsRun = false; + if (NULL != pSTDThread_Query) + { + pSTDThread_Query->join(); + } + if (NULL != pSTDThread_Insert) + { + pSTDThread_Insert->join(); + } + return true; +} +/******************************************************************** +函数名称:MemoryCache_DBData_DataInsert +函数功能:插入一条数据到高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要插入的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_DataInsert(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + MemoryCache_IsErrorOccur = false; + + if (NULL == pSt_DBMessageInfo) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT; + return false; + } + + MEMORYCACHE_DBINFO st_DBInfo = {}; + + st_DBInfo.nTimeStart = time(NULL); + st_DBInfo.st_DBMessageInfo = *pSt_DBMessageInfo; + + std::tuple<__int64x, std::string> stl_Key(pSt_DBMessageInfo->nQueueSerial, pSt_DBMessageInfo->tszQueueName); + + st_LockerQuery.lock(); + auto stl_MapIterator = stl_MapQuery.find(stl_Key); + if (stl_MapIterator == stl_MapQuery.end()) + { + stl_MapQuery[stl_Key] = st_DBInfo; + } + else + { + stl_MapIterator->second.st_DBMessageInfo = *pSt_DBMessageInfo; + } + st_LockerQuery.unlock(); + return true; +} +/******************************************************************** +函数名称:MemoryCache_DBData_DataQuery +函数功能:查询高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要查询的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + MemoryCache_IsErrorOccur = false; + + if (NULL == pSt_DBMessageInfo) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT; + return false; + } + + std::tuple<__int64x, std::string> stl_Key(pSt_DBMessageInfo->nQueueSerial, pSt_DBMessageInfo->tszQueueName); + + st_LockerQuery.lock_shared(); + auto stl_MapIterator = stl_MapQuery.find(stl_Key); + if (stl_MapIterator == stl_MapQuery.end()) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_NOTFOUND; + st_LockerQuery.unlock_shared(); + return false; + } + stl_MapIterator->second.nTimeLast = time(NULL); + *pSt_DBMessageInfo = stl_MapIterator->second.st_DBMessageInfo; + st_LockerQuery.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:MemoryCache_DBData_DataDelete +函数功能:删除高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要操作的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + MemoryCache_IsErrorOccur = false; + + if (NULL == pSt_DBMessageInfo) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT; + return false; + } + + st_LockerQuery.lock(); + if (-1 == pSt_DBMessageInfo->nQueueSerial) + { + for (auto stl_MapIterator = stl_MapQuery.begin(); stl_MapIterator != stl_MapQuery.end(); ) + { + if (std::get<1>((stl_MapIterator->first)) == pSt_DBMessageInfo->tszQueueName) + { + stl_MapIterator = stl_MapQuery.erase(stl_MapIterator); + } + else + { + stl_MapIterator++; + } + } + } + else + { + std::tuple<__int64x, std::string> stl_Key(pSt_DBMessageInfo->nQueueSerial, pSt_DBMessageInfo->tszQueueName); + auto stl_MapIterator = stl_MapQuery.find(stl_Key); + if (stl_MapIterator != stl_MapQuery.end()) + { + stl_MapQuery.erase(stl_Key); + } + } + st_LockerQuery.unlock(); + return true; +} +/******************************************************************** +函数名称:MemoryCache_DBData_QueueInsert +函数功能:队列插入工具 + 参数.一:lpszSQLStr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的语句 + 参数.二:pSt_DBMessageInfo + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的数据 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr, XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + MemoryCache_IsErrorOccur = false; + + if (NULL == lpszSQLStr) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT; + return false; + } + MEMORYCACHE_DBINSERT st_DBInsert = {}; + + st_DBInsert.m_StrSQL = lpszSQLStr; + st_DBInsert.st_DBMessageInfo = *pSt_DBMessageInfo; + + st_LockerList.lock(); + stl_ListInsert.push_back(st_DBInsert); + st_LockerList.unlock(); + return true; +} +////////////////////////////////////////////////////////////////////////// +// 线程函数 +////////////////////////////////////////////////////////////////////////// +XHTHREAD CALLBACK CMemoryCache_DBData::DBModule_MQUser_TimeThread(XPVOID lParam) +{ + CMemoryCache_DBData* pClass_This = (CMemoryCache_DBData*)lParam; + + std::list stl_ListDelete; + while (pClass_This->bIsRun) + { + time_t nTimeEnd = time(NULL); + pClass_This->st_LockerQuery.lock_shared(); + for (auto stl_MapIterator = pClass_This->stl_MapQuery.begin(); stl_MapIterator != pClass_This->stl_MapQuery.end(); stl_MapIterator++) + { + if (stl_MapIterator->second.nTimeLast > (nTimeEnd - pClass_This->m_nTimeLast)) + { + stl_ListDelete.push_back(stl_MapIterator->second.st_DBMessageInfo); + } + else if (pClass_This->m_nTimeStart > 0 && (nTimeEnd - pClass_This->m_nTimeStart)) + { + stl_ListDelete.push_back(stl_MapIterator->second.st_DBMessageInfo); + } + } + pClass_This->st_LockerQuery.unlock_shared(); + + for (auto stl_ListIterator = stl_ListDelete.begin(); stl_ListIterator != stl_ListDelete.end(); stl_ListIterator++) + { + XENGINE_DBMESSAGEQUEUE st_DBMessage = *stl_ListIterator; + if (pClass_This->MemoryCache_DBData_DataDelete(&st_DBMessage)) + { + pClass_This->lpCall_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_QUERY, true, pClass_This->stl_ListInsert.size(), &st_DBMessage, pClass_This->m_lParam); + } + else + { + pClass_This->lpCall_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_QUERY, false, pClass_This->stl_ListInsert.size(), &st_DBMessage, pClass_This->m_lParam); + } + } + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + return 0; +} +XHTHREAD CALLBACK CMemoryCache_DBData::DBModule_MQUser_InsertThread(XPVOID lParam) +{ + CMemoryCache_DBData* pClass_This = (CMemoryCache_DBData*)lParam; + + while (pClass_This->bIsRun) + { + if (!pClass_This->stl_ListInsert.empty()) + { + pClass_This->st_LockerList.lock(); + MEMORYCACHE_DBINSERT st_DBInsert = pClass_This->stl_ListInsert.front(); + pClass_This->stl_ListInsert.pop_front(); + pClass_This->st_LockerList.unlock(); + + if (DataBase_MySQL_Execute(pClass_This->m_xhDBSQL, st_DBInsert.m_StrSQL.c_str())) + { + pClass_This->lpCall_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_INSERT, true, pClass_This->stl_ListInsert.size(), &st_DBInsert.st_DBMessageInfo, pClass_This->m_lParam); + } + else + { + pClass_This->lpCall_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_INSERT, false, pClass_This->stl_ListInsert.size(), &st_DBInsert.st_DBMessageInfo, pClass_This->m_lParam); + } + } + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + return 0; +} \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h new file mode 100644 index 0000000..09ecd58 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h @@ -0,0 +1,73 @@ +#pragma once +/******************************************************************** +// Created: 2024/11/21 16:35:19 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_DBData\MemoryCache_DBData.h +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_DBData +// File Base: MemoryCache_DBData +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 数据库高速缓存 +// History: +*********************************************************************/ +typedef struct +{ + XENGINE_DBMESSAGEQUEUE st_DBMessageInfo; + time_t nTimeStart; + time_t nTimeLast; +}MEMORYCACHE_DBINFO; +typedef struct +{ + XENGINE_DBMESSAGEQUEUE st_DBMessageInfo; + std::string m_StrSQL; +}MEMORYCACHE_DBINSERT; + +struct TupleHash +{ + template + std::size_t operator()(const std::tuple& t) const + { + return std::apply([](auto&&... args) + { + std::size_t seed = 0; + ((seed ^= std::hash>()(args) + 0x9e3779b9 + (seed << 6) + (seed >> 2)), ...); + return seed; + }, t); + } +}; + +class CMemoryCache_DBData +{ +public: + CMemoryCache_DBData(); + ~CMemoryCache_DBData(); +public: + bool MemoryCache_DBData_Init(int nTimeLast, int nTimeStart, CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE fpCall_MemoryCache, XPVOID lParam = NULL); + bool MemoryCache_DBData_SetHandle(XNETHANDLE xhDBSQL); + bool MemoryCache_DBData_Destory(); +public: + bool MemoryCache_DBData_DataInsert(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); + bool MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); + bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); +public: + bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr, XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); +protected: + static XHTHREAD CALLBACK DBModule_MQUser_TimeThread(XPVOID lParam); + static XHTHREAD CALLBACK DBModule_MQUser_InsertThread(XPVOID lParam); +private: + bool bIsRun = false; + int m_nTimeLast = 0; + int m_nTimeStart = 0; + XNETHANDLE m_xhDBSQL = 0; + + XPVOID m_lParam; + CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE lpCall_MemoryCache; +private: + std::shared_mutex st_LockerList; + std::shared_mutex st_LockerQuery; + std::unique_ptr pSTDThread_Query; + std::unique_ptr pSTDThread_Insert; +private: + std::list stl_ListInsert; + std::unordered_map, MEMORYCACHE_DBINFO, TupleHash> stl_MapQuery; +}; \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h new file mode 100644 index 0000000..98d6b74 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h @@ -0,0 +1,131 @@ +#pragma once +/******************************************************************** +// Created: 2024/11/21 15:09:57 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_Define.h +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache +// File Base: MemoryCache_Define +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出的函数 +// History: +*********************************************************************/ +typedef enum +{ + ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_QUERY = 0, + ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_INSERT = 1 +}ENUM_MEMORYCACHE_CALLBACK_TYPE; +////////////////////////////////////////////////////////////////////////// +// 导出的回调 +////////////////////////////////////////////////////////////////////////// +typedef void(CALLBACK* CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE)(ENUM_MEMORYCACHE_CALLBACK_TYPE enMemoryType, bool bSuccess, size_t nListCount, XENGINE_DBMESSAGEQUEUE* pSt_DBInfo, XPVOID lParam); +////////////////////////////////////////////////////////////////////////// +// 导出的函数 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG MemoryCache_GetLastError(int *pInt_SysError = NULL); +/************************************************************************* + 高速缓存导出函数 +**************************************************************************/ +/******************************************************************** +函数名称:MemoryCache_DBData_Init +函数功能:初始化高速缓存管理器 + 参数.一:nTimeLast + In/Out:In + 类型:整数型 + 可空:N + 意思:允许的最后更新时间存在秒数 + 参数.二:nTimeStart + In/Out:In + 类型:整数型 + 可空:N + 意思:允许的最大保留时间 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_Init(int nTimeLast, int nTimeStart, CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE fpCall_MemoryCache, XPVOID lParam = NULL); +/******************************************************************** +函数名称:MemoryCache_DBData_SetHandle +函数功能:设置句柄 + 参数.一:xhDBSQL + In/Out:In + 类型:句柄 + 可空:N + 意思:数据库句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_SetHandle(XNETHANDLE xhDBSQL); +/******************************************************************** +函数名称:MemoryCache_DBData_Destory +函数功能:销毁高速缓存管理器 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_Destory(); +/******************************************************************** +函数名称:MemoryCache_DBData_DataInsert +函数功能:插入一条数据到高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要插入的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_DataInsert(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); +/******************************************************************** +函数名称:MemoryCache_DBData_DataQuery +函数功能:查询高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要查询的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); +/******************************************************************** +函数名称:MemoryCache_DBData_DataDelete +函数功能:删除高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要操作的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); +/******************************************************************** +函数名称:MemoryCache_DBData_QueueInsert +函数功能:队列插入工具 + 参数.一:lpszSQLStr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的语句 + 参数.二:pSt_DBMessageInfo + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的数据 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr, XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_Error.h b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Error.h new file mode 100644 index 0000000..c3dea5b --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Error.h @@ -0,0 +1,18 @@ +#pragma once +/******************************************************************** +// Created: 2024/11/21 15:10:20 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_Error.h +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache +// File Base: MemoryCache_Error +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出的错误 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 导出的错误 +////////////////////////////////////////////////////////////////////////// +#define ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_THREAD 0x1A0001 //创建线程失败 +#define ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT 0x1A0002 //参数错误 +#define ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_NOTFOUND 0x1A0003 //没有找到 \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/dllmain.cpp b/XEngine_Source/MQCore_MemoryCache/dllmain.cpp new file mode 100644 index 0000000..daed8c8 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : 定义 DLL 应用程序的入口点。 +#include "pch.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/XEngine_Source/MQCore_MemoryCache/framework.h b/XEngine_Source/MQCore_MemoryCache/framework.h new file mode 100644 index 0000000..80cbbc9 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/XEngine_Source/MQCore_MemoryCache/pch.cpp b/XEngine_Source/MQCore_MemoryCache/pch.cpp new file mode 100644 index 0000000..fe28202 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/pch.cpp @@ -0,0 +1,59 @@ +#include "pch.h" +#include "MemoryCache_DBData/MemoryCache_DBData.h" +/******************************************************************** +// Created: 2024/11/21 15:01:53 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\pch.cpp +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache +// File Base: pch +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出实现 +// History: +*********************************************************************/ +bool MemoryCache_IsErrorOccur = false; +XLONG MemoryCache_dwErrorCode = 0; +////////////////////////////////////////////////////////////////////////// +CMemoryCache_DBData m_MemoryDBData; +////////////////////////////////////////////////////////////////////////// +// 导出的函数 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG MemoryCache_GetLastError(int* pInt_SysError) +{ + if (NULL != pInt_SysError) + { + *pInt_SysError = errno; + } + return MemoryCache_dwErrorCode; +} +/************************************************************************* + 高速缓存导出函数 +**************************************************************************/ +extern "C" bool MemoryCache_DBData_Init(int nTimeLast, int nTimeStart, CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE fpCall_MemoryCache, XPVOID lParam) +{ + return m_MemoryDBData.MemoryCache_DBData_Init(nTimeLast, nTimeStart, fpCall_MemoryCache, lParam); +} +extern "C" bool MemoryCache_DBData_SetHandle(XNETHANDLE xhDBSQL) +{ + return m_MemoryDBData.MemoryCache_DBData_SetHandle(xhDBSQL); +} +extern "C" bool MemoryCache_DBData_Destory() +{ + return m_MemoryDBData.MemoryCache_DBData_Destory(); +} +extern "C" bool MemoryCache_DBData_DataInsert(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + return m_MemoryDBData.MemoryCache_DBData_DataInsert(pSt_DBMessageInfo); +} +extern "C" bool MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + return m_MemoryDBData.MemoryCache_DBData_DataQuery(pSt_DBMessageInfo); +} +extern "C" bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + return m_MemoryDBData.MemoryCache_DBData_DataDelete(pSt_DBMessageInfo); +} +extern "C" bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr, XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + return m_MemoryDBData.MemoryCache_DBData_QueueInsert(lpszSQLStr, pSt_DBMessageInfo); +} \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/pch.h b/XEngine_Source/MQCore_MemoryCache/pch.h new file mode 100644 index 0000000..81e84e2 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/pch.h @@ -0,0 +1,50 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +#ifdef _MSC_BUILD +// 添加要在此处预编译的标头 +#include "framework.h" +#endif +#endif //PCH_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../MQCore_DBModule/DBModule_Define.h" +#include "../MQCore_DBModule/DBModule_Error.h" +#include "MemoryCache_Define.h" +#include "MemoryCache_Error.h" +/******************************************************************** +// Created: 2024/11/21 14:44:49 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\pch.h +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache +// File Base: pch +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 公用头 +// History: +*********************************************************************/ +extern bool MemoryCache_IsErrorOccur; +extern XLONG MemoryCache_dwErrorCode; + +#ifdef _MSC_BUILD +#pragma comment(lib,"XEngine_HelpComponents/HelpComponents_DataBase.lib") +#endif \ No newline at end of file diff --git a/XEngine_Source/Makefile b/XEngine_Source/Makefile index b2e6f23..36bf6fc 100644 --- a/XEngine_Source/Makefile +++ b/XEngine_Source/Makefile @@ -8,6 +8,7 @@ BASE_THIRDPART_REPORT = ./XEngine_Depend/XEngine_Module/XEngine_InfoReport BASE_CONFIG_PATH = ./MQCore_ConfigModule BASE_PROTOCOL_PATH = ./MQCore_ProtocolModule +BASE_MEMORYCACHE_PATH = ./MQCore_MemoryCache BASE_DATABASE_PATH = ./MQCore_DBModule BASE_SESSION_PATH = ./MQCore_SessionModule @@ -20,7 +21,7 @@ else ifeq ($(PLATFORM),mac) endif XENGINE_MODULES = libjsoncpp.so libXEngine_InfoReport.so \ - libMQCore_ConfigModule.so libMQCore_ProtocolModule.so libMQCore_SessionModule.so libMQCore_DBModule.so \ + libMQCore_ConfigModule.so libMQCore_ProtocolModule.so libMQCore_SessionModule.so libMQCore_MemoryCache.so libMQCore_DBModule.so \ XEngine_MQServiceApp.exe .PHONY:MakeAll @@ -46,6 +47,8 @@ libMQCore_ProtocolModule.so: make -C $(BASE_PROTOCOL_PATH) PLATFORM=$(PLATFORM) $(FLAGS) libMQCore_SessionModule.so: make -C $(BASE_SESSION_PATH) PLATFORM=$(PLATFORM) $(FLAGS) +libMQCore_MemoryCache.so: + make -C $(BASE_MEMORYCACHE_PATH) PLATFORM=$(PLATFORM) $(FLAGS) libMQCore_DBModule.so: make -C $(BASE_DATABASE_PATH) PLATFORM=$(PLATFORM) $(FLAGS) diff --git a/XEngine_Source/VSCopy-x64.bat b/XEngine_Source/VSCopy_x64.bat similarity index 100% rename from XEngine_Source/VSCopy-x64.bat rename to XEngine_Source/VSCopy_x64.bat diff --git a/XEngine_Source/VSCopy-x86.bat b/XEngine_Source/VSCopy_x86.bat similarity index 100% rename from XEngine_Source/VSCopy-x86.bat rename to XEngine_Source/VSCopy_x86.bat diff --git a/XEngine_Source/XEngine_Depend b/XEngine_Source/XEngine_Depend index bf32fe9..1c1452f 160000 --- a/XEngine_Source/XEngine_Depend +++ b/XEngine_Source/XEngine_Depend @@ -1 +1 @@ -Subproject commit bf32fe97c51e74c15c7f3998c6cf88220ddfc36c +Subproject commit 1c1452f13720d22834e09c7e4e78042698411486 diff --git a/XEngine_Source/XEngine_MQServiceApp.sln b/XEngine_Source/XEngine_MQServiceApp.sln index 718dfab..3315a56 100644 --- a/XEngine_Source/XEngine_MQServiceApp.sln +++ b/XEngine_Source/XEngine_MQServiceApp.sln @@ -8,6 +8,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_MQServiceApp", "XEn {32D3FC68-6252-4D20-BB07-6C98BD753D11} = {32D3FC68-6252-4D20-BB07-6C98BD753D11} {5475F316-F9E9-4FF5-95ED-F7C9474709A3} = {5475F316-F9E9-4FF5-95ED-F7C9474709A3} {77321E0D-15DB-4C6E-8872-115CBBE41F27} = {77321E0D-15DB-4C6E-8872-115CBBE41F27} + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99} = {8C55D3E0-FEC2-4A6C-A374-651516ED8F99} {B0EB2A7A-53C1-4E9F-A851-19539099671C} = {B0EB2A7A-53C1-4E9F-A851-19539099671C} {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} = {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} {F6520D2C-BB8E-45BB-964B-F5D6A4318A89} = {F6520D2C-BB8E-45BB-964B-F5D6A4318A89} @@ -31,6 +32,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MQCore_Hdr", "MQCore_Hdr", EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MQCore_DBModule", "MQCore_DBModule\MQCore_DBModule.vcxproj", "{5475F316-F9E9-4FF5-95ED-F7C9474709A3}" + ProjectSection(ProjectDependencies) = postProject + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99} = {8C55D3E0-FEC2-4A6C-A374-651516ED8F99} + EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "XEngine_Depend", "XEngine_Depend", "{BAC91AAE-D438-4999-9541-EB8804B12F0C}" EndProject @@ -41,6 +45,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_InfoReport", "XEngi {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} = {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MQCore_MemoryCache", "MQCore_MemoryCache\MQCore_MemoryCache.vcxproj", "{8C55D3E0-FEC2-4A6C-A374-651516ED8F99}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -105,6 +111,14 @@ Global {F6520D2C-BB8E-45BB-964B-F5D6A4318A89}.Release|x64.Build.0 = Release|x64 {F6520D2C-BB8E-45BB-964B-F5D6A4318A89}.Release|x86.ActiveCfg = Release|Win32 {F6520D2C-BB8E-45BB-964B-F5D6A4318A89}.Release|x86.Build.0 = Release|Win32 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Debug|x64.ActiveCfg = Debug|x64 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Debug|x64.Build.0 = Debug|x64 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Debug|x86.ActiveCfg = Debug|Win32 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Debug|x86.Build.0 = Debug|Win32 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Release|x64.ActiveCfg = Release|x64 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Release|x64.Build.0 = Release|x64 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Release|x86.ActiveCfg = Release|Win32 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_Config.cpp b/XEngine_Source/XEngine_MQServiceApp/MQService_Config.cpp index e8fe2d1..22a9ab7 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_Config.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_Config.cpp @@ -30,15 +30,15 @@ bool MQ_Service_Parament(int argc, char** argv, XENGINE_SERVERCONFIG* pSt_Startl } else if (0 == _tcsxcmp("-TP",argv[i])) { - pSt_StartlParam->nTCPPort = _ttxoi(argv[i + 1]); + pSt_StartlParam->nTCPPort = _ttxoi(argv[++i]); } else if (0 == _tcsxcmp("-HP",argv[i])) { - pSt_StartlParam->nHttpPort = _ttxoi(argv[i + 1]); + pSt_StartlParam->nHttpPort = _ttxoi(argv[++i]); } else if (0 == _tcsxcmp("-d",argv[i])) { - pSt_StartlParam->bDeamon = _ttxoi(argv[i + 1]); + pSt_StartlParam->bDeamon = _ttxoi(argv[++i]); } else if (0 == _tcsxcmp("-t", argv[i])) { diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h b/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h index feb0c0e..e9113e9 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h @@ -3,6 +3,7 @@ #include #include #include +#include #else #include #include @@ -58,6 +59,8 @@ typedef std::string tstring; #include "../MQCore_DBModule/DBModule_Error.h" #include "../MQCore_ProtocolModule/Protocol_Define.h" #include "../MQCore_ProtocolModule/Protocol_Error.h" +#include "../MQCore_MemoryCache/MemoryCache_Define.h" +#include "../MQCore_MemoryCache/MemoryCache_Error.h" extern bool bIsRun; extern bool bIsTest; @@ -98,6 +101,7 @@ extern MESSAGEQUEUE_DBCONFIG st_DBConfig; #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_WSProtocol.lib") #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_MQTTProtocol.lib") #pragma comment(lib,"Ws2_32.lib") +#pragma comment(lib,"Dbghelp.lib") #ifdef _DEBUG #ifdef _WIN64 #pragma comment(lib,"../x64/Debug/MQCore_ConfigModule.lib") @@ -105,12 +109,14 @@ extern MESSAGEQUEUE_DBCONFIG st_DBConfig; #pragma comment(lib,"../x64/Debug/MQCore_SessionModule.lib") #pragma comment(lib,"../x64/Debug/MQCore_DBModule.lib") #pragma comment(lib,"../x64/Debug/XEngine_InfoReport.lib") +#pragma comment(lib,"../x64/Debug/MQCore_MemoryCache.lib") #else #pragma comment(lib,"../Debug/MQCore_ConfigModule.lib") #pragma comment(lib,"../Debug/MQCore_ProtocolModule.lib") #pragma comment(lib,"../Debug/MQCore_SessionModule.lib") #pragma comment(lib,"../Debug/MQCore_DBModule.lib") #pragma comment(lib,"../Debug/XEngine_InfoReport.lib") +#pragma comment(lib,"../Debug/MQCore_MemoryCache.lib") #endif #else #ifdef _WIN64 @@ -119,12 +125,14 @@ extern MESSAGEQUEUE_DBCONFIG st_DBConfig; #pragma comment(lib,"../x64/Release/MQCore_SessionModule.lib") #pragma comment(lib,"../x64/Release/MQCore_DBModule.lib") #pragma comment(lib,"../x64/Release/XEngine_InfoReport.lib") +#pragma comment(lib,"../x64/Release/MQCore_MemoryCache.lib") #else #pragma comment(lib,"../Release/MQCore_ConfigModule.lib") #pragma comment(lib,"../Release/MQCore_ProtocolModule.lib") #pragma comment(lib,"../Release/MQCore_SessionModule.lib") #pragma comment(lib,"../Release/MQCore_DBModule.lib") #pragma comment(lib,"../Release/XEngine_InfoReport.lib") +#pragma comment(lib,"../Release/MQCore_MemoryCache.lib") #endif #endif #endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp b/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp index 3fb0c82..34ce1d5 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp @@ -434,39 +434,51 @@ bool MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCXSTR lpszC } else { - int nListCount = 0; - XENGINE_DBUSERKEY** ppSt_ListUser; - DBModule_MQUser_KeyList(NULL, st_MQProtocol.tszMQKey, &ppSt_ListUser, &nListCount); + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_MSGNOTIFY; - for (int i = 0; i < nListCount; i++) + if (_tcsxlen(st_MQProtocol.tszMQUsr) > 0) { - //跳过自己 - if (0 == _tcsxncmp(tszUserName, ppSt_ListUser[i]->tszUserName, _tcsxlen(tszUserName)) && (0 == st_MQProtocol.st_MSGAttr.byAttrSelf)) + //如果发送指定用户被指定. + if (SessionModule_Client_GetExist(NULL, st_MQProtocol.tszMQUsr)) { - continue; + int nClientType = 0; + XCHAR tszUserAddr[128] = {}; + + SessionModule_Client_GetAddr(st_MQProtocol.tszMQUsr, tszUserAddr); + SessionModule_Client_GetType(tszUserAddr, &nClientType); + ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ)); + XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType); } - nSDLen = 0; - int nClientType = 0; - XCHAR tszUserAddr[128]; - memset(tszUserAddr, '\0', sizeof(tszUserAddr)); - memset(tszSDBuffer, '\0', sizeof(tszSDBuffer)); + } + else + { + int nListCount = 0; + XENGINE_DBUSERKEY** ppSt_ListUser; + DBModule_MQUser_KeyList(NULL, st_MQProtocol.tszMQKey, &ppSt_ListUser, &nListCount); - pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_MSGNOTIFY; - //只有在线用户才需要即时通知 - if (SessionModule_Client_GetExist(NULL, tszUserName)) + for (int i = 0; i < nListCount; i++) { - //如果发送指定用户被指定. - if ((_tcsxlen(st_MQProtocol.tszMQUsr) > 0) && (0 != _tcsxnicmp(st_MQProtocol.tszMQUsr, tszUserName, _tcsxlen(st_MQProtocol.tszMQUsr)))) + //跳过自己 + if (0 == _tcsxncmp(tszUserName, ppSt_ListUser[i]->tszUserName, _tcsxlen(tszUserName)) && (0 == st_MQProtocol.st_MSGAttr.byAttrSelf)) { continue; } - SessionModule_Client_GetAddr(ppSt_ListUser[i]->tszUserName, tszUserAddr); - SessionModule_Client_GetType(tszUserAddr, &nClientType); - ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ)); - XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType); + nSDLen = 0; + int nClientType = 0; + XCHAR tszUserAddr[128]; + memset(tszUserAddr, '\0', sizeof(tszUserAddr)); + memset(tszSDBuffer, '\0', sizeof(tszSDBuffer)); + //只有在线用户才需要即时通知 + if (SessionModule_Client_GetExist(NULL, ppSt_ListUser[i]->tszUserName)) + { + SessionModule_Client_GetAddr(ppSt_ListUser[i]->tszUserName, tszUserAddr); + SessionModule_Client_GetType(tszUserAddr, &nClientType); + ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ)); + XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType); + } } + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListUser, nListCount); } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListUser, nListCount); } _xstprintf(st_DBQueue.tszQueuePublishTime, _X("0")); } diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_Task.cpp b/XEngine_Source/XEngine_MQServiceApp/MQService_Task.cpp index 37e90ab..d70bfcb 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_Task.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_Task.cpp @@ -60,4 +60,29 @@ void CALLBACK MessageQueue_CBTask_TimePublish(XENGINE_DBTIMERELEASE* pSt_DBInfo, DBModule_MQUser_TimeUPDate(pSt_DBInfo); } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("定时任务,消息主题:%s,序列:%lld,定时任务分发成功,客户端个数:%d"), pSt_DBInfo->tszQueueName, pSt_DBInfo->nIDMsg, nListCount); +} +void CALLBACK MessageQueue_CBTask_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE enMemoryType, bool bSuccess, size_t nListCount, XENGINE_DBMESSAGEQUEUE* pSt_DBInfo, XPVOID lParam) +{ + if (ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_QUERY == enMemoryType) + { + if (bSuccess) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("高速缓存,消息主题:%s,序列:%lld,删除过期缓存成功,缓存剩余队列:%ld"), pSt_DBInfo->tszQueueName, pSt_DBInfo->nQueueSerial, nListCount); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("高速缓存,消息主题:%s,序列:%lld,删除过期缓存成功,缓存剩余队列:%ld"), pSt_DBInfo->tszQueueName, pSt_DBInfo->nQueueSerial, nListCount); + } + } + else if (ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_INSERT == enMemoryType) + { + if (bSuccess) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("高速缓存,消息主题:%s,序列:%lld,插入缓存队列到数据库成功,缓存剩余队列:%ld"), pSt_DBInfo->tszQueueName, pSt_DBInfo->nQueueSerial, nListCount); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("高速缓存,消息主题:%s,序列:%lld,插入缓存队列到数据库失败,缓存剩余队列:%ld"), pSt_DBInfo->tszQueueName, pSt_DBInfo->nQueueSerial, nListCount); + } + } } \ No newline at end of file diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_Task.h b/XEngine_Source/XEngine_MQServiceApp/MQService_Task.h index 2c29218..b92c117 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_Task.h +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_Task.h @@ -1,3 +1,4 @@ #pragma once -void CALLBACK MessageQueue_CBTask_TimePublish(XENGINE_DBTIMERELEASE* pSt_DBInfo, XPVOID lParam); \ No newline at end of file +void CALLBACK MessageQueue_CBTask_TimePublish(XENGINE_DBTIMERELEASE* pSt_DBInfo, XPVOID lParam); +void CALLBACK MessageQueue_CBTask_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE enMemoryType, bool bSuccess, size_t nListCount, XENGINE_DBMESSAGEQUEUE* pSt_DBInfo, XPVOID lParam); \ No newline at end of file diff --git a/XEngine_Source/XEngine_MQServiceApp/Makefile b/XEngine_Source/XEngine_MQServiceApp/Makefile index cfa2922..21f212f 100644 --- a/XEngine_Source/XEngine_MQServiceApp/Makefile +++ b/XEngine_Source/XEngine_MQServiceApp/Makefile @@ -4,10 +4,10 @@ PLATVER = PLATDIR = RELEASE = 0 LOADHDR = -I ./ -LOADSO = -L ../MQCore_ConfigModule -L ../MQCore_ProtocolModule -L ../MQCore_SessionModule -L ../MQCore_DBModule \ +LOADSO = -L ../MQCore_ConfigModule -L ../MQCore_ProtocolModule -L ../MQCore_SessionModule -L ../MQCore_MemoryCache -L ../MQCore_DBModule \ -L ../XEngine_Depend/XEngine_Module/jsoncpp -L ../XEngine_Depend/XEngine_Module/XEngine_InfoReport LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lXClient_APIHelp -lXEngine_SystemApi -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_WSProtocol -lRfcComponents_HttpProtocol -lRfcComponents_MQTTProtocol \ - -lMQCore_ConfigModule -lMQCore_ProtocolModule -lMQCore_SessionModule -lMQCore_DBModule \ + -lMQCore_ConfigModule -lMQCore_ProtocolModule -lMQCore_SessionModule -lMQCore_MemoryCache -lMQCore_DBModule \ -ljsoncpp -lXEngine_InfoReport LIBEX = OBJECTS = MQService_Net.o MQService_Config.o MQService_TCPTask.o MQService_HttpTask.o MQService_WSTask.o MQService_Task.o MQService_MQTTTask.o XEngine_MQServiceApp.o diff --git a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp index 64fd830..d5a0f4b 100644 --- a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp @@ -44,6 +44,7 @@ void ServiceApp_Stop(int signo) DBModule_MQData_Destory(); DBModule_MQUser_Destory(); + MemoryCache_DBData_Destory(); SessionModule_Client_Destory(); HelpComponents_XLog_Destroy(xhLog); @@ -84,12 +85,37 @@ static int ServiceApp_Deamon(int wait) #endif return 0; } +#ifdef _MSC_BUILD +LONG WINAPI Coredump_ExceptionFilter(EXCEPTION_POINTERS* pExceptionPointers) +{ + static int i = 0; + XCHAR tszFileStr[MAX_PATH] = {}; + XCHAR tszTimeStr[128] = {}; + BaseLib_OperatorTime_TimeToStr(tszTimeStr); + _xstprintf(tszFileStr, _X("./XEngine_Coredump/dumpfile_%s_%d.dmp"), tszTimeStr, i++); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_FATAL, _X("主程序:软件崩溃,写入dump:%s"), tszFileStr); + HANDLE hDumpFile = CreateFileA(tszFileStr, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (INVALID_HANDLE_VALUE != hDumpFile) + { + MINIDUMP_EXCEPTION_INFORMATION st_DumpInfo = {}; + st_DumpInfo.ExceptionPointers = pExceptionPointers; + st_DumpInfo.ThreadId = GetCurrentThreadId(); + st_DumpInfo.ClientPointers = TRUE; + // 写入 dump 文件 + MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpNormal, &st_DumpInfo, NULL, NULL); + CloseHandle(hDumpFile); + } + return EXCEPTION_EXECUTE_HANDLER; +} +#endif int main(int argc, char** argv) { #ifdef _WINDOWS WSADATA st_WSAData; WSAStartup(MAKEWORD(2, 2), &st_WSAData); + + SetUnhandledExceptionFilter(Coredump_ExceptionFilter); #endif int nRet = -1; LPCXSTR lpszHTTPMime = _X("./XEngine_Config/HttpMime.types"); @@ -140,9 +166,23 @@ int main(int argc, char** argv) signal(SIGABRT, ServiceApp_Stop); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化服务器信号管理成功")); + if (st_ServiceCfg.st_XMemory.bDataQueryEnable || st_ServiceCfg.st_XMemory.bDataInsertEnable) + { + if (!MemoryCache_DBData_Init(st_ServiceCfg.st_XMemory.nTimeLast, st_ServiceCfg.st_XMemory.nTimeStart, MessageQueue_CBTask_MemoryCache)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化高速缓存服务失败,错误:%lX"), MemoryCache_GetLastError()); + goto NETSERVICEEXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化高速缓存服务成功,更新最大时间:%d,存储最大时间:%d"), st_ServiceCfg.st_XMemory.nTimeLast, st_ServiceCfg.st_XMemory.nTimeStart); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,检测到没有启用高速缓存服务"), st_ServiceCfg.st_XMemory.nTimeLast, st_ServiceCfg.st_XMemory.nTimeStart); + } + if (!bIsTest) { - if (!DBModule_MQData_Init((DATABASE_MYSQL_CONNECTINFO*)&st_ServiceCfg.st_XSql)) + if (!DBModule_MQData_Init((DATABASE_MYSQL_CONNECTINFO*)&st_ServiceCfg.st_XSql, st_ServiceCfg.st_XMemory.bDataQueryEnable, st_ServiceCfg.st_XMemory.bDataInsertEnable)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化消息数据数据库失败,错误:%lX"), DBModule_GetLastError()); goto NETSERVICEEXIT; @@ -356,7 +396,7 @@ int main(int argc, char** argv) XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("所有服务成功启动,服务运行中,XEngine版本:%s%s,发行版本次数:%d,当前运行版本:%s。。。"), BaseLib_OperatorVer_XNumberStr(), BaseLib_OperatorVer_XTypeStr(), st_ServiceCfg.st_XVer.pStl_ListStorage->size(), st_ServiceCfg.st_XVer.pStl_ListStorage->front().c_str()); - while (bIsRun) + while (true) { if (bIsTest) { @@ -394,6 +434,7 @@ int main(int argc, char** argv) DBModule_MQData_Destory(); DBModule_MQUser_Destory(); + MemoryCache_DBData_Destory(); SessionModule_Client_Destory(); HelpComponents_XLog_Destroy(xhLog);