Commit e0cb4bb9 by amir

start working on feature

parent 7b356122
...@@ -18,7 +18,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) ...@@ -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 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_system -lboost_thread -lboost_date_time -lboost_regex -lboost_filesystem -lpthread
-lboost_random -lboost_chrono -lboost_system -lboost_thread -lssl -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( ../3party/lib )
link_directories( ../internals/lib ) link_directories( ../internals/lib )
...@@ -31,12 +31,13 @@ include_directories(SYSTEM ../3party/cpprest/Release/include) ...@@ -31,12 +31,13 @@ include_directories(SYSTEM ../3party/cpprest/Release/include)
include_directories(SYSTEM ../3party/rabbitmq) include_directories(SYSTEM ../3party/rabbitmq)
include_directories(SYSTEM ../internals/include/Rabbitmq) include_directories(SYSTEM ../internals/include/Rabbitmq)
include_directories(SYSTEM /usr/include/hiredis) include_directories(SYSTEM /usr/include/hiredis)
include_directories(SYSTEM ../3party/czmq-4.0.0/include)
# recursive search files cpp files # recursive search files cpp files
file(GLOB_RECURSE SOURCES "src/*.cpp") file(GLOB_RECURSE SOURCES "src/*.cpp")
set (3PARTY_SOURCES ../3party/mongoose/mongoose.c) set (3PARTY_SOURCES ../3party/mongoose/mongoose.c)
#Generate the shared library from the sources #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} ) target_link_libraries(Microservice ${PROJECT_LINK_LIBS} )
set_target_properties(Microservice PROPERTIES VERSION ${Microservice_VERSION_STRING} set_target_properties(Microservice PROPERTIES VERSION ${Microservice_VERSION_STRING}
SOVERSION ${Microservice_VERSION_MAJOR}) SOVERSION ${Microservice_VERSION_MAJOR})
......
...@@ -6,4 +6,4 @@ ...@@ -6,4 +6,4 @@
# Created on May 8, 2016, 9:59:18 AM # Created on May 8, 2016, 9:59:18 AM
# #
sudo apt-get install -y libhiredis0.10 libhiredis-dev libzmq3 libzmq3-dev liblog4cpp5 liblog4cpp5-dev \ sudo apt-get install -y libhiredis0.10 libhiredis-dev libzmq3 libzmq3-dev liblog4cpp5 liblog4cpp5-dev \
libgoogle-glog-dev libboost-all-dev libssl-dev libgoogle-glog-dev libboost-all-dev libssl-dev uuid-dev libpcre3-dev valgrind
\ No newline at end of file \ No newline at end of file
...@@ -27,6 +27,12 @@ class cMicroservice_BaseHandler; ...@@ -27,6 +27,12 @@ class cMicroservice_BaseHandler;
namespace nsMicroservice_Iface namespace nsMicroservice_Iface
{ {
///////////////////// BASE INTERFACES //////////////////////
struct IServer {};
struct IClient {};
////////////////////////////////////////////////////////////
struct INotifyCallback struct INotifyCallback
{ {
virtual void onMessage(std::string& t_Topic, std::string& t_Message) = 0; virtual void onMessage(std::string& t_Topic, std::string& t_Message) = 0;
...@@ -68,30 +74,17 @@ namespace nsMicroservice_Iface ...@@ -68,30 +74,17 @@ namespace nsMicroservice_Iface
virtual void setLevel(cMicroservice_Enums::eLogLevel level) = 0; virtual void setLevel(cMicroservice_Enums::eLogLevel level) = 0;
}; };
struct ICommandClient struct ICommandClient : public IClient
{ {
ILogger* p_logger_; ILogger* p_logger_;
public: public:
/**
/* * the create/post of CRUD
public abstract class Command extends HystrixCommand<BaseRestResponse> { * @param p_cmd_params
protected MSCommandParams* p_cmd_params = null; * @param p_response
* @return
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; virtual MSRetStat Create(MSCommandParams* p_cmd_params, cMicroservice_BaseRestResponse* p_response) = 0;
/** /**
* the read/get of CRUD * the read/get of CRUD
* @param reqCtx * @param reqCtx
...@@ -161,6 +154,29 @@ namespace nsMicroservice_Iface ...@@ -161,6 +154,29 @@ namespace nsMicroservice_Iface
virtual void GetMetrics(std::map<std::string,long>& metrics_map) = 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;
/**
*
* @param topic
*/
virtual void unsubscribe(std::string& topic) = 0;
};
struct IPubSubClient : public IClient
{
virtual void publish(std::string& topic, std::string& message) = 0;
};
struct IPubSub struct IPubSub
{ {
/** /**
...@@ -186,7 +202,7 @@ namespace nsMicroservice_Iface ...@@ -186,7 +202,7 @@ namespace nsMicroservice_Iface
virtual IConfigurationProvider& getConfigurationProvider() = 0; virtual IConfigurationProvider& getConfigurationProvider() = 0;
}; };
struct IRestServer struct IRestServer : public IServer
{ {
public: public:
virtual bool build(std::string& appName, virtual bool build(std::string& appName,
...@@ -199,7 +215,7 @@ namespace nsMicroservice_Iface ...@@ -199,7 +215,7 @@ namespace nsMicroservice_Iface
virtual void registerService(IServiceDiscovery* pc_ServiceDiscovery, std::string& id) = 0; virtual void registerService(IServiceDiscovery* pc_ServiceDiscovery, std::string& id) = 0;
}; };
struct IRequest struct IRequest
{ {
public: public:
virtual ~IRequest() {}; virtual ~IRequest() {};
...@@ -256,7 +272,7 @@ struct IRequest ...@@ -256,7 +272,7 @@ struct IRequest
*/ */
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 * subscribing to specific topic
* @param topic * @param topic
...@@ -276,7 +292,6 @@ struct IRequest ...@@ -276,7 +292,6 @@ struct IRequest
* @param messageNode * @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
...@@ -297,6 +312,23 @@ struct IRequest ...@@ -297,6 +312,23 @@ struct IRequest
virtual bool exists(std::string& key) = 0; virtual bool exists(std::string& key) = 0;
}; };
struct IMsgQueueServer : public IServer
{
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;
};
} }
......
...@@ -29,6 +29,7 @@ private: ...@@ -29,6 +29,7 @@ private:
cMicroservice_BaseHandler* mpc_Handler; cMicroservice_BaseHandler* mpc_Handler;
nsMicroservice_Iface::ILogger* mpc_Logger; nsMicroservice_Iface::ILogger* mpc_Logger;
nsMicroservice_Iface::IPubSub* mpc_PubSub; nsMicroservice_Iface::IPubSub* mpc_PubSub;
cMicroservice_RequestContext* mpc_RequestContext; cMicroservice_RequestContext* mpc_RequestContext;
char mba_Buff[nsMicroservice_Constants::MAX_URI_LENGTH]; char mba_Buff[nsMicroservice_Constants::MAX_URI_LENGTH];
char mba_ErrorBuff[nsMicroservice_Constants::MAX_ERROR_BUFF_URI_LENGTH]; char mba_ErrorBuff[nsMicroservice_Constants::MAX_ERROR_BUFF_URI_LENGTH];
......
//
// 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();
}
//
// 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
...@@ -36,12 +36,16 @@ public: ...@@ -36,12 +36,16 @@ public:
} }
void DoCreate(cMicroservice_RequestContext* pc_reqCtx) void DoCreate(cMicroservice_RequestContext* pc_reqCtx)
{ {
if (pc_reqCtx->mc_QueryParameters.empty())
CreateSync(pc_reqCtx);
else {
rapidjson::Document rpj_Doc; rapidjson::Document rpj_Doc;
if (this->ReadObjectFromRequest(pc_reqCtx,rpj_Doc) ) if (this->ReadObjectFromRequest(pc_reqCtx,rpj_Doc) )
this->WriteObjectToResponse(pc_reqCtx,rpj_Doc); this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
else else
this->SendErrorResp(pc_reqCtx,"Error in parsing json"); this->SendErrorResp(pc_reqCtx,"Error in parsing json");
} }
}
void DoRead(cMicroservice_RequestContext* pc_reqCtx) void DoRead(cMicroservice_RequestContext* pc_reqCtx)
{ {
...@@ -85,6 +89,25 @@ public: ...@@ -85,6 +89,25 @@ public:
SendErrorResp(pc_reqCtx, retstat.GetError()); 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) void DoUpdate(cMicroservice_RequestContext* pc_reqCtx)
{ {
} }
......
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