Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery.common.cpp
/
Microservice
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bc887b8e
authored
Mar 29, 2017
by
amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
first version of mongoose free
parent
e3d315e5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
73 additions
and
147 deletions
CMakeLists.txt
src/Microservice_App.cpp
src/common/Microservice_Iface.h
src/handlers/Microservice_RMQHandler.cpp
src/handlers/Microservice_RestHandler.cpp
src/handlers/Microservice_RestHandler.h
src/impl/Microservice_IRequestRestImpl.cpp
src/impl/Microservice_IRequestRestImpl.h
src/impl/Microservice_IResponseRestImpl.cpp
src/impl/servers/Microservice_IRestServerMongooseImpl.cpp → src/impl/servers/Microservice_IRestServerCivetWebImpl.cpp
src/impl/servers/Microservice_IRestServerMongooseImpl.h → src/impl/servers/Microservice_IRestServerCivetWebImpl.h
src/utils/CommonUtils.h
src/utils/ServerFactory.cpp
src/utils/ServerFactory.h
test/Microservice_ClientTest.cpp
test/Microservice_Test.cpp
CMakeLists.txt
View file @
bc887b8e
...
@@ -28,17 +28,18 @@ include_directories(SYSTEM ../3party/cereal-1.2.1/include)
...
@@ -28,17 +28,18 @@ include_directories(SYSTEM ../3party/cereal-1.2.1/include)
include_directories
(
SYSTEM ../3party/rapidjson-cereal-1.2.1
)
include_directories
(
SYSTEM ../3party/rapidjson-cereal-1.2.1
)
#include_directories(SYSTEM ../3party/rapidjson-0.11/include/rapidjson)
#include_directories(SYSTEM ../3party/rapidjson-0.11/include/rapidjson)
include_directories
(
SYSTEM ../3party/cppmetrics-0.1.1-Linux/include
)
include_directories
(
SYSTEM ../3party/cppmetrics-0.1.1-Linux/include
)
include_directories
(
SYSTEM ../3party/
mongoos
e
)
include_directories
(
SYSTEM ../3party/
civetweb/includ
e
)
include_directories
(
SYSTEM ../3party/cpprest/Release/include
)
include_directories
(
SYSTEM ../3party/cpprest/Release/include
)
include_directories
(
SYSTEM ../3party/rabbitmq
)
include_directories
(
SYSTEM ../3party/rabbitmq
)
include_directories
(
SYSTEM ../internals/include/Rabbitmq
)
include_directories
(
SYSTEM ../internals/include/Rabbitmq
)
include_directories
(
SYSTEM /usr/include/hiredis
)
include_directories
(
SYSTEM /usr/include/hiredis
)
# recursive search files cpp files
# recursive search files cpp files
file
(
GLOB_RECURSE SOURCES
"src/*.cpp"
)
file
(
GLOB_RECURSE SOURCES
"src/*.cpp"
src/Microservice_BaseRestResponse.h src/common/Microservice_RestResponse.h src/common/Microservice_MsgQContext.h src/handlers/Microservice_Reactor.cpp src/handlers/Microservice_Reactor.h src/common/Microservice_PubSubContext.h src/handlers/Microservice_MsgQHandler.h src/handlers/Microservice_PubSubHandler.h src/impl/servers/Microservice_IMsgQueueServerZmqImpl.cpp src/impl/servers/Microservice_IMsgQueueServerZmqImpl.h src/impl/Microservice_IMsgArchiverCerealImpls.h src/utils/ServerFactory.cpp src/utils/ServerFactory.h src/utils/ClientFactory.cpp src/utils/ClientFactory.h src/impl/clients/MSZMQClientImpl.cpp src/impl/clients/MSZMQClientImpl.h src/impl/clients/MSIPubSubClientImpl.cpp src/impl/clients/MSIPubSubClientImpl.h
)
set
(
3PARTY_SOURCES ../3party/mongoose/mongoose.c
)
set
(
3PARTY_SOURCES ../3party/civetweb/src/civetweb.c ../3party/civetweb/src/CivetServer.cpp ../3party/civetweb/src/md5.inl ../3party/civetweb/src/handle_form.inl
)
#Generate the shared library from the sources
#Generate the shared library from the sources
add_library
(
Microservice SHARED
${
SOURCES
}
${
3PARTY_SOURCES
}
src/common/Microservice_RestResponse.h src/common/Microservice_MsgQContext.h src/handlers/Microservice_Reactor.cpp src/handlers/Microservice_Reactor.h src/common/Microservice_PubSubContext.h src/handlers/Microservice_MsgQHandler.h src/handlers/Microservice_PubSubHandler.h src/impl/servers/Microservice_IMsgQueueServerZmqImpl.cpp src/impl/servers/Microservice_IMsgQueueServerZmqImpl.h src/impl/Microservice_IMsgArchiverCerealImpls.h src/utils/ServerFactory.cpp src/utils/ServerFactory.h src/utils/ClientFactory.cpp src/utils/ClientFactory.h src/impl/clients/MSZMQClientImpl.cpp src/impl/clients/MSZMQClientImpl.h src/impl/clients/MSIPubSubClientImpl.cpp src/impl/clients/MSIPubSubClientImpl.h
)
add_library
(
Microservice SHARED
${
SOURCES
}
${
3PARTY_SOURCES
}
)
target_link_libraries
(
Microservice
${
PROJECT_LINK_LIBS
}
)
target_link_libraries
(
Microservice
${
PROJECT_LINK_LIBS
}
)
set_target_properties
(
Microservice PROPERTIES VERSION
${
Microservice_VERSION_STRING
}
set_target_properties
(
Microservice PROPERTIES VERSION
${
Microservice_VERSION_STRING
}
SOVERSION
${
Microservice_VERSION_MAJOR
}
)
SOVERSION
${
Microservice_VERSION_MAJOR
}
)
...
...
src/Microservice_App.cpp
View file @
bc887b8e
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
#include <Microservice_App.h>
#include <Microservice_App.h>
#include <params/Microservice_Params.h>
#include <params/Microservice_Params.h>
#include <handlers/Microservice_BaseHandler.h>
#include <handlers/Microservice_BaseHandler.h>
#include <handlers/Microservice_RestHandler.h>
#include <handlers/Microservice_MonitorHandler.h>
#include <handlers/Microservice_MonitorHandler.h>
#include <algorithm>
#include <algorithm>
#include <Microservice_Client.h>
#include <Microservice_Client.h>
...
...
src/common/Microservice_Iface.h
View file @
bc887b8e
...
@@ -273,8 +273,6 @@ namespace nsMicroservice_Iface
...
@@ -273,8 +273,6 @@ namespace nsMicroservice_Iface
ILogger
*
pc_Logger
,
ILogger
*
pc_Logger
,
IPubSub
*
pc_PubSub
,
IPubSub
*
pc_PubSub
,
IMetricsFactory
*
p_metrics_factory
)
=
0
;
IMetricsFactory
*
p_metrics_factory
)
=
0
;
// virtual void run() = 0;
// virtual void stop() = 0;
virtual
void
registerService
(
IServiceDiscovery
*
pc_ServiceDiscovery
,
std
::
string
&
id
)
=
0
;
virtual
void
registerService
(
IServiceDiscovery
*
pc_ServiceDiscovery
,
std
::
string
&
id
)
=
0
;
virtual
const
char
*
getType
()
final
{
return
TYPE
;
}
virtual
const
char
*
getType
()
final
{
return
TYPE
;
}
};
};
...
...
src/handlers/Microservice_RMQHandler.cpp
View file @
bc887b8e
...
@@ -10,7 +10,8 @@
...
@@ -10,7 +10,8 @@
#include <stringbuffer.h>
#include <stringbuffer.h>
#include <map>
#include <map>
#include <deque>
#include <deque>
#include <mongoose.h>
//#include <mongoose.h>
#include <civetweb.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stringbuffer.h> //rapidjson string
#include <stringbuffer.h> //rapidjson string
...
...
src/handlers/Microservice_RestHandler.cpp
deleted
100644 → 0
View file @
e3d315e5
This diff is collapsed.
Click to expand it.
src/handlers/Microservice_RestHandler.h
deleted
100644 → 0
View file @
e3d315e5
/*
* Microservice_RestHandler.h
*
* Created on: Mar 23, 2015
* Author: amir
*/
#ifndef MICROSERVICE_RESTHANDLER_H_
#define MICROSERVICE_RESTHANDLER_H_
#include <common/Microservice_Defines.h>
#include <common/Microservice_Iface.h>
#include <stddef.h>
#include <writer.h>
#include <stringbuffer.h>
#include <handlers/Microservice_BaseHandler.h>
#include <Microservice_BaseRestResponse.h>
struct
mg_connection
;
struct
http_message
;
class
cMicroservice_RequestContext
;
class
cMicroservice_RestHandler
:
public
nsMicroservice_Iface
::
IContainer
{
private
:
JsonStringWriter
*
mpc_Writer
;
rapidjson
::
StringBuffer
*
mpc_Buffer
;
std
::
string
apiContextPath
;
cMicroservice_BaseHandler
*
mpc_Handler
;
nsMicroservice_Iface
::
ILogger
*
mpc_Logger
;
nsMicroservice_Iface
::
IPubSub
*
mpc_PubSub
;
std
::
map
<
std
::
string
,
cMicroservice_Enums
::
eCrudMethod
>
crudMethodMap_
;
cMicroservice_RequestContext
*
mpc_RequestContext
;
char
mba_Buff
[
nsMicroservice_Constants
::
MAX_URI_LENGTH
];
char
mba_ErrorBuff
[
nsMicroservice_Constants
::
MAX_ERROR_BUFF_URI_LENGTH
];
nsMicroservice_Iface
::
IMetricsFactory
*
p_metrics_factory_
;
// metrics
nsMicroservice_Iface
::
IMetricsFactory
::
IMeter
*
p_get_meter_
;
nsMicroservice_Iface
::
IMetricsFactory
::
IMeter
*
p_post_meter_
;
nsMicroservice_Iface
::
IMetricsFactory
::
IMeter
*
p_put_meter_
;
nsMicroservice_Iface
::
IMetricsFactory
::
IMeter
*
p_delete_meter_
;
nsMicroservice_Iface
::
IMetricsFactory
::
ITimer
*
p_get_timer_
;
nsMicroservice_Iface
::
IMetricsFactory
::
ITimer
*
p_post_timer_
;
cMicroservice_Enums
::
eMethod
GetMethod
(
http_message
*
msg
);
// inlines
void
DoGet
(
cMicroservice_RequestContext
*
pc_ReqCtx
)
{
mpc_Handler
->
DoRead
(
pc_ReqCtx
);
}
void
DoPost
(
cMicroservice_RequestContext
*
pc_ReqCtx
){
mpc_Handler
->
DoCreate
(
pc_ReqCtx
);
}
void
DoPut
(
cMicroservice_RequestContext
*
pc_ReqCtx
)
{
mpc_Handler
->
DoUpdate
(
pc_ReqCtx
);
}
void
DoDelete
(
cMicroservice_RequestContext
*
pc_ReqCtx
){
mpc_Handler
->
DoDelete
(
pc_ReqCtx
);
}
/**
* prepare the request context
* @param mg_connection
* @return
*/
void
SetRequestContext
(
mg_connection
*
conn
,
http_message
*
msg
);
void
GetQueryParams
(
http_message
*
msg
);
void
LogRequest
(
http_message
*
msg
);
void
CreateMetrics
();
void
PreHandleMetrics
(
cMicroservice_Enums
::
eMethod
e_Method
);
void
PostHandleMetrics
(
cMicroservice_Enums
::
eMethod
e_Method
);
public
:
cMicroservice_RestHandler
(
std
::
string
apiContextPath
,
cMicroservice_BaseHandler
*
pc_Handler
);
void
withMetrics
(
nsMicroservice_Iface
::
IMetricsFactory
*
p_metrics_factory
)
{
this
->
p_metrics_factory_
=
p_metrics_factory
;
CreateMetrics
();
}
void
withLogger
(
nsMicroservice_Iface
::
ILogger
*
pc_Logger
)
{
this
->
mpc_Logger
=
pc_Logger
;
}
void
withPubSub
(
nsMicroservice_Iface
::
IPubSub
*
pc_PubSub
)
{
this
->
mpc_PubSub
=
pc_PubSub
;
}
void
HandleRequest
(
mg_connection
*
conn
,
http_message
*
msg
);
void
SendErrorResp
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
std
::
string
error
);
void
WriteObjectToResponse
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
rapidjson
::
Document
&
t_ObjectDoc
);
void
WriteObjectToResponse
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
cMicroservice_BaseRestResponse
&
t_BaseRestResponse
);
void
WriteStringToResponse
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
const
char
*
pba_Doc
);
bool
ReadObjectFromRequest
(
nsMicroservice_Iface
::
IRequest
*
pti_Request
,
rapidjson
::
Document
&
t_ObjectDoc
);
// void Publish(std::string& t_Topic, std::string& t_Message) {}
// void Subscribe(std::string& t_Topic, nsMicroservice_Iface::INotifyCallback& t_NotifyHandler) {}
// void Unsubscribe(std::string& t_Topic) {}
eCrudMethod
GetCrudMethod
(
http_message
*
pMessage
);
};
#endif
/* MICROSERVICE_RESTHANDLER_H_ */
src/impl/Microservice_IRequestRestImpl.cpp
View file @
bc887b8e
...
@@ -6,12 +6,13 @@
...
@@ -6,12 +6,13 @@
*/
*/
#include <impl/Microservice_IRequestRestImpl.h>
#include <impl/Microservice_IRequestRestImpl.h>
#include <mongoose.h>
//#include <mongoose.h>
#include <civetweb.h>
#include <stdlib.h>
#include <stdlib.h>
cMicroservice_IRequestRestImpl
::
cMicroservice_IRequestRestImpl
()
:
cMicroservice_IRequestRestImpl
::
cMicroservice_IRequestRestImpl
()
:
mpt_MgMsg
(
nullptr
),
mba_BodyBuffer
(
nullptr
)
p_reqInfo_
(
nullptr
),
mba_BodyBuffer
(
nullptr
)
{
{
// TODO Auto-generated constructor stub
// TODO Auto-generated constructor stub
...
@@ -24,39 +25,36 @@ cMicroservice_IRequestRestImpl::~cMicroservice_IRequestRestImpl() {
...
@@ -24,39 +25,36 @@ cMicroservice_IRequestRestImpl::~cMicroservice_IRequestRestImpl() {
}
}
void
cMicroservice_IRequestRestImpl
::
Reset
()
{
void
cMicroservice_IRequestRestImpl
::
Reset
()
{
mpt_MgMsg
=
nullptr
;
p_reqInfo_
=
nullptr
;
}
}
const
char
*
cMicroservice_IRequestRestImpl
::
GetQueryString
()
const
char
*
cMicroservice_IRequestRestImpl
::
GetQueryString
()
{
{
if
(
mpt_MgMsg
)
if
(
p_reqInfo_
)
return
mpt_MgMsg
->
query_string
.
p
;
return
p_reqInfo_
->
query_string
;
return
NULL
;
return
nullptr
;
}
}
const
char
*
cMicroservice_IRequestRestImpl
::
GetRelativePath
()
const
char
*
cMicroservice_IRequestRestImpl
::
GetRelativePath
()
{
{
if
(
mpt_MgMsg
)
if
(
p_reqInfo_
)
return
mpt_MgMsg
->
uri
.
p
;
return
p_reqInfo_
->
local_uri
;
return
NULL
;
return
nullptr
;
}
}
const
char
*
cMicroservice_IRequestRestImpl
::
GetContent
()
const
char
*
cMicroservice_IRequestRestImpl
::
GetContent
()
{
{
if
(
mpt_MgMsg
)
if
(
p_reqInfo_
)
{
{
register
auto
len
=
mpt_MgMsg
->
body
.
len
;
register
auto
len
=
p_reqInfo_
->
content_length
;
if
(
len
>
0
)
if
(
len
>
0
)
{
{
mba_BodyBuffer
=
(
char
*
)
realloc
(
mba_BodyBuffer
,
len
+
1
);
mba_BodyBuffer
=
(
char
*
)
realloc
(
mba_BodyBuffer
,
len
+
1
);
memcpy
(
mba_BodyBuffer
,
mpt_MgMsg
->
body
.
p
,
len
);
len
=
mg_read
((
mg_connection
*
)
p_conn_
,
mba_BodyBuffer
,
len
);
*
(
mba_BodyBuffer
+
len
)
=
CNULL
;
*
(
mba_BodyBuffer
+
len
)
=
CNULL
;
return
(
const
char
*
)
mba_BodyBuffer
;
return
(
const
char
*
)
mba_BodyBuffer
;
}
}
// mpt_MgMsg->body.p[mpt_MgMsg->body.len] = CNULL;
//return mpt_MgMsg->body.p;
}
}
return
NULL
;
return
NULL
;
}
}
src/impl/Microservice_IRequestRestImpl.h
View file @
bc887b8e
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#ifndef MICROSERVICE_IREQUESTRESTIMPL_H_
#ifndef MICROSERVICE_IREQUESTRESTIMPL_H_
#define MICROSERVICE_IREQUESTRESTIMPL_H_
#define MICROSERVICE_IREQUESTRESTIMPL_H_
#include <common/Microservice_Iface.h>
#include <common/Microservice_Iface.h>
#include <civetweb.h>
struct
mg_connection
;
struct
mg_connection
;
struct
http_message
;
struct
http_message
;
...
@@ -15,7 +16,8 @@ struct http_message;
...
@@ -15,7 +16,8 @@ struct http_message;
class
cMicroservice_IRequestRestImpl
:
public
nsMicroservice_Iface
::
IRequest
class
cMicroservice_IRequestRestImpl
:
public
nsMicroservice_Iface
::
IRequest
{
{
//mg_connection *mpt_MgConn;
//mg_connection *mpt_MgConn;
http_message
*
mpt_MgMsg
;
const
mg_request_info
*
p_reqInfo_
;
const
mg_connection
*
p_conn_
;
char
*
mba_BodyBuffer
;
char
*
mba_BodyBuffer
;
public
:
public
:
cMicroservice_IRequestRestImpl
();
cMicroservice_IRequestRestImpl
();
...
@@ -28,7 +30,10 @@ public:
...
@@ -28,7 +30,10 @@ public:
void
Reset
();
void
Reset
();
//void setConn(mg_connection* pt_conn) { this->mpt_MgConn = pt_conn;}
//void setConn(mg_connection* pt_conn) { this->mpt_MgConn = pt_conn;}
void
SetMsg
(
http_message
*
mpt_MgMsg
)
{
this
->
mpt_MgMsg
=
mpt_MgMsg
;
}
void
SetParams
(
const
mg_connection
*
p_conn
,
const
mg_request_info
*
mpt_MgMsg
)
{
p_conn_
=
p_conn
;
p_reqInfo_
=
mpt_MgMsg
;
}
};
};
...
...
src/impl/Microservice_IResponseRestImpl.cpp
View file @
bc887b8e
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
* Author: amir
* Author: amir
*/
*/
#include <impl/Microservice_IResponseRestImpl.h>
#include <impl/Microservice_IResponseRestImpl.h>
#include <mongoose.h>
//
#include <mongoose.h>
#include <civetweb.h>
cMicroservice_IResponseRestImpl
::
cMicroservice_IResponseRestImpl
()
:
cMicroservice_IResponseRestImpl
::
cMicroservice_IResponseRestImpl
()
:
mpt_MgConn
(
NULL
)
mpt_MgConn
(
NULL
)
...
...
src/impl/servers/Microservice_IRestServer
Mongoose
Impl.cpp
→
src/impl/servers/Microservice_IRestServer
CivetWeb
Impl.cpp
View file @
bc887b8e
This diff is collapsed.
Click to expand it.
src/impl/servers/Microservice_IRestServer
Mongoose
Impl.h
→
src/impl/servers/Microservice_IRestServer
CivetWeb
Impl.h
View file @
bc887b8e
...
@@ -13,24 +13,28 @@
...
@@ -13,24 +13,28 @@
#ifndef MICROSERVICE_IRESTSERVERMONGOOSEIMPL_H
#ifndef MICROSERVICE_IRESTSERVERMONGOOSEIMPL_H
#define MICROSERVICE_IRESTSERVERMONGOOSEIMPL_H
#define MICROSERVICE_IRESTSERVERMONGOOSEIMPL_H
static
const
char
*
const
HTTP_1_1
=
"1.1"
;
#include "common/Microservice_Iface.h"
#include "common/Microservice_Iface.h"
#include <thread>
#include <thread>
#include <common/Microservice_RequestContext.h>
#include <common/Microservice_RequestContext.h>
#include "../../params/Microservice_Params.h"
#include "../../params/Microservice_Params.h"
struct
mg_connection
;
struct
mg_connection
;
struct
mg_mgr
;
//struct mg_mgr;
struct
http_message
;
//struct http_message;
struct
mg_context
;
struct
mg_request_info
;
class
cMicroservice_RestHandler
;
//
class cMicroservice_RestHandler;
class
cMicroservice_IResponseRestImpl
;
class
cMicroservice_IResponseRestImpl
;
class
cMicroservice_IRequestRestImpl
;
class
cMicroservice_IRequestRestImpl
;
class
cMicroservice_IRestServer
Mongoose
Impl
:
public
nsMicroservice_Iface
::
IRestServer
,
public
nsMicroservice_Iface
::
IContainer
{
class
cMicroservice_IRestServer
CivetWeb
Impl
:
public
nsMicroservice_Iface
::
IRestServer
,
public
nsMicroservice_Iface
::
IContainer
{
public
:
public
:
cMicroservice_IRestServer
Mongoose
Impl
(
cMicroservice_RestServerParams
*
pc_Param
);
cMicroservice_IRestServer
CivetWeb
Impl
(
cMicroservice_RestServerParams
*
pc_Param
);
cMicroservice_IRestServer
MongooseImpl
(
const
cMicroservice_IRestServerMongoose
Impl
&
orig
);
cMicroservice_IRestServer
CivetWebImpl
(
const
cMicroservice_IRestServerCivetWeb
Impl
&
orig
);
virtual
~
cMicroservice_IRestServer
Mongoose
Impl
();
virtual
~
cMicroservice_IRestServer
CivetWeb
Impl
();
bool
build
(
std
::
string
&
appName
,
const
std
::
map
<
std
::
string
,
nsMicroservice_Iface
::
IHandler
*>&
msHandlersMap
,
bool
build
(
std
::
string
&
appName
,
const
std
::
map
<
std
::
string
,
nsMicroservice_Iface
::
IHandler
*>&
msHandlersMap
,
nsMicroservice_Iface
::
ILogger
*
pc_Logger
,
nsMicroservice_Iface
::
ILogger
*
pc_Logger
,
...
@@ -45,7 +49,7 @@ public:
...
@@ -45,7 +49,7 @@ public:
virtual
bool
init
()
override
;
virtual
bool
init
()
override
;
void
HandleRequest
(
mg_connection
*
conn
,
http_message
*
msg
);
void
HandleRequest
(
mg_connection
*
conn
,
const
mg_request_info
*
req_info
);
void
SendNotImplemented
(
mg_connection
*
conn
);
void
SendNotImplemented
(
mg_connection
*
conn
);
virtual
void
SendErrorResp
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
std
::
string
error
)
override
;
virtual
void
SendErrorResp
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
std
::
string
error
)
override
;
...
@@ -63,9 +67,9 @@ public:
...
@@ -63,9 +67,9 @@ public:
private
:
private
:
cMicroservice_RestServerParams
*
mpc_Param
;
cMicroservice_RestServerParams
*
mpc_Param
;
//std::map<std::string,cMicroservice_RestHandler*> mc_HandlersMap
;
struct
mg_context
*
p_ctx_
;
std
::
string
mc_AppName
;
std
::
string
mc_AppName
;
mg_mgr
*
mpt_ServerManager
;
//
mg_mgr *mpt_ServerManager;
char
mba_UriBuff
[
nsMicroservice_Constants
::
MAX_URI_LENGTH
];
char
mba_UriBuff
[
nsMicroservice_Constants
::
MAX_URI_LENGTH
];
std
::
thread
*
mpc_RunThread
;
std
::
thread
*
mpc_RunThread
;
nsMicroservice_Iface
::
ILogger
*
mpc_Logger
;
nsMicroservice_Iface
::
ILogger
*
mpc_Logger
;
...
@@ -75,18 +79,18 @@ private:
...
@@ -75,18 +79,18 @@ private:
cMicroservice_IRequestRestImpl
*
p_requestRestImpl_
;
cMicroservice_IRequestRestImpl
*
p_requestRestImpl_
;
void
HandleNewRequest
(
mg_connection
*
p_connection
,
std
::
string
key
,
void
HandleNewRequest
(
mg_connection
*
p_connection
,
std
::
string
key
,
http_message
*
p_message
,
std
::
string
&
apiContextPath
);
const
mg_request_info
*
req_info
,
std
::
string
&
apiContextPath
);
void
SendGeneralError
(
mg_connection
*
p_connection
,
int
respCode
,
const
char
*
error
);
void
SendGeneralError
(
mg_connection
*
p_connection
,
int
respCode
,
const
char
*
error
);
MSRetStat
ParseRequest
(
mg_connection
*
p_conn
,
MSRetStat
ParseRequest
(
mg_connection
*
p_conn
,
http_message
*
p_message
,
const
mg_request_info
*
p_reqInfo
,
cMicroservice_RequestContext
&
ctx
,
cMicroservice_RequestContext
&
ctx
,
std
::
string
&
apiContextPath
);
std
::
string
&
apiContextPath
);
void
LogRequest
(
http_message
*
p_msg
);
void
LogRequest
(
const
mg_request_info
*
p_reqInfo
);
void
GetQueryParams
(
cMicroservice_RequestContext
&
ctx
,
http_message
*
p_msg
);
void
GetQueryParams
(
cMicroservice_RequestContext
&
ctx
,
const
mg_request_info
*
p_reqInfo
);
eCrudMethod
GetCrudMethod
(
http_message
*
p_msg
);
eCrudMethod
GetCrudMethod
(
const
mg_request_info
*
p_reqInfo
);
};
};
#endif
/* MICROSERVICE_IRESTSERVERMONGOOSEIMPL_H */
#endif
/* MICROSERVICE_IRESTSERVERMONGOOSEIMPL_H */
...
...
src/utils/CommonUtils.h
View file @
bc887b8e
...
@@ -33,6 +33,21 @@ public:
...
@@ -33,6 +33,21 @@ public:
return
duration
.
count
();
return
duration
.
count
();
}
}
static
int
strcmp
(
const
char
*
str1
,
const
char
*
str2
)
{
size_t
n2
=
strlen
(
str2
),
n1
=
strlen
(
str1
);
int
r
=
memcmp
(
str1
,
str2
,
(
n1
<
n2
)
?
n1
:
n2
);
if
(
r
==
0
)
{
return
n1
-
n2
;
}
return
r
;
}
static
int
numofcpu
(){
size_t
cpunum
=
sysconf
(
_SC_NPROCESSORS_ONLN
);
if
(
cpunum
==
0
)
cpunum
=
1
;
return
(
int
)
cpunum
;
}
};
};
...
...
src/utils/ServerFactory.cpp
View file @
bc887b8e
...
@@ -3,13 +3,13 @@
...
@@ -3,13 +3,13 @@
//
//
#include "ServerFactory.h"
#include "ServerFactory.h"
#include <impl/servers/Microservice_IRestServer
Mongoose
Impl.h>
#include <impl/servers/Microservice_IRestServer
CivetWeb
Impl.h>
#include <impl/servers/Microservice_IMsgQueueServerZmqImpl.h>
#include <impl/servers/Microservice_IMsgQueueServerZmqImpl.h>
#include <impl/servers/Microservice_IRestServerRMQImpl.h>
#include <impl/servers/Microservice_IRestServerRMQImpl.h>
cMicroservice_IRestServer
Mongoose
Impl
*
cMicroservice_IRestServer
CivetWeb
Impl
*
ServerFactory
::
createIRestServerMongooseImpl
(
std
::
string
host
,
int
port
,
int
workerThreadsNum
)
{
ServerFactory
::
createIRestServerMongooseImpl
(
std
::
string
host
,
int
port
,
int
workerThreadsNum
)
{
return
new
cMicroservice_IRestServer
Mongoose
Impl
(
new
cMicroservice_RestServerParams
(
port
,
host
,
workerThreadsNum
));
return
new
cMicroservice_IRestServer
CivetWeb
Impl
(
new
cMicroservice_RestServerParams
(
port
,
host
,
workerThreadsNum
));
}
}
Microservice_IMsgQueueServerZmqImpl
*
Microservice_IMsgQueueServerZmqImpl
*
...
...
src/utils/ServerFactory.h
View file @
bc887b8e
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#include <string>
#include <string>
#include <params/Microservice_Params.h>
#include <params/Microservice_Params.h>
class
cMicroservice_IRestServer
Mongoose
Impl
;
class
cMicroservice_IRestServer
CivetWeb
Impl
;
class
Microservice_IMsgQueueServerZmqImpl
;
class
Microservice_IMsgQueueServerZmqImpl
;
class
cMicroservice_IRestServerRMQImpl
;
class
cMicroservice_IRestServerRMQImpl
;
...
@@ -18,7 +18,7 @@ class cMicroservice_IRestServerRMQImpl;
...
@@ -18,7 +18,7 @@ class cMicroservice_IRestServerRMQImpl;
class
ServerFactory
{
class
ServerFactory
{
public
:
public
:
static
cMicroservice_IRestServer
Mongoose
Impl
*
createIRestServerMongooseImpl
(
std
::
string
host
,
static
cMicroservice_IRestServer
CivetWeb
Impl
*
createIRestServerMongooseImpl
(
std
::
string
host
,
int
port
,
int
port
,
int
workerThreadsNum
);
int
workerThreadsNum
);
static
Microservice_IMsgQueueServerZmqImpl
*
createIMsgQueueServerZmqImpl
(
std
::
string
host
,
static
Microservice_IMsgQueueServerZmqImpl
*
createIMsgQueueServerZmqImpl
(
std
::
string
host
,
...
...
test/Microservice_ClientTest.cpp
View file @
bc887b8e
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#include <Microservice_Client.h>
#include <Microservice_Client.h>
#include <params/Microservice_Params.h>
#include <params/Microservice_Params.h>
#include <document.h> //rapidjson
#include <document.h> //rapidjson
#include <impl/servers/Microservice_IRestServer
Mongoose
Impl.h>
#include <impl/servers/Microservice_IRestServer
CivetWeb
Impl.h>
#include <impl/servers/Microservice_IRestServerRMQImpl.h>
#include <impl/servers/Microservice_IRestServerRMQImpl.h>
#include <impl/Microservice_ICacheClientRedisImpl.h>
#include <impl/Microservice_ICacheClientRedisImpl.h>
#include <impl/clients/MSICommandClientHttpImpl.h>
#include <impl/clients/MSICommandClientHttpImpl.h>
...
...
test/Microservice_Test.cpp
View file @
bc887b8e
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#include <Microservice_Client.h>
#include <Microservice_Client.h>
#include <params/Microservice_Params.h>
#include <params/Microservice_Params.h>
#include <document.h> //rapidjson
#include <document.h> //rapidjson
#include <impl/servers/Microservice_IRestServer
Mongoose
Impl.h>
#include <impl/servers/Microservice_IRestServer
CivetWeb
Impl.h>
#include <impl/servers/Microservice_IMsgQueueServerZmqImpl.h>
#include <impl/servers/Microservice_IMsgQueueServerZmqImpl.h>
#include <impl/servers/Microservice_IRestServerRMQImpl.h>
#include <impl/servers/Microservice_IRestServerRMQImpl.h>
#include <impl/Microservice_ICacheClientRedisImpl.h>
#include <impl/Microservice_ICacheClientRedisImpl.h>
...
@@ -101,8 +101,8 @@ public:
...
@@ -101,8 +101,8 @@ public:
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
it
->
first
.
c_str
()),
rapidjson
::
StringRef
(
dequeIt
->
c_str
()),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
it
->
first
.
c_str
()),
rapidjson
::
StringRef
(
dequeIt
->
c_str
()),
rpj_Alloc
);
}
}
}
}
ReadSync
(
pc_reqCtx
);
//
ReadSync(pc_reqCtx);
//
ReadAsync2(pc_reqCtx);
ReadAsync2
(
pc_reqCtx
);
//this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
//this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
// add metric
// add metric
long
value
=
rand
()
%
1000
+
1
;
long
value
=
rand
()
%
1000
+
1
;
...
@@ -302,7 +302,7 @@ void runNewMS(){
...
@@ -302,7 +302,7 @@ void runNewMS(){
.
addClient
(
ClientFactory
::
createHttpImplMsClient
(
"other-service"
,
"localhost"
,
32010
,
true
,
10
,
false
,
"localhost:6379"
))
//new cMicroservice_Client(new MSICommandClientHttpImpl(),&clientParams))
.
addClient
(
ClientFactory
::
createHttpImplMsClient
(
"other-service"
,
"localhost"
,
32010
,
true
,
10
,
false
,
"localhost:6379"
))
//new cMicroservice_Client(new MSICommandClientHttpImpl(),&clientParams))
.
addClient
(
ClientFactory
::
createZmqMsgQImp
(
"zmq-service"
,
msApp
.
name
(),
0
,
.
addClient
(
ClientFactory
::
createZmqMsgQImp
(
"zmq-service"
,
msApp
.
name
(),
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addServer
(
ServerFactory
::
createIRestServerMongooseImpl
(
""
,
50010
,
1
))
// .addRestServer(new cMicroservice_IRestServer
Mongoose
Impl(new cMicroservice_RestServerParams(50010,"",1)))
.
addServer
(
ServerFactory
::
createIRestServerMongooseImpl
(
""
,
50010
,
1
))
// .addRestServer(new cMicroservice_IRestServer
CivetWeb
Impl(new cMicroservice_RestServerParams(50010,"",1)))
.
addServer
(
ServerFactory
::
createIMsgQueueServerZmqImpl
(
msApp
.
name
(),
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addServer
(
ServerFactory
::
createIMsgQueueServerZmqImpl
(
msApp
.
name
(),
0
,
Microservice_ZMQServerParams
::
eProtocol
::
eIpc
))
.
addHandler
(
"/xxx"
,(
cMicroservice_BaseHandler
*
)
new
cMicroserviceHandler
(
"hello"
))
.
addHandler
(
"/xxx"
,(
cMicroservice_BaseHandler
*
)
new
cMicroserviceHandler
(
"hello"
))
.
addHandler
(
"/zmq"
,
new
MSMsgQHandler
())
.
addHandler
(
"/zmq"
,
new
MSMsgQHandler
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment