Thrift项目实现

参考 https://my.oschina.net/wangmengjun/blog/910817

Maven工程结构

一共四个模块

thrift-rpc-interface

用来存放上一节thrift文件生成的代码

thrift-rpc-service

用来实现接口

thrift-rpc-server

简单的服务器

thrift-rpc-client

简单的客户端

service代码实现

package top.lilixin.thrift.service;

import org.apache.thrift.TException;

import java.util.logging.Logger;

/**
 * @Description TODO
 * @Author lilixin
 * @Date 2021/1/20 11:37 上午
 **/
public class GreetingServiceImpl implements GreetingService.Iface{
    private static final Logger logger =  Logger.getLogger(GreetingServiceImpl.class.getName());

    public String sayHello(String name) throws TException {
        logger.info(String.format("welcome to my world! name = {%s}", name));

        return "Hello, " + name;
    }
}

server代码实现

client代码实现

完整代码

https://github.com/lilixin/learning-thrift/tree/mainarrow-up-right

Last updated