Skip to content

Commit 7e64d41

Browse files
committed
added:topic owner for db
1 parent 961534f commit 7e64d41

File tree

7 files changed

+240
-7
lines changed

7 files changed

+240
-7
lines changed

XEngine_Source/MQCore_DBModule/DBModule_Define.h

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ typedef struct
4646
TCHAR tszCreateTime[64]; //创建的时间
4747
__int64x nKeySerial; //包序列号
4848
}XENGINE_DBUSERKEY;
49+
//主题所有者
50+
typedef struct
51+
{
52+
TCHAR tszQueueName[256]; //主题名称
53+
TCHAR tszUserName[256]; //主题所有者
54+
}XENGINE_DBTOPICOWNER;
4955
//////////////////////////////////////////////////////////////////////////
5056
// 导出的函数
5157
//////////////////////////////////////////////////////////////////////////
@@ -466,4 +472,49 @@ extern "C" BOOL DBModule_MQUser_TimeDelete(XENGINE_DBTIMERELEASE * pSt_DBInfo);
466472
意思:是否成功
467473
备注:
468474
*********************************************************************/
469-
extern "C" BOOL DBModule_MQUser_TimeClaer(time_t nTime = 0);
475+
extern "C" BOOL DBModule_MQUser_TimeClaer(time_t nTime = 0);
476+
/*************************************************************************
477+
主题所有者导出函数
478+
**************************************************************************/
479+
/********************************************************************
480+
函数名称:DBModule_MQUser_OwnerInsert
481+
函数功能:主题所有者插入
482+
参数.一:pSt_DBOwner
483+
In/Out:In
484+
类型:数据结构指针
485+
可空:N
486+
意思:要操作的数据
487+
返回值
488+
类型:逻辑型
489+
意思:是否成功
490+
备注:
491+
*********************************************************************/
492+
extern "C" BOOL DBModule_MQUser_OwnerInsert(XENGINE_DBTOPICOWNER* pSt_DBOwner);
493+
/********************************************************************
494+
函数名称:DBModule_MQUser_OwnerDelete
495+
函数功能:主题所有者删除
496+
参数.一:pSt_DBOwner
497+
In/Out:In
498+
类型:数据结构指针
499+
可空:N
500+
意思:要操作的数据
501+
返回值
502+
类型:逻辑型
503+
意思:是否成功
504+
备注:
505+
*********************************************************************/
506+
extern "C" BOOL DBModule_MQUser_OwnerDelete(XENGINE_DBTOPICOWNER* pSt_DBOwner);
507+
/********************************************************************
508+
函数名称:DBModule_MQUser_OwnerQuery
509+
函数功能:主题所有者查询
510+
参数.一:pSt_DBOwner
511+
In/Out:In
512+
类型:数据结构指针
513+
可空:N
514+
意思:要操作的数据
515+
返回值
516+
类型:逻辑型
517+
意思:是否成功
518+
备注:
519+
*********************************************************************/
520+
extern "C" BOOL DBModule_MQUser_OwnerQuery(XENGINE_DBTOPICOWNER* pSt_DBOwner);

XEngine_Source/MQCore_DBModule/DBModule_Error.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
#define ERROR_XENGINE_MQCORE_DATABASE_PARAMENT 0xF0001 //参数错误
1717
#define ERROR_XENGINE_MQCORE_DATABASE_EMPTY 0xF0002 //数据为空
1818
#define ERROR_XENGINE_MQCORE_DATABASE_EXIST 0xF0003 //数据存在
19-
#define ERROR_XENGINE_MQCORE_DATABASE_CREATETHREAD 0xF0004 //创建线程失败
19+
#define ERROR_XENGINE_MQCORE_DATABASE_CREATETHREAD 0xF0004 //创建线程失败
20+
#define ERROR_XENGINE_MQCORE_DATABASE_NOTFOUND 0xF0005 //没有找到

