sogou workflow 实践

最近 sogou开源的workflow项目在github上得到了很大的关注,抱着学习的心态研究一下。https://github.com/sogou/workflow

一、编译安装

git clone --recursive https://github.com/sogou/workflow.git
cd workflow
./configure #在workflow目录下创建build文件夹,整个是用cmake来编译的。
cd build
make #编译成功在workflow目录下生成两个文件夹_include _lib

编译还是非常方便的,只需要依赖OpenSSL>=1.1

二、搭建一个简单的服务端程序

/*
 * @Author: Lei Jiang
 * @Email: [email protected]
 * @Date: 2020-10-30 15:53:26
 * @Description: code description
 */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include "workflow/HttpMessage.h"
#include "workflow/HttpUtil.h"
#include "workflow/WFServer.h"
#include "workflow/WFHttpServer.h"
#include "workflow/WFFacilities.h"

#include 
using namespace std;

static WFFacilities::WaitGroup wait_group(1);

void process(WFHttpTask *server_task)
{
    cout << "get one post" << endl;
    protocol::HttpResponse *resp = server_task->get_resp();
    string res_content = "fuck you baby";
    resp->append_output_body(res_content.c_str(),res_content.size());
    resp->set_status_code("200");
}

int main(int argc, char **argv)
{
    unsigned short port;
    if (argc != 2)
    {
        cerr << "USAGE:" << argv[0] << " 8080" << endl;
        exit(1);
    }
    WFHttpServer server_obj(process);
    port = atoi(argv[1]);
    if (server_obj.start(port) == 0)
    {
        cout << "server start ok" << endl;
        wait_group.wait();
        server_obj.stop();
    }
    else
    {
        cout << "start server occurs problem" << endl;
    }

    return 0;
}

测试通过,简单易使用。

你可能感兴趣的:(sogou workflow 实践)