Commit 22c972c4 by Amir Aharon

end of day: add libevent to develop image and some evpp code

parent 8ef5aa9c
......@@ -35,6 +35,7 @@
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"${workspaceRoot}/../3party",
"${workspaceRoot}/../3party/evpp/build-release/include",
"${workspaceRoot}/src"
],
"defines": [],
......
......@@ -32,7 +32,10 @@
{
"label": "clean",
"type": "shell",
"command": "docker exec -it devenv make clean"
"command": "docker exec -it devenv make clean",
"problemMatcher": [
"$gcc"
]
},
{
"label": "start-gdbserver",
......@@ -40,6 +43,13 @@
// not using -it so that it can be a preLaunchTask
"command": "docker exec -d devenv gdbserver :2000 bin/test_Microservice",
"problemMatcher": []
},
{
"label": "build develop image",
"type": "shell",
// not using -it so that it can be a preLaunchTask
"command": "docker build -t municipalitybank.com:5050/ipgallery.common.cpp/microservice/develop .",
"problemMatcher": []
}
]
}
\ No newline at end of file
......@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 2.8.12)
project(Microservice)
# version stuff
set (Microservice_VERSION_MAJOR 1)
set (Microservice_VERSION_MINOR 4)
set (Microservice_VERSION_PATCH 2)
set (Microservice_VERSION_MINOR 5)
set (Microservice_VERSION_PATCH 0)
set(Microservice_VERSION_STRING ${Microservice_VERSION_MAJOR}.${Microservice_VERSION_MINOR}.${Microservice_VERSION_PATCH})
# type build flags
......@@ -19,7 +19,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set ( PROJECT_LINK_LIBS -lPocoFoundation -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 -llog4cpp -lglog -lzmqpp -lzmq )
-lcrypto -llog4cpp -lglog -lzmqpp -lzmq -levpp -levent)
# set ( PROJECT_LINK_LIBS -lPocoFoundation -ljson -lhiredis -lcpprest -lcppmetrics -lboost_random -lboost_timer -lboost_chrono
# -lboost_system -lboost_thread -lboost_date_time -lboost_regex -lboost_filesystem -lpthread
......
## C++ Microservice Framework
## VERSIONS:
# 1.5.0
- add new rest server Evpp
# 1.4.2
- moving to municipalitybank.com cloud
# 1.4.1
......
......@@ -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 uuid-dev libzmqpp-dev libmhash-dev
\ No newline at end of file
libgoogle-glog-dev libboost-all-dev libssl-dev uuid-dev libzmqpp-dev libmhash-dev libevent-2.0
\ No newline at end of file
......@@ -4,9 +4,17 @@
static int s_sig_num = 0;
void run_thread(Microservice_IRestServerEvppImpl* pc_Obj)
{
pc_Obj->start();
void DefaultHandler(evpp::EventLoop* loop,
const evpp::http::ContextPtr& ctx,
const evpp::http::HTTPSendResponseCallback& cb) {
std::stringstream oss;
oss << "func=" << __FUNCTION__ << " OK"
<< " ip=" << ctx->remote_ip() << "\n"
<< " uri=" << ctx->uri() << "\n"
<< " body=" << ctx->body().ToString() << "\n";
ctx->AddResponseHeader("Content-Type", "application/octet-stream");
ctx->AddResponseHeader("Server", "evpp");
cb(oss.str());
}
static void signal_handler(int sig_num) {
......@@ -28,12 +36,23 @@ bool Microservice_IRestServerEvppImpl::build(std::string& appName, const std::ma
nsMicroservice_Iface::IMetricsFactory* p_metrics_factory){
bool result = false;
if (p_param_)
{
appName_.assign(appName);
p_logger_ = pc_Logger;
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
result = true;
}
return result;
}
void Microservice_IRestServerEvppImpl::registerService(nsMicroservice_Iface::IServiceDiscovery* pc_ServiceDiscovery,
std::string& id){
if (pc_ServiceDiscovery != nullptr)
pc_ServiceDiscovery->registerService(appName_, id, p_param_->getHost(), p_param_->getPort());
}
void Microservice_IRestServerEvppImpl::run(){
......@@ -48,5 +67,9 @@ void Microservice_IRestServerEvppImpl::stop(){
}
bool Microservice_IRestServerEvppImpl::init(){
p_server_ = new evpp::http::Server(p_param_->getWorkerThreadsNum());
p_server_->SetThreadDispatchPolicy(evpp::ThreadDispatchPolicy::kIPAddressHashing);
p_server_->RegisterDefaultHandler(&DefaultHandler);
return true;
}
\ No newline at end of file
......@@ -7,6 +7,77 @@
#include <thread>
#include <evpp/http/http_server.h>
class Microservice_IResponseRestEvppImpl: public nsMicroservice_Iface::IResponse
{
// for cloning
// Microservice_IResponseRestEvppImpl() :
// // p_respConnection_(p_respConnection),
// // respBuilder_(nsMicroservice_Constants::REQUEST_MSG_INITIAL_SIZE),
// rcid_(0)
// {}
//Evpppp::socket* p_respConnection_;
std::uint64_t rcid_;
public:
Microservice_IResponseRestEvppImpl() : rcid_(0) {}
void Send(const char* response) override {
// if (p_respConnection_) {
// /**
// * building restresponse msg
// */
// respBuilder_.Clear();
// auto restResponse = common::context::CreateRestResponseDirect(respBuilder_,rcid_,response);
// respBuilder_.Finish(restResponse);
// p_respConnection_->send_raw((const char *) respBuilder_.GetBufferPointer(), respBuilder_.GetSize(), Evpppp::socket::dont_wait);
// }
}
void Reset() override { /*p_respConnection_ = nullptr; */}
void setParams(/*Evpppp::socket *p_respConnection, */std::uint64_t rcid) {
//p_respConnection_ = p_respConnection;
rcid_ = rcid;
}
virtual nsMicroservice_Iface::IResponse *clone() override {
return new Microservice_IResponseRestEvppImpl();
}
};
class Microservice_IRequestRestEvppImpl: public nsMicroservice_Iface::IRequest {
public:
Microservice_IRequestRestEvppImpl() {}
const char *GetQueryString() override {
// if (p_restMsg_)
// return p_restMsg_->queryString()->c_str();
return nullptr;
}
const char *GetRelativePath() override {
// if (p_restMsg_)
// return p_restMsg_->url()->c_str();
return nullptr;
}
const char *GetContent() override {
// if (p_restMsg_)
// return p_restMsg_->content()->c_str();
return nullptr;
}
void Reset() override {
// p_restMsg_ = nullptr;
}
private:
};
class Microservice_IRestServerEvppImpl : public nsMicroservice_Iface::IRestServer , public nsMicroservice_Iface::IContainer {
public:
Microservice_IRestServerEvppImpl(cMicroservice_RestServerParams* p_param);
......@@ -32,6 +103,7 @@ private:
nsMicroservice_Iface::ILogger* p_logger_;
std::string serverType_;
cMicroservice_RestServerParams* p_param_;
std::string appName_;
// consts
static constexpr uint32_t SLEEP_INTERVAL = 1; //useconds
......
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