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
ce505d29
authored
Mar 30, 2017
by
amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
todo
parent
f7e1966d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
27 deletions
doc/todo.txt
test/Microservice_ClientTest.cpp
doc/todo.txt
View file @
ce505d29
...
@@ -3,4 +3,6 @@
...
@@ -3,4 +3,6 @@
Using 2 channels push and pull . client send on push and in another thread waits on pull
Using 2 channels push and pull . client send on push and in another thread waits on pull
the server receives the msg with the source(client pull channel) address to reply to,
the server receives the msg with the source(client pull channel) address to reply to,
checks in the hash for already connected and uses this channel to send a reply.
checks in the hash for already connected and uses this channel to send a reply.
we can use zmqpp::socket::send_more to send source address and then the actual msg
we can use zmqpp::socket::send_more to send source address and then the actual msg
\ No newline at end of file
- Test FlatBuffer as serialyzer for rest over zmq
\ No newline at end of file
test/Microservice_ClientTest.cpp
View file @
ce505d29
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include "impl/Microservices_ILoggerLog4cppImpl.h"
#include "impl/Microservices_ILoggerLog4cppImpl.h"
#include <utils/ClientFactory.h>
#include <utils/ClientFactory.h>
#include <utils/CommonUtils.h>
static
const
char
*
const
PUBSUBHOST
=
"zmqpubsub"
;
static
const
char
*
const
PUBSUBHOST
=
"zmqpubsub"
;
...
@@ -197,21 +198,67 @@ using json = nlohmann::json;
...
@@ -197,21 +198,67 @@ using json = nlohmann::json;
static
const
int
ITERATIONS
=
1000000
;
static
const
int
ITERATIONS
=
1000000
;
static
const
char
*
const
JSON_CONTENT
=
"{
\n
"
"
\"
success
\"
: true,
\n
"
"
\"
error
\"
: null,
\n
"
"
\"
objectNode
\"
: {
\n
"
"
\"
success
\"
: true,
\n
"
"
\"
error
\"
: null,
\n
"
"
\"
objectNode
\"
: {
\n
"
"
\"
num_results
\"
: 6,
\n
"
"
\"
query
\"
:
\"
base
\"
,
\n
"
"
\"
results
\"
: [
\n
"
" {
\n
"
"
\"
description
\"
: null,
\n
"
"
\"
name
\"
:
\"
amir/base-server-no-db
\"\n
"
" },
\n
"
" {
\n
"
"
\"
description
\"
: null,
\n
"
"
\"
name
\"
:
\"
amir/base-server-ui
\"\n
"
" },
\n
"
" {
\n
"
"
\"
description
\"
: null,
\n
"
"
\"
name
\"
:
\"
amir/base-server-db
\"\n
"
" },
\n
"
" {
\n
"
"
\"
description
\"
:
\"\"
,
\n
"
"
\"
name
\"
:
\"
ipgallery/base-ims
\"\n
"
" },
\n
"
" {
\n
"
"
\"
description
\"
:
\"\"
,
\n
"
"
\"
name
\"
:
\"
ipgallery/base-resin
\"\n
"
" },
\n
"
" {
\n
"
"
\"
description
\"
:
\"\"
,
\n
"
"
\"
name
\"
:
\"
ipgallery/base-microservice-java
\"\n
"
" }
\n
"
" ]
\n
"
" }
\n
"
" }
\n
"
"}"
;
static
const
char
*
const
SOURCE_CHANNEL
=
"ipc:///tmp/some-file.ipc"
;
static
const
char
*
const
URI
=
"/xxx/resource/subResource"
;
static
const
char
*
const
QUERY_STRING
=
"a=b&c=d&abba=sabba"
;
void
testRapidJson
()
{
void
testRapidJson
()
{
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
std
::
string
json
;
std
::
string
json
;
rapidjson
::
Document
rpj_Doc
;
// Null
rapidjson
::
Document
rpj_Doc
;
// Null
rapidjson
::
Document
::
AllocatorType
&
rpj_Alloc
=
rpj_Doc
.
GetAllocator
();
rapidjson
::
Document
::
AllocatorType
&
rpj_Alloc
=
rpj_Doc
.
GetAllocator
();
rpj_Doc
.
SetObject
();
rpj_Doc
.
SetObject
();
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"hello"
),
rapidjson
::
StringRef
(
"world"
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"source"
),
rapidjson
::
StringRef
(
SOURCE_CHANNEL
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"number"
),
rapidjson
::
Value
(
i
),
rpj_Alloc
);
//rpj_Doc.AddMember(rapidjson::StringRef("uri"), rapidjson::Value(i), rpj_Alloc);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"status"
),
true
,
rpj_Alloc
);
//rpj_Doc.AddMember(rapidjson::StringRef("status"), true, rpj_Alloc);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"hello1"
),
rapidjson
::
StringRef
(
"world"
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"uri"
),
rapidjson
::
StringRef
(
URI
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"number1"
),
rapidjson
::
Value
(
i
),
rpj_Alloc
);
//rpj_Doc.AddMember(rapidjson::StringRef("number1"), rapidjson::Value(i), rpj_Alloc);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"status1"
),
true
,
rpj_Alloc
);
//rpj_Doc.AddMember(rapidjson::StringRef("status1"), true, rpj_Alloc);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"hello2"
),
rapidjson
::
StringRef
(
"world"
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"queryString"
),
rapidjson
::
StringRef
(
QUERY_STRING
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"number2"
),
rapidjson
::
Value
(
i
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"content"
),
rapidjson
::
StringRef
(
JSON_CONTENT
),
rpj_Alloc
);
rpj_Doc
.
AddMember
(
rapidjson
::
StringRef
(
"status2"
),
true
,
rpj_Alloc
);
// rpj_Doc.AddMember(rapidjson::StringRef("number2"), rapidjson::Value(i), rpj_Alloc);
// rpj_Doc.AddMember(rapidjson::StringRef("status2"), true, rpj_Alloc);
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
rpj_Doc
.
Accept
(
writer
);
rpj_Doc
.
Accept
(
writer
);
...
@@ -223,31 +270,53 @@ void testNlohmanJson() {
...
@@ -223,31 +270,53 @@ void testNlohmanJson() {
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
std
::
string
jsonStr
;
std
::
string
jsonStr
;
json
j
;
json
j
;
j
.
emplace
(
"hello"
,
"world"
);
j
.
emplace
(
"source"
,
SOURCE_CHANNEL
);
j
.
emplace
(
"number"
,
i
);
j
.
emplace
(
"uri"
,
URI
);
j
.
emplace
(
"status"
,
true
);
j
.
emplace
(
"queryString"
,
QUERY_STRING
);
j
[
"hello1"
]
=
"world"
;
j
[
"content"
]
=
JSON_CONTENT
;
j
[
"number1"
]
=
i
;
j
[
"status1"
]
=
true
;
j
.
emplace
(
"hello2"
,
"world"
);
j
.
emplace
(
"number2"
,
i
);
j
.
emplace
(
"status2"
,
true
);
jsonStr
=
j
.
dump
();
jsonStr
=
j
.
dump
();
}
}
}
}
#define MAKE_STRING_PAIR(s1,s2) std::make_pair<std::string,std::string>(s1,s2)
void
testSerializations
()
{
using
ParamsMap
=
std
::
map
<
std
::
string
,
std
::
string
>
;
ParamsMap
paramsMap
;
const
char
*
strBuff
;
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
paramsMap
.
emplace
(
MAKE_STRING_PAIR
(
"source"
,
SOURCE_CHANNEL
));
paramsMap
.
emplace
(
MAKE_STRING_PAIR
(
"uri"
,
URI
));
paramsMap
.
emplace
(
MAKE_STRING_PAIR
(
"queryString"
,
QUERY_STRING
));
paramsMap
.
emplace
(
MAKE_STRING_PAIR
(
"content"
,
JSON_CONTENT
));
rapidjson
::
Document
doc
;
// Null
rapidjson
::
Document
::
AllocatorType
&
allocator
=
doc
.
GetAllocator
();
doc
.
SetObject
();
for
(
auto
&
pair
:
paramsMap
)
doc
.
AddMember
(
rapidjson
::
StringRef
(
pair
.
first
.
c_str
()),
rapidjson
::
StringRef
(
pair
.
second
.
c_str
()),
allocator
);
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
doc
.
Accept
(
writer
);
strBuff
=
buffer
.
GetString
();
}
}
void
testJsons
()
void
testJsons
()
{
{
std
::
time_t
now
=
std
::
time
(
nullptr
)
;
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with map serialization json took: "
<<
CommonUtils
::
measureFunc
<>
(
testSerializations
)
<<
"msec"
<<
'\n'
;
testRapidJson
();
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with rapid json took: "
<<
std
::
time
(
nullptr
)
-
now
<<
"msec"
<<
'\n'
;
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with rapid json took: "
<<
CommonUtils
::
measureFunc
<>
(
testRapidJson
)
<<
"msec"
<<
'\n'
;
if
(
false
or
not
true
){
if
(
false
or
not
true
){
}
}
// test json-nlohman
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with nlohman json took: "
<<
CommonUtils
::
measureFunc
<>
(
testNlohmanJson
)
<<
"msec"
<<
'\n'
;
now
=
std
::
time
(
nullptr
);
testNlohmanJson
();
std
::
cout
<<
" Testing "
<<
ITERATIONS
<<
" with nlohman json took: "
<<
std
::
time
(
nullptr
)
-
now
<<
"msec"
<<
'\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