目录

0.参考链接

1.执行cmake_tars_server.sh脚本

2.进入build目录,执行cmake ..;make -j4;make HelloServer-tar;make HelloServer-upload

3.添加测试接口testHello

4.开发客户端

5.服务部署并进行相关配置

6.客户端测试

7.服务端端口查看


0.参考链接

官方参考链接

官方文档-总括

1.执行cmake_tars_server.sh脚本

[root@localhost tars]# /usr/local/tars/cpp/script/cmake_tars_server.sh TestApp HelloServer Hello
APP:TestApp, SERVER:HelloServer, SERVANT:Hello
[mkdir: HelloServer]
[create server: TestApp.HelloServer ...]
-- The C compiler identification is GNU 9.3.1
-- The CXX compiler identification is GNU 9.3.1
-- Check for working C compiler: /opt/rh/devtoolset-9/root/usr/bin/cc
-- Check for working C compiler: /opt/rh/devtoolset-9/root/usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /opt/rh/devtoolset-9/root/usr/bin/c++
-- Check for working CXX compiler: /opt/rh/devtoolset-9/root/usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-------------------------------------------------------------------------------------
CMAKE_SOURCE_DIR:          /usr/local/app/tars/HelloServer
CMAKE_BINARY_DIR:          /usr/local/app/tars/HelloServer/build
PROJECT_SOURCE_DIR:        /usr/local/app/tars/HelloServer
CMAKE_BUILD_TYPE:          Release
PLATFORM:                  linux
TARS2CPP:                  /usr/local/tars/cpp/tools/tars2cpp
TARSMERGE:                 /usr/local/tars/cpp/tools/tarsmerge
TARS_MYSQL:                ON
TARS_HTTP2:                OFF
TARS_SSL:                  OFF
TARS_WEB_HOST:             http://web.tars.com
TARS_TOKEN:
-------------------------------------------------------------------------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/app/tars/HelloServer/build
Scanning dependencies of target tars-HelloServer
[ 25%] /usr/local/tars/cpp/tools/tars2cpp  /usr/local/app/tars/HelloServer/src/Hello.tars
[ 25%] Built target tars-HelloServer
Scanning dependencies of target HelloServer
[ 50%] Building CXX object src/CMakeFiles/HelloServer.dir/HelloImp.cpp.o
[ 75%] Building CXX object src/CMakeFiles/HelloServer.dir/HelloServer.cpp.o
[100%] Linking CXX executable ../bin/HelloServer
[100%] Built target HelloServer
[done.]

These files already contain the basic service framework and the default test interface
implementation.We just need to fill in the code that reflects the logic of the program.
生成的这些文件已经包含了基础的服务框架和默认的测试接口实现,我们需要做的仅仅就是填充反应
程序逻辑的代码.

2.进入build目录,执行cmake ..;make -j4;make HelloServer-tar;make HelloServer-upload

3.添加测试接口testHello

You can modify Hello.tars and add function with the below commands:module TestApp
{interface Hello{int test();int testHello(string sReq, out string sRsp);};
};
Use /usr/local/tars/cpp/tools/tars2cpp hello.tars to recreate hello.h.
Next,modify HelloImp.h/HelloImp.cpp to implement the new interface code.In HelloImp.h, the testHello method of inheriting from the Hello class is:virtual int testHello(const std::string &sReq, std::string &sRsp,
tars::TarsCurrentPtr current);For HelloImp.cpp to implement testHello function:
int HelloImp::testHello(const std::string &sReq, std::string &sRsp,
tars::TarsCurrentPtr current)
{TLOGDEBUG("HelloImp::testHellosReq:"<<sReq<<endl);sRsp = sReq;return 0;
}
The make clean all;make;make tar command can recreate the HelloServer.tgz package.

至此,服务器端的开发就完成了.

4.开发客户端

mkdir -p /home/tarsproto/TestApp/HelloServer
mkdir -p /home/tarsproto/TestApp/HelloClient
将HelloServer下的Hello.h和Hello.cpp文件放到/home/tarsproto/TestApp/HelloClient下.

