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
c0cf21cb
authored
Jun 16, 2020
by
Amir Aharon
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add MQTT client tested
parent
b0e131d8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
12 deletions
.vscode/settings.json
CMakeLists.txt
README.md
script/install-vcpkg-dependencies.sh
src/common/Microservice_Defines.h
src/impl/mqtt/MSIPubSubClientMqttImpl.cpp
src/impl/mqtt/MSIPubSubClientMqttImpl.h
.vscode/settings.json
View file @
c0cf21cb
...
@@ -52,7 +52,22 @@
...
@@ -52,7 +52,22 @@
"cinttypes"
:
"cpp"
,
"cinttypes"
:
"cpp"
,
"type_traits"
:
"cpp"
,
"type_traits"
:
"cpp"
,
"typeindex"
:
"cpp"
,
"typeindex"
:
"cpp"
,
"typeinfo"
:
"cpp"
"typeinfo"
:
"cpp"
,
"any"
:
"cpp"
,
"complex"
:
"cpp"
,
"list"
:
"cpp"
,
"algorithm"
:
"cpp"
,
"iterator"
:
"cpp"
,
"map"
:
"cpp"
,
"memory_resource"
:
"cpp"
,
"optional"
:
"cpp"
,
"random"
:
"cpp"
,
"set"
:
"cpp"
,
"string"
:
"cpp"
,
"string_view"
:
"cpp"
,
"cfenv"
:
"cpp"
,
"valarray"
:
"cpp"
,
"variant"
:
"cpp"
},
},
"cmake.configureOnOpen"
:
true
"cmake.configureOnOpen"
:
true
}
}
\ No newline at end of file
CMakeLists.txt
View file @
c0cf21cb
...
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0)
...
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0)
project
(
Microservice
)
project
(
Microservice
)
# version stuff
# version stuff
set
(
Microservice_VERSION_MAJOR 1
)
set
(
Microservice_VERSION_MAJOR 1
)
set
(
Microservice_VERSION_MINOR
6
)
set
(
Microservice_VERSION_MINOR
7
)
set
(
Microservice_VERSION_PATCH
1
)
set
(
Microservice_VERSION_PATCH
0
)
set
(
Microservice_VERSION_STRING
${
Microservice_VERSION_MAJOR
}
.
${
Microservice_VERSION_MINOR
}
.
${
Microservice_VERSION_PATCH
}
)
set
(
Microservice_VERSION_STRING
${
Microservice_VERSION_MAJOR
}
.
${
Microservice_VERSION_MINOR
}
.
${
Microservice_VERSION_PATCH
}
)
# type build flags
# type build flags
...
@@ -172,7 +172,7 @@ include(CPack)
...
@@ -172,7 +172,7 @@ include(CPack)
#gradle uploadArchives -Pcversion=[version] -Ppublish_file=[the gz file]
#gradle uploadArchives -Pcversion=[version] -Ppublish_file=[the gz file]
# install lib files
# install lib files
#
#
install
(
TARGETS Microservice MicroserviceRedis MicroserviceZmq DESTINATION lib
)
install
(
TARGETS Microservice MicroserviceRedis MicroserviceZmq
MicroserviceMqtt
DESTINATION lib
)
set
(
PUBLISH_FILE target/
${
CPACK_PACKAGE_FILE_NAME
}
-
${
CPACK_SYSTEM_NAME
}
.tar.gz
)
set
(
PUBLISH_FILE target/
${
CPACK_PACKAGE_FILE_NAME
}
-
${
CPACK_SYSTEM_NAME
}
.tar.gz
)
add_custom_target
(
publish COMMAND gradle uploadArchives -Pcversion=
${
Microservice_VERSION_STRING
}
-Ppublish_file=
${
PUBLISH_FILE
}
)
add_custom_target
(
publish COMMAND gradle uploadArchives -Pcversion=
${
Microservice_VERSION_STRING
}
-Ppublish_file=
${
PUBLISH_FILE
}
)
README.md
View file @
c0cf21cb
## C++ Microservice Framework
## C++ Microservice Framework
*
to create microservice docker run script/build_microservice_docker.sh
[
version
]
*
to create microservice docker run script/build_microservice_docker.sh
[
version
]
## VERSIONS:
## VERSIONS:
# 1.7.0
-
add MQTT client support
# 1.6.1
# 1.6.1
-
remove RabbitMQ for now, remove log4cpp, cpprestsdk
-
remove RabbitMQ for now, remove log4cpp, cpprestsdk
-
use stripped version off pplx (without cpprestsdk)
-
use stripped version off pplx (without cpprestsdk)
...
...
script/install-vcpkg-dependencies.sh
View file @
c0cf21cb
...
@@ -18,4 +18,4 @@ echo "Installing vcpkg packages..."
...
@@ -18,4 +18,4 @@ echo "Installing vcpkg packages..."
/home/vscode/vcpkg/vcpkg install evpp
\
/home/vscode/vcpkg/vcpkg install evpp
\
spdlog nlohmann-json cereal rapidjson flatbuffers poco
\
spdlog nlohmann-json cereal rapidjson flatbuffers poco
\
hiredis glog libuuid boost-foreach boost-chrono boost-thread
\
hiredis glog libuuid boost-foreach boost-chrono boost-thread
\
boost-asio boost-random
boost-asio boost-random
paho-mqtt
src/common/Microservice_Defines.h
View file @
c0cf21cb
...
@@ -65,6 +65,7 @@ namespace nsMicroservice_Constants
...
@@ -65,6 +65,7 @@ namespace nsMicroservice_Constants
static
const
std
::
string
RCID_HEADER
=
std
::
string
(
"X-RCID"
);
static
const
std
::
string
RCID_HEADER
=
std
::
string
(
"X-RCID"
);
static
const
char
*
FAILED_BUILD_URI
=
"Failed to build uri"
;
static
const
char
*
FAILED_BUILD_URI
=
"Failed to build uri"
;
static
const
int
CACHE_TIMEOUT
=
30000
;
static
const
int
CACHE_TIMEOUT
=
30000
;
static
const
int
CLOSE_WAIT_MSEC
=
1000
;
}
}
/*
/*
...
...
src/impl/mqtt/MSIPubSubClientMqttImpl.cpp
View file @
c0cf21cb
This diff is collapsed.
Click to expand it.
src/impl/mqtt/MSIPubSubClientMqttImpl.h
View file @
c0cf21cb
...
@@ -10,7 +10,8 @@
...
@@ -10,7 +10,8 @@
#include <thread>
#include <thread>
#include <queue>
#include <queue>
#include <common/Microservice_PubSubContext.h>
#include <common/Microservice_PubSubContext.h>
#include <paho-mqtt/MQTTClient.h>
// #include <paho-mqtt/MQTTClient.h>
#include <paho-mqtt/MQTTAsync.h>
namespace
evpp
{
namespace
evpp
{
class
EventLoop
;
class
EventLoop
;
...
@@ -38,25 +39,39 @@ public:
...
@@ -38,25 +39,39 @@ public:
virtual
void
subscribe
(
std
::
string
&
topic
,
OnMessageCallback
msgCllback
,
OnErrorCallback
errorCallback
)
override
;
virtual
void
subscribe
(
std
::
string
&
topic
,
OnMessageCallback
msgCllback
,
OnErrorCallback
errorCallback
)
override
;
virtual
void
unsubscribe
(
std
::
string
&
topic
)
override
;
virtual
void
unsubscribe
(
std
::
string
&
topic
)
override
;
void
Delivered
(
MQTTClient_deliveryToken
dt
);
// callback section
int
OnMessage
(
char
*
topicName
,
int
topicLen
,
MQTTClient
_message
*
message
);
void
OnMessage
(
char
*
topicName
,
int
topicLen
,
MQTTAsync
_message
*
message
);
void
ConnectionLost
(
char
*
cause
);
void
ConnectionLost
(
char
*
cause
);
std
::
string
getTopicNoWildcards
(
std
::
string
&
topic
);
void
OnDelivered
(
MQTTAsync_token
dt
);
void
OnConnected
(
char
*
cause
);
void
OnSubscribe
(
MQTTAsync_successData
*
response
);
void
OnSubscribeFailure
(
MQTTAsync_failureData
*
response
);
void
OnPublishFailure
(
MQTTAsync_failureData
*
response
);
void
OnConnectFailure
(
MQTTAsync_failureData
*
response
);
void
OnDisconnected
();
private
:
private
:
std
::
string
GetTopicNoWildcards
(
std
::
string
&
topic
);
std
::
string
GetAddress
();
std
::
string
GetAddress
();
void
CloseConnection
();
void
CloseConnection
();
void
Connect
();
void
connect
();
void
InitSubscribeParams
();
void
InitPublishParams
();
private
:
private
:
Microservice_MqttBrokerParams
params_
;
Microservice_MqttBrokerParams
params_
;
MQTTClient
client_
;
MQTTAsync
client_
;
MQTTClient_connectOptions
conn_opts_
;
// = MQTTClient_connectOptions_initializer;
MQTTAsync_connectOptions
conn_opts_
;
// = MQTTAsync_connectOptions_initializer;
MQTTAsync_responseOptions
subRespOpts_
;
MQTTAsync_responseOptions
pubRespOpts_
;
nsMicroservice_Iface
::
ILogger
*
p_logger_
;
nsMicroservice_Iface
::
ILogger
*
p_logger_
;
std
::
unordered_map
<
std
::
string
,
Item
>
items_map_
;
std
::
unordered_map
<
std
::
string
,
Item
>
items_map_
;
std
::
mutex
queue_lock_
;
std
::
mutex
queue_lock_
;
std
::
mutex
closeMutex_
;
std
::
condition_variable
closeCondition_
;
evpp
::
EventLoop
*
p_loop_
;
evpp
::
EventLoop
*
p_loop_
;
std
::
thread
*
p_loopThread_
;
std
::
thread
*
p_loopThread_
;
...
...
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