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
e0cb4bb9
authored
Nov 14, 2016
by
amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
start working on feature
parent
7b356122
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
329 additions
and
232 deletions
CMakeLists.txt
doc/install-dependencies.sh
src/Microservice_Iface.h
src/handlers/Microservice_RestHandler.h
src/impl/servers/Microservice_IMsgQueueZmqImpl.cpp
src/impl/servers/Microservice_IMsgQueueZmqImpl.h
test/Microservice_Test.cpp
CMakeLists.txt
View file @
e0cb4bb9
...
...
@@ -18,7 +18,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set
(
PROJECT_LINK_LIBS -ljson -lhiredis -lcpprest -lcppmetrics -lboost_random -lboost_timer -lboost_chrono
-lboost_system -lboost_thread -lboost_date_time -lboost_regex -lboost_filesystem -lpthread
-lboost_random -lboost_chrono -lboost_system -lboost_thread -lssl
-lcrypto -lRabbitmq -lrabbitmq -llog4cpp -lglog
)
-lcrypto -lRabbitmq -lrabbitmq -llog4cpp -lglog
-lczmq
)
link_directories
(
../3party/lib
)
link_directories
(
../internals/lib
)
...
...
@@ -31,12 +31,13 @@ include_directories(SYSTEM ../3party/cpprest/Release/include)
include_directories
(
SYSTEM ../3party/rabbitmq
)
include_directories
(
SYSTEM ../internals/include/Rabbitmq
)
include_directories
(
SYSTEM /usr/include/hiredis
)
include_directories
(
SYSTEM ../3party/czmq-4.0.0/include
)
# recursive search files cpp files
file
(
GLOB_RECURSE SOURCES
"src/*.cpp"
)
set
(
3PARTY_SOURCES ../3party/mongoose/mongoose.c
)
#Generate the shared library from the sources
add_library
(
Microservice SHARED
${
SOURCES
}
${
3PARTY_SOURCES
}
src/common/Microservice_RestResponse.h
)
add_library
(
Microservice SHARED
${
SOURCES
}
${
3PARTY_SOURCES
}
src/common/Microservice_RestResponse.h
src/impl/servers/Microservice_IMsgQueueZmqImpl.cpp src/impl/servers/Microservice_IMsgQueueZmqImpl.h
)
target_link_libraries
(
Microservice
${
PROJECT_LINK_LIBS
}
)
set_target_properties
(
Microservice PROPERTIES VERSION
${
Microservice_VERSION_STRING
}
SOVERSION
${
Microservice_VERSION_MAJOR
}
)
...
...
doc/install-dependencies.sh
View file @
e0cb4bb9
...
...
@@ -6,4 +6,4 @@
# Created on May 8, 2016, 9:59:18 AM
#
sudo
apt-get install
-y
libhiredis0.10 libhiredis-dev libzmq3 libzmq3-dev liblog4cpp5 liblog4cpp5-dev
\
libgoogle-glog-dev libboost-all-dev libssl-dev
\ No newline at end of file
libgoogle-glog-dev libboost-all-dev libssl-dev uuid-dev libpcre3-dev valgrind
\ No newline at end of file
src/Microservice_Iface.h
View file @
e0cb4bb9
...
...
@@ -27,202 +27,218 @@ class cMicroservice_BaseHandler;
namespace
nsMicroservice_Iface
{
struct
INotifyCallback
{
virtual
void
onMessage
(
std
::
string
&
t_Topic
,
std
::
string
&
t_Message
)
=
0
;
virtual
void
onError
(
std
::
string
&
t_Topic
,
std
::
string
&
t_Error
)
=
0
;
};
struct
IConfigurationProvider
{
virtual
std
::
map
<
std
::
string
,
std
::
string
>
getAllProperties
()
=
0
;
virtual
std
::
string
getPropertyAsString
(
std
::
string
key
)
=
0
;
};
struct
IConfiguration
{
virtual
void
AddConfigurationProvider
(
IConfigurationProvider
&
iProvider
)
=
0
;
virtual
void
Reload
()
=
0
;
virtual
long
GetLong
(
std
::
string
key
,
long
defaultVal
)
=
0
;
virtual
std
::
string
GetString
(
std
::
string
key
,
std
::
string
defaultVal
)
=
0
;
virtual
bool
GetBoolean
(
std
::
string
key
,
bool
defaultVal
)
=
0
;
};
struct
ILogger
{
virtual
void
fatal
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
error
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
warning
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
info
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
debug
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
trace
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
fatal
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
error
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
warning
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
info
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
debug
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
trace
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
setLevel
(
cMicroservice_Enums
::
eLogLevel
level
)
=
0
;
};
struct
ICommandClient
{
ILogger
*
p_logger_
;
public
:
/*
public abstract class Command extends HystrixCommand<BaseRestResponse> {
protected MSCommandParams* p_cmd_params = null;
public Command(MSCommandParams* p_cmd_params, String cmdName)
{
super(HystrixCommandGroupKey.Factory.asKey(cmdName));
this.reqCtx = reqCtx;
}
@Override
protected BaseRestResponse getFallback()
{
return new BaseRestResponse(false, COMMAND_ERROR + getFailedExecutionException().getMessage());
}
}
*/
virtual
MSRetStat
Create
(
MSCommandParams
*
p_cmd_params
,
cMicroservice_BaseRestResponse
*
p_response
)
=
0
;
/**
* the read/get of CRUD
* @param reqCtx
*/
virtual
MSRetStat
Read
(
MSCommandParams
*
p_cmd_params
,
cMicroservice_BaseRestResponse
*
p_response
)
=
0
;
/**
* the update/put of CRUD
* @param reqCtx
*/
virtual
MSRetStat
Update
(
MSCommandParams
*
p_cmd_params
,
cMicroservice_BaseRestResponse
*
p_response
)
=
0
;
/**
* the delete of CRUD
* @param reqCtx
*/
virtual
MSRetStat
Delete
(
MSCommandParams
*
p_cmd_params
,
cMicroservice_BaseRestResponse
*
p_response
)
=
0
;
/**
* getting the metrics as jsonnode - array
* @return
*/
virtual
void
GetMetrics
(
std
::
map
<
std
::
string
,
long
>&
metrics_map
)
=
0
;
virtual
void
SetLogger
(
ILogger
*
logger
)
{
p_logger_
=
logger
;
}
};
struct
IMetricsFactory
{
struct
IMeter
///////////////////// BASE INTERFACES //////////////////////
struct
IServer
{};
struct
IClient
{};
////////////////////////////////////////////////////////////
struct
INotifyCallback
{
virtual
void
mark
()
=
0
;
virtual
void
mark
(
long
n
)
=
0
;
virtual
long
getCount
()
=
0
;
virtual
void
onMessage
(
std
::
string
&
t_Topic
,
std
::
string
&
t_Message
)
=
0
;
virtual
void
onError
(
std
::
string
&
t_Topic
,
std
::
string
&
t_Error
)
=
0
;
};
struct
IConfigurationProvider
{
virtual
std
::
map
<
std
::
string
,
std
::
string
>
getAllProperties
()
=
0
;
virtual
std
::
string
getPropertyAsString
(
std
::
string
key
)
=
0
;
};
struct
IConfiguration
{
virtual
void
AddConfigurationProvider
(
IConfigurationProvider
&
iProvider
)
=
0
;
virtual
void
Reload
()
=
0
;
virtual
long
GetLong
(
std
::
string
key
,
long
defaultVal
)
=
0
;
virtual
std
::
string
GetString
(
std
::
string
key
,
std
::
string
defaultVal
)
=
0
;
virtual
bool
GetBoolean
(
std
::
string
key
,
bool
defaultVal
)
=
0
;
};
struct
I
Count
er
struct
I
Logg
er
{
virtual
void
inc
()
=
0
;
virtual
void
inc
(
long
n
)
=
0
;
virtual
void
dec
()
=
0
;
virtual
void
dec
(
long
n
)
=
0
;
virtual
long
getCount
()
=
0
;
virtual
void
fatal
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
error
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
warning
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
info
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
debug
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
trace
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
fatal
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
error
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
warning
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
info
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
debug
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
trace
(
const
char
*
stringFormat
,
...)
=
0
;
virtual
void
setLevel
(
cMicroservice_Enums
::
eLogLevel
level
)
=
0
;
};
struct
I
Timer
struct
I
CommandClient
:
public
IClient
{
virtual
void
start
()
=
0
;
virtual
void
stop
()
=
0
;
ILogger
*
p_logger_
;
public
:
/**
* the create/post of CRUD
* @param p_cmd_params
* @param p_response
* @return
*/
virtual
MSRetStat
Create
(
MSCommandParams
*
p_cmd_params
,
cMicroservice_BaseRestResponse
*
p_response
)
=
0
;
/**
* the read/get of CRUD
* @param reqCtx
*/
virtual
MSRetStat
Read
(
MSCommandParams
*
p_cmd_params
,
cMicroservice_BaseRestResponse
*
p_response
)
=
0
;
/**
* the update/put of CRUD
* @param reqCtx
*/
virtual
MSRetStat
Update
(
MSCommandParams
*
p_cmd_params
,
cMicroservice_BaseRestResponse
*
p_response
)
=
0
;
/**
* the delete of CRUD
* @param reqCtx
*/
virtual
MSRetStat
Delete
(
MSCommandParams
*
p_cmd_params
,
cMicroservice_BaseRestResponse
*
p_response
)
=
0
;
/**
* getting the metrics as jsonnode - array
* @return
*/
virtual
void
GetMetrics
(
std
::
map
<
std
::
string
,
long
>&
metrics_map
)
=
0
;
virtual
void
SetLogger
(
ILogger
*
logger
)
{
p_logger_
=
logger
;
}
};
struct
IHistogram
{
virtual
void
update
(
long
value
)
=
0
;
virtual
long
getCount
()
=
0
;
virtual
void
clear
()
=
0
;
};
/**
* must be at the end of init , after the netrics are defined
*/
virtual
void
startReporting
()
=
0
;
virtual
void
stopReporting
()
=
0
;
virtual
IMeter
*
createMeter
(
std
::
string
&
name
)
=
0
;
virtual
ICounter
*
createCounter
(
std
::
string
&
name
)
=
0
;
virtual
ITimer
*
createTimer
(
std
::
string
&
name
)
=
0
;
virtual
IHistogram
*
createHistogram
(
std
::
string
&
name
)
=
0
;
virtual
void
GetMetrics
(
std
::
map
<
std
::
string
,
long
>&
metrics_map
)
=
0
;
};
struct
IPubSub
struct
IMetricsFactory
{
struct
IMeter
{
virtual
void
mark
()
=
0
;
virtual
void
mark
(
long
n
)
=
0
;
virtual
long
getCount
()
=
0
;
};
struct
ICounter
{
virtual
void
inc
()
=
0
;
virtual
void
inc
(
long
n
)
=
0
;
virtual
void
dec
()
=
0
;
virtual
void
dec
(
long
n
)
=
0
;
virtual
long
getCount
()
=
0
;
};
struct
ITimer
{
virtual
void
start
()
=
0
;
virtual
void
stop
()
=
0
;
};
struct
IHistogram
{
virtual
void
update
(
long
value
)
=
0
;
virtual
long
getCount
()
=
0
;
virtual
void
clear
()
=
0
;
};
/**
* must be at the end of init , after the netrics are defined
*/
virtual
void
startReporting
()
=
0
;
virtual
void
stopReporting
()
=
0
;
virtual
IMeter
*
createMeter
(
std
::
string
&
name
)
=
0
;
virtual
ICounter
*
createCounter
(
std
::
string
&
name
)
=
0
;
virtual
ITimer
*
createTimer
(
std
::
string
&
name
)
=
0
;
virtual
IHistogram
*
createHistogram
(
std
::
string
&
name
)
=
0
;
virtual
void
GetMetrics
(
std
::
map
<
std
::
string
,
long
>&
metrics_map
)
=
0
;
};
struct
IPubSubServer
:
public
IServer
{
/**
/**
* you can subscribe multiple times but
* every subscription opens a thread
* @param topic - can be with wildcard: activity/*
* @param notifyHandler
*/
virtual
void
subscribe
(
std
::
string
&
topic
,
INotifyCallback
&
notifyHandler
)
=
0
;
/**
*
virtual
void
subscribe
(
std
::
string
&
topic
,
INotifyCallback
&
notifyHandler
)
=
0
;
/**
*
* @param topic
*/
virtual
void
unsubscribe
(
std
::
string
&
topic
)
=
0
;
virtual
void
publish
(
std
::
string
&
topic
,
std
::
string
&
message
)
=
0
;
virtual
void
unsubscribe
(
std
::
string
&
topic
)
=
0
;
};
struct
IServiceDiscovery
{
virtual
bool
registerService
(
std
::
string
&
name
,
std
::
string
&
id
,
std
::
string
&
host
,
int
port
)
=
0
;
virtual
bool
unregisterService
()
=
0
;
virtual
IConfigurationProvider
&
getConfigurationProvider
()
=
0
;
};
struct
IRestServer
{
public
:
virtual
bool
build
(
std
::
string
&
appName
,
std
::
map
<
std
::
string
,
cMicroservice_BaseHandler
*>&
msHandlersMap
,
ILogger
*
pc_Logger
,
IPubSub
*
pc_PubSub
,
IMetricsFactory
*
p_metrics_factory
)
=
0
;
virtual
void
run
()
=
0
;
virtual
void
stop
()
=
0
;
virtual
void
registerService
(
IServiceDiscovery
*
pc_ServiceDiscovery
,
std
::
string
&
id
)
=
0
;
};
struct
IRequest
{
public
:
virtual
~
IRequest
()
{};
//InputStream getInputStream() = 0;
virtual
const
char
*
GetQueryString
()
=
0
;
virtual
const
char
*
GetRelativePath
()
=
0
;
virtual
const
char
*
GetContent
()
=
0
;
virtual
void
Reset
()
{};
};
struct
IResponse
struct
IPubSubClient
:
public
IClient
{
public
:
virtual
~
IResponse
()
{};
//public void send(ByteBuffer buffer);
virtual
void
Send
(
const
char
*
response
)
=
0
;
virtual
void
Reset
()
{};
virtual
IResponse
*
clone
()
=
0
;
virtual
void
publish
(
std
::
string
&
topic
,
std
::
string
&
message
)
=
0
;
};
/**
struct
IPubSub
{
/**
* you can subscribe multiple times but
* every subscription opens a thread
* @param topic - can be with wildcard: activity/*
* @param notifyHandler
*/
virtual
void
subscribe
(
std
::
string
&
topic
,
INotifyCallback
&
notifyHandler
)
=
0
;
/**
*
* @param topic
*/
virtual
void
unsubscribe
(
std
::
string
&
topic
)
=
0
;
virtual
void
publish
(
std
::
string
&
topic
,
std
::
string
&
message
)
=
0
;
};
struct
IServiceDiscovery
{
virtual
bool
registerService
(
std
::
string
&
name
,
std
::
string
&
id
,
std
::
string
&
host
,
int
port
)
=
0
;
virtual
bool
unregisterService
()
=
0
;
virtual
IConfigurationProvider
&
getConfigurationProvider
()
=
0
;
};
struct
IRestServer
:
public
IServer
{
public
:
virtual
bool
build
(
std
::
string
&
appName
,
std
::
map
<
std
::
string
,
cMicroservice_BaseHandler
*>&
msHandlersMap
,
ILogger
*
pc_Logger
,
IPubSub
*
pc_PubSub
,
IMetricsFactory
*
p_metrics_factory
)
=
0
;
virtual
void
run
()
=
0
;
virtual
void
stop
()
=
0
;
virtual
void
registerService
(
IServiceDiscovery
*
pc_ServiceDiscovery
,
std
::
string
&
id
)
=
0
;
};
struct
IRequest
{
public
:
virtual
~
IRequest
()
{};
//InputStream getInputStream() = 0;
virtual
const
char
*
GetQueryString
()
=
0
;
virtual
const
char
*
GetRelativePath
()
=
0
;
virtual
const
char
*
GetContent
()
=
0
;
virtual
void
Reset
()
{};
};
struct
IResponse
{
public
:
virtual
~
IResponse
()
{};
//public void send(ByteBuffer buffer);
virtual
void
Send
(
const
char
*
response
)
=
0
;
virtual
void
Reset
()
{};
virtual
IResponse
*
clone
()
=
0
;
};
/**
* this interface defines the basic operations
* required from the container implementor
* needed by the ms handler
...
...
@@ -230,73 +246,89 @@ struct IRequest
* @author amir
*
*/
struct
IContainer
{
public
:
virtual
~
IContainer
()
{};
//public static Pattern seperatorPattern = Pattern.compile("/");
virtual
void
SendErrorResp
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
std
::
string
error
)
=
0
;
/**
struct
IContainer
{
public
:
virtual
~
IContainer
()
{};
//public static Pattern seperatorPattern = Pattern.compile("/");
virtual
void
SendErrorResp
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
std
::
string
error
)
=
0
;
/**
* writing the value to resp as json
* @param res
* @param value
*/
virtual
void
WriteObjectToResponse
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
rapidjson
::
Document
&
t_ObjectDoc
)
=
0
;
virtual
void
WriteObjectToResponse
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
cMicroservice_BaseRestResponse
&
t_BaseRestResponse
)
=
0
;
virtual
void
WriteStringToResponse
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
const
char
*
pba_Doc
)
=
0
;
/**
virtual
void
WriteObjectToResponse
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
rapidjson
::
Document
&
t_ObjectDoc
)
=
0
;
virtual
void
WriteObjectToResponse
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
cMicroservice_BaseRestResponse
&
t_BaseRestResponse
)
=
0
;
virtual
void
WriteStringToResponse
(
nsMicroservice_Iface
::
IResponse
*
pti_Response
,
const
char
*
pba_Doc
)
=
0
;
/**
* reading the object from the request body json
* @param req
* @param ObjClass
* @return
*/
virtual
bool
ReadObjectFromRequest
(
nsMicroservice_Iface
::
IRequest
*
pti_Request
,
rapidjson
::
Document
&
t_ObjectDoc
)
=
0
;
/**
virtual
bool
ReadObjectFromRequest
(
nsMicroservice_Iface
::
IRequest
*
pti_Request
,
rapidjson
::
Document
&
t_ObjectDoc
)
=
0
;
////////// PUB/SUB ////////////////////////////////
/**
* subscribing to specific topic
* @param topic
* @param notifyHandler
*/
virtual
void
Subscribe
(
std
::
string
&
t_Topic
,
nsMicroservice_Iface
::
INotifyCallback
&
t_NotifyHandler
)
=
0
;
/**
virtual
void
Subscribe
(
std
::
string
&
t_Topic
,
nsMicroservice_Iface
::
INotifyCallback
&
t_NotifyHandler
)
=
0
;
/**
* un-subscribing from topic
* @param topic
*/
virtual
void
Unsubscribe
(
std
::
string
&
t_Topic
)
=
0
;
/**
virtual
void
Unsubscribe
(
std
::
string
&
t_Topic
)
=
0
;
/**
* publish msg on specific topic
* @param topic
* @param messageNode
*/
virtual
void
Publish
(
std
::
string
&
t_Topic
,
std
::
string
&
t_Message
)
=
0
;
virtual
void
Publish
(
std
::
string
&
t_Topic
,
std
::
string
&
t_Message
)
=
0
;
};
struct
ICacheClient
struct
ICacheClient
{
/**
* set/update with the default expiration
* @param key
* @param value
*/
virtual
void
set
(
std
::
string
&
key
,
std
::
string
&
value
)
=
0
;
virtual
void
set
(
std
::
string
&
key
,
std
::
string
&
value
,
int
expiration
)
=
0
;
virtual
void
setExpiration
(
std
::
string
&
key
,
int
expiration
)
=
0
;
virtual
bool
get
(
std
::
string
&
key
,
std
::
string
&
retval
)
=
0
;
virtual
void
del
(
std
::
string
&
key
)
=
0
;
virtual
void
delByPattern
(
std
::
string
&
pattern
)
=
0
;
virtual
bool
getKeysByPattern
(
std
::
string
&
pattern
,
std
::
vector
<
std
::
string
>&
retKeys
)
=
0
;
virtual
bool
getByPattern
(
std
::
string
&
pattern
,
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>&
retKeyValues
)
=
0
;
virtual
bool
exists
(
std
::
string
&
key
)
=
0
;
};
struct
IMsgQueueServer
:
public
IServer
{
/**
* set/update with the default expiration
* @param key
* @param value
*/
virtual
void
set
(
std
::
string
&
key
,
std
::
string
&
value
)
=
0
;
virtual
void
set
(
std
::
string
&
key
,
std
::
string
&
value
,
int
expiration
)
=
0
;
virtual
void
setExpiration
(
std
::
string
&
key
,
int
expiration
)
=
0
;
virtual
bool
get
(
std
::
string
&
key
,
std
::
string
&
retval
)
=
0
;
virtual
void
del
(
std
::
string
&
key
)
=
0
;
virtual
void
delByPattern
(
std
::
string
&
pattern
)
=
0
;
virtual
bool
getKeysByPattern
(
std
::
string
&
pattern
,
std
::
vector
<
std
::
string
>&
retKeys
)
=
0
;
virtual
bool
getByPattern
(
std
::
string
&
pattern
,
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>&
retKeyValues
)
=
0
;
virtual
bool
exists
(
std
::
string
&
key
)
=
0
;
virtual
MSRetStat
Receive
(
std
::
string
&
t_Message
)
=
0
;
};
struct
IMsgQueueClient
:
public
IClient
{
virtual
MSRetStat
Send
(
std
::
string
&
t_Message
)
=
0
;
};
struct
IMsgQueue
{
struct
IDestination
{};
virtual
MSRetStat
Send
(
std
::
string
&
t_Message
,
IDestination
*
p_Dest
)
=
0
;
virtual
MSRetStat
Receive
(
std
::
string
&
t_Message
)
=
0
;
};
}
...
...
src/handlers/Microservice_RestHandler.h
View file @
e0cb4bb9
...
...
@@ -29,6 +29,7 @@ private:
cMicroservice_BaseHandler
*
mpc_Handler
;
nsMicroservice_Iface
::
ILogger
*
mpc_Logger
;
nsMicroservice_Iface
::
IPubSub
*
mpc_PubSub
;
cMicroservice_RequestContext
*
mpc_RequestContext
;
char
mba_Buff
[
nsMicroservice_Constants
::
MAX_URI_LENGTH
];
char
mba_ErrorBuff
[
nsMicroservice_Constants
::
MAX_ERROR_BUFF_URI_LENGTH
];
...
...
src/impl/servers/Microservice_IMsgQueueZmqImpl.cpp
0 → 100644
View file @
e0cb4bb9
//
// Created by amir on 13/11/16.
//
#include "Microservice_IMsgQueueZmqImpl.h"
MSRetStat
Microservice_IMsgQueueZmqImpl
::
Send
(
std
::
string
&
t_Message
,
nsMicroservice_Iface
::
IMsgQueue
::
IDestination
*
p_Dest
)
{
return
MSRetStat
();
}
MSRetStat
Microservice_IMsgQueueZmqImpl
::
Receive
(
std
::
string
&
t_Message
)
{
return
MSRetStat
();
}
src/impl/servers/Microservice_IMsgQueueZmqImpl.h
0 → 100644
View file @
e0cb4bb9
//
// Created by amir on 13/11/16.
//
#ifndef MICROSERVICE_MICROSERVICE_IMSGQUEUEZMQIMPL_H
#define MICROSERVICE_MICROSERVICE_IMSGQUEUEZMQIMPL_H
#include <Microservice_Iface.h>
class
Microservice_IMsgQueueZmqImpl
:
public
nsMicroservice_Iface
::
IMsgQueue
{
public
:
class
ZMQDestination
:
public
nsMicroservice_Iface
::
IMsgQueue
::
IDestination
{
};
public
:
virtual
MSRetStat
Send
(
std
::
string
&
t_Message
,
IDestination
*
p_Dest
)
override
;
virtual
MSRetStat
Receive
(
std
::
string
&
t_Message
)
override
;
};
typedef
std
::
shared_ptr
<
Microservice_IMsgQueueZmqImpl
::
ZMQDestination
>
ZmqDestinationPtr
;
#endif //MICROSERVICE_MICROSERVICE_IMSGQUEUEZMQIMPL_H
test/Microservice_Test.cpp
View file @
e0cb4bb9
...
...
@@ -36,11 +36,15 @@ public:
}
void
DoCreate
(
cMicroservice_RequestContext
*
pc_reqCtx
)
{
rapidjson
::
Document
rpj_Doc
;
if
(
this
->
ReadObjectFromRequest
(
pc_reqCtx
,
rpj_Doc
)
)
this
->
WriteObjectToResponse
(
pc_reqCtx
,
rpj_Doc
);
else
this
->
SendErrorResp
(
pc_reqCtx
,
"Error in parsing json"
);
if
(
pc_reqCtx
->
mc_QueryParameters
.
empty
())
CreateSync
(
pc_reqCtx
);
else
{
rapidjson
::
Document
rpj_Doc
;
if
(
this
->
ReadObjectFromRequest
(
pc_reqCtx
,
rpj_Doc
)
)
this
->
WriteObjectToResponse
(
pc_reqCtx
,
rpj_Doc
);
else
this
->
SendErrorResp
(
pc_reqCtx
,
"Error in parsing json"
);
}
}
void
DoRead
(
cMicroservice_RequestContext
*
pc_reqCtx
)
...
...
@@ -85,6 +89,25 @@ public:
SendErrorResp
(
pc_reqCtx
,
retstat
.
GetError
());
}
void
CreateSync
(
cMicroservice_RequestContext
*
pc_reqCtx
)
{
Microservice_RestResponse
rest_response
;
std
::
map
<
std
::
string
,
std
::
string
>
headers
;
headers
[
"X-IPgallery"
]
=
"OK"
;
MSCommandParams
cmd_params
;
cmd_params
//.WithEntity("http://httpbin.org/post")
.
WithEntity
(
"http://172.16.1.151:50010/nse/auth"
)
//.WithParamsString("login")
.
WithRequestParams
(
"key=123"
)
.
EnableAsync
(
false
);
MSRetStat
retstat
=
p_client_
->
Read
(
&
cmd_params
,
&
rest_response
);
if
(
retstat
.
IsSuccess
())
WriteObjectToResponse
(
pc_reqCtx
,
rest_response
);
else
SendErrorResp
(
pc_reqCtx
,
retstat
.
GetError
());
}
void
DoUpdate
(
cMicroservice_RequestContext
*
pc_reqCtx
)
{
}
...
...
@@ -247,7 +270,7 @@ TO testDocs()
cMicroservice_BaseRestResponse
resp
;
if
(
resp
.
GetObjectNode
().
IsNull
())
{
std
::
cout
<<
"empty
\n
"
;
}
rapidjson
::
Document
&
rpj_Doc
=
resp
.
GetObjectNode
();
rapidjson
::
Document
&
rpj_Doc
=
resp
.
GetObjectNode
();
rapidjson
::
Document
::
AllocatorType
&
rpj_Alloc
=
rpj_Doc
.
GetAllocator
();
rpj_Doc
.
SetObject
();
if
(
resp
.
GetObjectNode
().
IsNull
())
{
std
::
cout
<<
"empty
\n
"
;
}
...
...
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