XEngine_Source/MQCore_DBModule/DBModule_MQUser/DBModule_MQUser.cpp

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,125 @@ BOOL CDBModule_MQUser::DBModule_MQUser_TimeClaer(time_t nTime /* = 0 */)
738738
}
739739
return TRUE;
740740
}
741+
/********************************************************************
742+
函数名称:DBModule_MQUser_OwnerInsert
743+
函数功能:主题所有者插入
744+
参数.一:pSt_DBOwner
745+
In/Out:In
746+
类型:数据结构指针
747+
可空:N
748+
意思:要操作的数据
749+
返回值
750+
类型:逻辑型
751+
意思:是否成功
752+
备注:
753+
*********************************************************************/
754+
BOOL CDBModule_MQUser::DBModule_MQUser_OwnerInsert(XENGINE_DBTOPICOWNER* pSt_DBOwner)
755+
{
756+
DBModule_IsErrorOccur = FALSE;
757+
758+
if (NULL == pSt_DBOwner)
759+
{
760+
DBModule_IsErrorOccur = TRUE;
761+
DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_PARAMENT;
762+
return FALSE;
763+
}
764+
TCHAR tszSQLStatement[10240];
765+
memset(tszSQLStatement, '\0', sizeof(tszSQLStatement));
766+
767+
_stprintf(tszSQLStatement, _T("INSERT IGNORE INTO `KeyOwner` (tszUserName,tszKeyName) VALUES('%s','%s')"), pSt_DBOwner->tszUserName, pSt_DBOwner->tszQueueName);
768+
if (!DataBase_MySQL_Execute(xhDBSQL, tszSQLStatement))
769+
{
770+
DBModule_IsErrorOccur = TRUE;
771+
DBModule_dwErrorCode = DataBase_GetLastError();
772+
return FALSE;
773+
}
774+
return TRUE;
775+
}
776+
/********************************************************************
777+
函数名称:DBModule_MQUser_OwnerDelete
778+
函数功能:主题所有者删除
779+
参数.一:pSt_DBOwner
780+
In/Out:In
781+
类型:数据结构指针
782+
可空:N
783+
意思:要操作的数据
784+
返回值
785+
类型:逻辑型
786+
意思:是否成功
787+
备注:
788+
*********************************************************************/
789+
BOOL CDBModule_MQUser::DBModule_MQUser_OwnerDelete(XENGINE_DBTOPICOWNER* pSt_DBOwner)
790+
{
791+
DBModule_IsErrorOccur = FALSE;
792+
793+
if (NULL == pSt_DBOwner)
794+
{
795+
DBModule_IsErrorOccur = TRUE;
796+
DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_PARAMENT;
797+
return FALSE;
798+
}
799+
__int64u nAffectRow = 0;
800+
TCHAR tszSQLStatement[10240];
801+
memset(tszSQLStatement, '\0', sizeof(tszSQLStatement));
802+
803+
_stprintf(tszSQLStatement, _T("DELETE FROM `KeyOwner` WHERE tszUserName = '%s' AND tszKeyName = '%s'"), pSt_DBOwner->tszUserName, pSt_DBOwner->tszQueueName);
804+
if (!DataBase_MySQL_Execute(xhDBSQL, tszSQLStatement, &nAffectRow))
805+
{
806+
DBModule_IsErrorOccur = TRUE;
807+
DBModule_dwErrorCode = DataBase_GetLastError();
808+
return FALSE;
809+
}
810+
if (nAffectRow <= 0)
811+
{
812+
DBModule_IsErrorOccur = TRUE;
813+
DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_NOTFOUND;
814+
return FALSE;
815+
}
816+
return TRUE;
817+
}
818+
/********************************************************************
819+
函数名称:DBModule_MQUser_OwnerQuery
820+
函数功能:主题所有者查询
821+
参数.一:pSt_DBOwner
822+
In/Out:In
823+
类型:数据结构指针
824+
可空:N
825+
意思:要操作的数据
826+
返回值
827+
类型:逻辑型
828+
意思:是否成功
829+
备注:
830+
*********************************************************************/
831+
BOOL CDBModule_MQUser::DBModule_MQUser_OwnerQuery(XENGINE_DBTOPICOWNER* pSt_DBOwner)
832+
{
833+
DBModule_IsErrorOccur = FALSE;
834+
835+
//查询
836+
XNETHANDLE xhTable = 0;
837+
__int64u nllLine = 0;
838+
__int64u nllRow = 0;
839+
TCHAR tszSQLStatement[1024];
840+
841+
memset(tszSQLStatement, '\0', sizeof(tszSQLStatement));
842+
843+
_stprintf(tszSQLStatement, _T("SELECT * FROM `KeyOwner` WHERE tszUserName = '%s' AND tszKeyName = '%s'"), pSt_DBOwner->tszUserName, pSt_DBOwner->tszQueueName);
844+
845+
if (!DataBase_MySQL_ExecuteQuery(xhDBSQL, &xhTable, tszSQLStatement, &nllLine, &nllRow))
846+
{
847+
DBModule_IsErrorOccur = TRUE;
848+
DBModule_dwErrorCode = DataBase_GetLastError();
849+
return FALSE;
850+
}
851+
DataBase_MySQL_FreeResult(xhDBSQL, xhTable);
852+
if (nllLine <= 0)
853+
{
854+
DBModule_IsErrorOccur = TRUE;
855+
DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_EMPTY;
856+
return FALSE;
857+
}
858+
return TRUE;
859+
}
741860
//////////////////////////////////////////////////////////////////////////
742861
// 线程函数
743862
//////////////////////////////////////////////////////////////////////////

