Commit c0cf21cb by Amir Aharon

add MQTT client tested

parent b0e131d8
......@@ -52,7 +52,22 @@
"cinttypes": "cpp",
"type_traits": "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
}
\ No newline at end of file
......@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0)
project(Microservice)
# version stuff
set (Microservice_VERSION_MAJOR 1)
set (Microservice_VERSION_MINOR 6)
set (Microservice_VERSION_PATCH 1)
set (Microservice_VERSION_MINOR 7)
set (Microservice_VERSION_PATCH 0)
set(Microservice_VERSION_STRING ${Microservice_VERSION_MAJOR}.${Microservice_VERSION_MINOR}.${Microservice_VERSION_PATCH})
# type build flags
......@@ -172,7 +172,7 @@ include(CPack)
#gradle uploadArchives -Pcversion=[version] -Ppublish_file=[the gz file]
# 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)
add_custom_target(publish COMMAND gradle uploadArchives -Pcversion=${Microservice_VERSION_STRING} -Ppublish_file=${PUBLISH_FILE})
## C++ Microservice Framework
* to create microservice docker run script/build_microservice_docker.sh [version]
## VERSIONS:
# 1.7.0
- add MQTT client support
# 1.6.1
- remove RabbitMQ for now, remove log4cpp, cpprestsdk
- use stripped version off pplx (without cpprestsdk)
......
......@@ -18,4 +18,4 @@ echo "Installing vcpkg packages..."
/home/vscode/vcpkg/vcpkg install evpp \
spdlog nlohmann-json cereal rapidjson flatbuffers poco \
hiredis glog libuuid boost-foreach boost-chrono boost-thread \
boost-asio boost-random
boost-asio boost-random paho-mqtt
......@@ -65,6 +65,7 @@ namespace nsMicroservice_Constants
static const std::string RCID_HEADER = std::string("X-RCID");
static const char* FAILED_BUILD_URI = "Failed to build uri";
static const int CACHE_TIMEOUT = 30000;
static const int CLOSE_WAIT_MSEC = 1000;
}
/*
......
......@@ -10,7 +10,8 @@
#include <thread>
#include <queue>
#include <common/Microservice_PubSubContext.h>
#include <paho-mqtt/MQTTClient.h>
// #include <paho-mqtt/MQTTClient.h>
#include <paho-mqtt/MQTTAsync.h>
namespace evpp {
class EventLoop;
......@@ -38,25 +39,39 @@ public:
virtual void subscribe(std::string &topic, OnMessageCallback msgCllback, OnErrorCallback errorCallback) override;
virtual void unsubscribe(std::string &topic) override;
void Delivered(MQTTClient_deliveryToken dt);
int OnMessage(char *topicName, int topicLen, MQTTClient_message *message);
// callback section
void OnMessage(char *topicName, int topicLen, MQTTAsync_message *message);
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:
std::string GetTopicNoWildcards(std::string &topic);
std::string GetAddress();
void CloseConnection();
void Connect();
void connect();
void InitSubscribeParams();
void InitPublishParams();
private:
Microservice_MqttBrokerParams params_;
MQTTClient client_;
MQTTClient_connectOptions conn_opts_;// = MQTTClient_connectOptions_initializer;
MQTTAsync client_;
MQTTAsync_connectOptions conn_opts_;// = MQTTAsync_connectOptions_initializer;
MQTTAsync_responseOptions subRespOpts_;
MQTTAsync_responseOptions pubRespOpts_;
nsMicroservice_Iface::ILogger* p_logger_;
std::unordered_map<std::string,Item> items_map_;
std::mutex queue_lock_;
std::mutex closeMutex_;
std::condition_variable closeCondition_;
evpp::EventLoop* p_loop_;
std::thread* p_loopThread_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment