Commit 8468cd1b by Amir Aharon

testing Evpp client and server async

parent 88a45474
......@@ -89,6 +89,7 @@ struct ClientAsyncTaskParamsFactory
static ClientAsyncTaskParamsPtr CreateMsgQAsyncTask(IResponse* p_IResponse, IContainer* p_IContainer) {
return std::make_shared<ClientAsyncTaskParams>(p_IResponse,p_IContainer,ClientAsyncTaskParams::eMsgQ);
}
};
class cMicroservice_Client {
......
......@@ -8,8 +8,8 @@
#include <evpp/http/http_server.h>
struct EvppConnParams {
const evpp::http::ContextPtr& ctx_;
const evpp::http::HTTPSendResponseCallback& cb_;
const evpp::http::ContextPtr ctx_;
const evpp::http::HTTPSendResponseCallback cb_;
EvppConnParams(const evpp::http::ContextPtr& ctx, const evpp::http::HTTPSendResponseCallback& cb) :
ctx_(ctx),cb_(cb) {}
......
......@@ -109,14 +109,47 @@ public:
rpj_Doc.AddMember(rapidjson::StringRef(it->first.c_str()),rapidjson::StringRef(dequeIt->c_str()),rpj_Alloc);
}
}
ReadSync(pc_reqCtx);
ReadAsyncEvpp(pc_reqCtx);
//ReadSync(pc_reqCtx);
// ReadAsync2(pc_reqCtx);
//this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
// this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
// add metric
long value = rand() % 1000 + 1;
p_histo->update(value);
}
void ReadAsyncEvpp(cMicroservice_RequestContext *pc_reqCtx) {
std::string body = "This is expected to be sent back as part of response body.";
auto p_msClient = ClientFactory::createEvppCommandImpl("evpp-test");
std::map<std::string,std::string> headers;
headers["Content-Type"] = "application/json";
//std::string uri = "http://echo.jpillora.com";
std::string uri = "https://postman-echo.com";
auto clientAsyncTaskParamsPtr = ClientAsyncTaskParamsFactory::CreateCommndParamsAsyncTask(pc_reqCtx->mpti_Response,
pc_reqCtx->mpti_Container);
MSCommandParams msCmndParams;
msCmndParams.WithEntity(uri)
.WithRequestParams("q=base")
.WithHeadersMap(&headers)
.WithContent(body);
msCmndParams.WithParamsString("post");
p_msClient->AsyncCreate(&msCmndParams, [clientAsyncTaskParamsPtr](cMicroservice_BaseRestResponse* p_baseRestResponse){
if(p_baseRestResponse->IsSuccess()){
clientAsyncTaskParamsPtr->p_IContainer_->WriteObjectToResponse(
clientAsyncTaskParamsPtr->p_IResponse_.get(),
p_baseRestResponse->GetObjectNode());
} else {
clientAsyncTaskParamsPtr->p_IContainer_->SendErrorResp(
clientAsyncTaskParamsPtr->p_IResponse_.get(),
p_baseRestResponse->GetError());
}
});
}
void ReadSync(cMicroservice_RequestContext *pc_reqCtx) {
Microservice_RestResponse rest_response;
std::map<std::string,std::string> headers;
......
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