XEngine_Source/MQCore_DBModule/DBModule_MQUser/DBModule_MQUser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class CDBModule_MQUser
3434
BOOL DBModule_MQUser_TimeQuery(XENGINE_DBTIMERELEASE*** pppSt_DBInfo, int* pInt_ListCount);
3535
BOOL DBModule_MQUser_TimeDelete(XENGINE_DBTIMERELEASE* pSt_DBInfo);
3636
BOOL DBModule_MQUser_TimeClaer(time_t nTime = 0);
37+
public:
38+
BOOL DBModule_MQUser_OwnerInsert(XENGINE_DBTOPICOWNER* pSt_DBOwner);
39+
BOOL DBModule_MQUser_OwnerDelete(XENGINE_DBTOPICOWNER* pSt_DBOwner);
40+
BOOL DBModule_MQUser_OwnerQuery(XENGINE_DBTOPICOWNER* pSt_DBOwner);
3741
protected:
3842
static XHTHREAD CALLBACK DBModule_MQUser_TimeThread(LPVOID lParam);
3943
private:

XEngine_Source/MQCore_DBModule/MQCore_DBModule.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@ EXPORTS
3030
DBModule_MQUser_TimeInsert
3131
DBModule_MQUser_TimeQuery
3232
DBModule_MQUser_TimeDelete
33-
DBModule_MQUser_TimeClaer
33+
DBModule_MQUser_TimeClaer
34+
35+
DBModule_MQUser_OwnerInsert
36+
DBModule_MQUser_OwnerDelete
37+
DBModule_MQUser_OwnerQuery

XEngine_Source/MQCore_DBModule/pch.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,19 @@ extern "C" BOOL DBModule_MQUser_TimeDelete(XENGINE_DBTIMERELEASE * pSt_DBInfo)
139139
extern "C" BOOL DBModule_MQUser_TimeClaer(time_t nTime)
140140
{
141141
return m_DBUser.DBModule_MQUser_TimeClaer(nTime);
142+
}
143+
/*************************************************************************
144+
主题所有者导出函数
145+
**************************************************************************/
146+
extern "C" BOOL DBModule_MQUser_OwnerInsert(XENGINE_DBTOPICOWNER * pSt_DBOwner)
147+
{
148+
return m_DBUser.DBModule_MQUser_OwnerInsert(pSt_DBOwner);
149+
}
150+
extern "C" BOOL DBModule_MQUser_OwnerDelete(XENGINE_DBTOPICOWNER * pSt_DBOwner)
151+
{
152+
return m_DBUser.DBModule_MQUser_OwnerDelete(pSt_DBOwner);
153+
}
154+
extern "C" BOOL DBModule_MQUser_OwnerQuery(XENGINE_DBTOPICOWNER * pSt_DBOwner)
155+
{
156+
return m_DBUser.DBModule_MQUser_OwnerQuery(pSt_DBOwner);
142157
}

XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ BOOL MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCTSTR lpszC
476476
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQCREATE == pSt_ProtocolHdr->unOperatorCode)
477477
{
478478
pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPCREATE;
479+
//创建表
479480
if (!DBModule_MQData_CreateTable(st_MQProtocol.tszMQKey))
480481
{
481482
if (pSt_ProtocolHdr->byIsReply || (XENGINE_MQAPP_NETTYPE_HTTP == nNetType))
@@ -484,10 +485,30 @@ BOOL MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCTSTR lpszC
484485
ProtocolModule_Packet_Common(nNetType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
485486
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, nNetType);
486487
}
487-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("%s消息端:%s,创建主题失败,主题名称:%s,无法继续,错误:%lX"), lpszClientType, lpszClientAddr, st_MQProtocol.tszMQKey, DBModule_GetLastError());
488+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("%s消息端:%s,创建主题失败,创建表失败,主题名称:%s,无法继续,错误:%lX"), lpszClientType, lpszClientAddr, st_MQProtocol.tszMQKey, DBModule_GetLastError());
488489
return FALSE;
489490
}
491+
//插入所有者
492+
XENGINE_DBTOPICOWNER st_DBOwner;
493+
memset(&st_DBOwner, '\0', sizeof(XENGINE_DBTOPICOWNER));
494+
495+
_tcscpy(st_DBOwner.tszUserName, tszUserName);
496+
_tcscpy(st_DBOwner.tszQueueName, st_MQProtocol.tszMQKey);
497+
498+
if (!DBModule_MQUser_OwnerInsert(&st_DBOwner))
499+
{
500+
if (pSt_ProtocolHdr->byIsReply || (XENGINE_MQAPP_NETTYPE_HTTP == nNetType))
501+
{
502+
pSt_ProtocolHdr->wReserve = 762;
503+
ProtocolModule_Packet_Common(nNetType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
504+
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, nNetType);
505+
}
506+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("%s消息端:%s,创建主题失败,插入所有者失败,主题名称:%s,无法继续,错误:%lX"), lpszClientType, lpszClientAddr, st_MQProtocol.tszMQKey, DBModule_GetLastError());
507+
return FALSE;
508+
}
509+
//创建通知
490510
SessionModule_Notify_Create(st_MQProtocol.tszMQKey);
511+
//回复
491512
if (pSt_ProtocolHdr->byIsReply || (XENGINE_MQAPP_NETTYPE_HTTP == nNetType))
492513
{
493514
pSt_ProtocolHdr->wReserve = 0;
@@ -499,15 +520,33 @@ BOOL MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCTSTR lpszC
499520
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQDELETE == pSt_ProtocolHdr->unOperatorCode)
500521
{
501522
pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPDELETE;
502-
523+
//清理所有者
524+
XENGINE_DBTOPICOWNER st_DBOwner;
525+
memset(&st_DBOwner, '\0', sizeof(XENGINE_DBTOPICOWNER));
526+
527+
_tcscpy(st_DBOwner.tszUserName, tszUserName);
528+
_tcscpy(st_DBOwner.tszQueueName, st_MQProtocol.tszMQKey);
529+
530+
if (!DBModule_MQUser_OwnerDelete(&st_DBOwner))
531+
{
532+
if (pSt_ProtocolHdr->byIsReply || (XENGINE_MQAPP_NETTYPE_HTTP == nNetType))
533+
{
534+
pSt_ProtocolHdr->wReserve = 0;
535+
ProtocolModule_Packet_Common(nNetType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
536+
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, nNetType);
537+
}
538+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("%s消息端:%s,删除主题失败,删除所有者失败,主题名称:%s,无法继续,错误:%lX"), lpszClientType, lpszClientAddr, st_MQProtocol.tszMQKey, DBModule_GetLastError());
539+
return FALSE;
540+
}
541+
//清楚数据库
542+
SessionModule_Notify_Destory(st_MQProtocol.tszMQKey);
543+
DBModule_MQData_DeleteTable(st_MQProtocol.tszMQKey);
503544
if (pSt_ProtocolHdr->byIsReply || (XENGINE_MQAPP_NETTYPE_HTTP == nNetType))
504545
{
505546
pSt_ProtocolHdr->wReserve = 0;
506547
ProtocolModule_Packet_Common(nNetType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen);
507548
XEngine_MQXService_Send(lpszClientAddr, tszSDBuffer, nSDLen, nNetType);
508549
}
509-
DBModule_MQData_DeleteTable(st_MQProtocol.tszMQKey);
510-
SessionModule_Notify_Destory(st_MQProtocol.tszMQKey);
511550
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("%s消息端:%s,主题:%s,删除主题成功"), lpszClientType, lpszClientAddr, st_MQProtocol.tszMQKey);
512551
}
513552
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REQNOTIFY == pSt_ProtocolHdr->unOperatorCode)

0 commit comments

Comments
 (0)