sogou workflow 實踐

最近 sogou開源的workflow項目在github上得到了很大的關(guān)注,抱著學(xué)習(xí)的心態(tài)研究一下。https://github.com/sogou/workflow

一、編譯安裝

git clone --recursive https://github.com/sogou/workflow.git
cd workflow
./configure #在workflow目錄下創(chuàng)建build文件夾,整個是用cmake來編譯的。
cd build
make #編譯成功在workflow目錄下生成兩個文件夾_include _lib

編譯還是非常方便的,只需要依賴OpenSSL>=1.1

二、搭建一個簡單的服務(wù)端程序

/*
 * @Author: Lei Jiang
 * @Email: leijiang420@163.com
 * @Date: 2020-10-30 15:53:26
 * @Description: code description
 */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <string>

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

#include <iostream>
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;
}

測試通過,簡單易使用。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容