Makefile
----------------------------------------------------------------------
APP :=TestApp
TARGET :=TestHelloClient
CONFIG :=
STRIP_FLAG := N
INCLUDE += -I/home/tarsproto/TestApp/HelloServer/
LIB +=
#-----------------------------------------------------------------------
include /usr/local/tars/cpp/makefile/makefile.tars
#-----------------------------------------------------------------------
#include <iostream>
#include "servant/Communicator.h"
#include "Hello.h"
using namespace std;
using namespace TestApp;
using namespace tars;
int main(int argc,char ** argv)
{Communicator comm;try{HelloPrx prx;//comm.stringToProxy("TestApp.HelloServer.HelloObj@tcp -h 192.168.118.138 -p 15319" , prx);// 注意 "应用+服务名+对象" 要对应到注册的那个服务上comm.stringToProxy("tars.HelloServer.HelloObj@tcp -h 192.168.118.138 -p 15319" , prx);try{string sReq("hello world");string sRsp("");int iRet = prx->testHello(sReq, sRsp);cout<<"iRet:"<<iRet<<" sReq:"<<sReq<<" sRsp:"<<sRsp<<endl;}catch(exception &ex){cerr << "line 23 , ex:" << ex.what() << endl;}catch(...){cerr << "unknown exception." << endl;}}catch(exception& e){cerr << "exception:" << e.what() << endl;}catch (...){cerr << "unknown exception." << endl;}return 0;
}

5.服务部署并进行相关配置

"应用"指你的服务程序归在哪一个应用下,例如:"TestApp"或者图中的"tars";
"服务名称"指你的服务程序的标识名字,例如:"HelloServer";
"服务类型"指你的服务程序用什么语言写的,例如:c++的选择“tars_cpp”。
"模版"指你的服务程序在启动时,设置的配置文件的名称,默认用"tars.default"即可,也可以用对应想要的;
"节点"指服务部署的机器IP;
"Set分组"指设置服务的Set分组信息,Set信息包括3部分:Set名,Set地区,Set组名;
"OBJ名称"指Servant的名称;
"OBJ绑定IP"指服务绑定的机器IP,一般与节点一样;
"端口"指OBJ要绑定的端口;
"端口类型"指使用TCP还是UDP;
"协议"指应用层使用的通信协议,Tars框架默认使用tars协议;
"线程数"指业务处理线程的数目;
"最大连接数"指支持的最大连接数;
"队列最大长度"指请求接收队列的大小;
"队列超时时间"指请求接收队列的超时时间.

然后在服务列表中点击启动即可,如果一切正常,就可以正常启动.

6.客户端测试

至此,一个简单的hello world完成了.

7.服务端端口查看

netstat 命令当中的内部地址和外部地址

【TARS】用TarsCpp-创建第一个服务相关推荐

  1. 【TARS】TARS-CPP客户端学习二

    目录 0.测试代码路径与说明 1.helloworld客户端的线程情况 1.0 线程总体分布 1.1线程一(main线程) 1.2 线程二(StatReport线程) 1.3 线程三(TC_TimeP ...

  2. 使用模式创建一个面向服务的组件中间件

    引言 在本文中,您将了解面向服务的组件中间件在用于资源有限的语音设备时,在设计阶段所应用的模式.它涵盖了项目的问题上下文,并被看成是一组决定因素,是对相关体系结构远景的一个简要概括.您还会得到一份描述 ...

  3. linux创建的kvm无法运行,使用virt-manager运行虚拟机的方法(创建第一个虚拟机)...

    本文将指导你使用Fedora Linux上的Virt Manager来设置虚拟机,使用virt-manager运行虚拟机,我们来创建第一个虚拟机. 介绍QEMU/KVM和Libvirt 与所有其他Li ...

  4. Tomcat创建一个windows服务

    这段时间一直跟着团队忙着开发了两个小模块的系统,说实话功能并不怎么强大,不过总算是经过大家的努力第一阶段算是结束了.现在要给用户在服务器上部署,让用户体验,在体验的过程中提出需求,用于明年进行升级改进 ...

  5. vert.x_使用vert.x 2.0,RxJava和mongoDB创建simpe RESTful服务

    vert.x 中断了将近半年后发表了一篇新文章. 在本文中,我们将快速了解如何开始使用vert.x,更有趣的是,如何使用RxJava简化异步系统的编程. 我们将涵盖以下主题: 使用Maven创建一个空 ...

  6. 使用vert.x 2.0,RxJava和mongoDB创建simpe RESTful服务

    中断了将近半年后发表了一篇新文章. 在本文中,我们将快速了解如何开始使用vert.x,更有趣的是,如何使用RxJava简化异步系统的编程. 我们将涵盖以下主题: 使用Maven创建一个空的vert.x ...

  7. 服务器创建多个dhcp服务_如何在15分钟内创建无服务器服务

    服务器创建多个dhcp服务 by Charlee Li 通过李李 如何在15分钟内创建无服务器服务 (How to create a serverless service in 15 minutes) ...

  8. Django创建第一个应用

    Django创建第一个应用 1,创建应用 Django自带一个实用程序,可以自动生成应用程序的基本目录结构,因此您可以专注于编写代码而不是创建目录. 要创建您的应用程序,请确保您与目录位于同一目录,m ...

  9. python 创建一个空向量_Python之Django系列-创建第一个应用-5

    上一篇:Python之Django系列-创建第一个应用-4 这一章我们会讲到视图层怎么与数据库操作并返回数据到模板层进行渲染最终显示在页面上 投票应用基本上会有这么几个视图 问题列表页 问题详情页 问 ...

  10. VB.NET工作笔记008---vs2017创建使用WCF服务_并调用服务demo

    技术交流QQ群[JAVA,.NET,BigData,AI]:170933152 声明,找的例子,之前没有做过wcf,但是看了看例子感觉挺简单的,记一下吧 WCF的全称是Windows Communic ...

最新文章

  1. R语言CRAN软件包Meta分析
  2. Dalvik VM进程系统(二):分析Zygote的启动过程
  3. KubeDL 加入 CNCF Sandbox,加速 AI 产业云原生化
  4. 微软将中止支持 .NET Core 2.2,建议开发者升级至 .NET Core 3.1
  5. Eclipse中启动tomcat报错java.lang.OutOfMemoryError: PermGen space的解决方法
  6. 复习----使用链表实现队列(先进先出)及迭代
  7. python send 案例_python之pexpect实现自动交互的例子
  8. Nginx 反向代理解决跨域问题
  9. 饼状图改变数据显示位置_Tableau--饼图大作战
  10. 如何为Linux系统中的SSH添加双重认证
  11. 剑指offer题目系列一
  12. mysql8导入不同schme_新特性解读 | MySQL 8.0.22 任意格式数据导入
  13. 数据结构严蔚敏 栈基本操作 C语言实现
  14. 阿里云解析PrivateZone和云解析DNS的区别
  15. 有关Excel表格公式的方式进行前边数字排序,后边内容不变的方法。
  16. pyqt5 从本地选择图片 并显示在label上
  17. js中数组的entries方法
  18. Cutting (暴力 + 滚动哈希判字符串匹配)
  19. 破解flowplayer
  20. 科创板|龙软科技国科环宇等4公司中止审核

热门文章

  1. matlab猜数游戏
  2. jmeter“察看结果树”响应结果乱码
  3. ERROR: Timeout after 10 minutes ERROR: Error fetching remote repo 'origin'
  4. Sql Server数据库备份大全(Sql语句)
  5. 天行健,君子以自强不息!
  6. 算法学习之路和程序员(技术)学习必读书籍
  7. 人脸比对指标 -- 人脸相似度
  8. R语言学习——plot函数
  9. GCC编译器安装与下载
  10. 2022 iapp 云便签源码