kbms
kbms copied to clipboard
一个轻量级c++网络框架
trafficstars
ke-bear-microservice(kbms)
Introduction 中文说明
KBMS is a C++11 high performance network framework based on libevent. It is light and easy to deploy. At present, it mainly supports HTTP protocol.
Features
- Non-blocking pure asynchronous multithreaded HTTP server
- Light and concise
- Simple function, focus on Network
- Simple and easy to deploy
Origin
In the process of practice, the service enabling group of our AI center mainly provides external functions in the form of micro services, so we need a convenient and concise network framework. In the process of investigating open source projects, we did not find a suitable library to meet our requirements. According to our own business situation, the ideal C + + network framework should meet the following characteristics:
- Due to the historical tradition of the group, the best is C++
- Multi thread, high performance network server
- Handy and easy to deploy
- Can access to spring-cloud-netflix
Getting Started
Please see Quick Start
Examples
An echo HTTP server
#include "http_server.h"
int main(int argc, char* argv[]) {
uint32_t port = 12138;
uint32_t thread_num = 5;
if(!kbms::HttpServer::Instance()->Init(port,thread_num)){
std::cerr<<"initalize global resource failed."<<std::endl;
return 0;
}
kbms::HttpServer::Instance()->RegisterDefaultFun(&DefaultHandler);
kbms::HttpServer::Instance()->RegisterFun("/echo",[](const kbms::HttpContextPtr& ctx,const kbms::HTTPSendResponseCallback& cb)
{ cb(ctx->BodyByString()); });
kbms::HttpServer::Instance()->StartServer();
while (true) {
usleep(1);
}
return 0;
}
More examples
Please see the source code in examples.