Coder Social home page Coder Social logo

houkx / nettythrift Goto Github PK

View Code? Open in Web Editor NEW
63.0 13.0 29.0 396 KB

Thrift on Netty, support TCP/HTTP/WebSocket at same port. support multiple Protocols at same time. multil Simple Clients with Connection Pool.

License: Apache License 2.0

Java 100.00%
netty netty-rpc thrift rpc

nettythrift's Introduction

nettythrift

en: A Java Server IO framework use netty and thrift. You could send thrift json protol Http-GET request with Broswer line google Chrome, or send compactProtocol thrift data with thrift client.

zh-CN: 一个 netty 服务端框架, 基于 thrift协议. 你可以通过chrome浏览器发送thrift json 协议的Http-GET 请求, 同时也可以使用thrift原生的的客户端发送压缩协议的数据.

项目经过了线上高并发的考验.

Server Example

 public void startServer() {
  // different from nify, This Server:
  // support TCP/HTTP/WebSocket At Same time.
  // support sync/async (notFrame or Frame) At Same time.
  // support TBinaryProtocol/TCompactProtocol/TJSONProtocol/TSimpleJSONProtocol At Same time.
  
  int port = 8081; // The port to bind.
  ExecutorService threadPoolExecutor = ... // business Executor
  
  // Create the handler, the interface impl
  MyService.Iface serviceInterface = new MyServiceHandler();

  //en: Create the processor, you no need give a TProtocolFactory here,the protocol is dynamic, same as the client.
  //zh-CN: 创建处理器, 你不需要指定一个TProtocolFactory, 协议是动态适应客户端的协议.
  // you could sen
  TBaseProcessor processor = new MyService.Processor<>(serviceInterface);

  ThriftServerDef serverDef = ThriftServerDef.newBuilder().listen(port)//
			.withProcessor(processor)//
			.using(threadPoolExecutor)//
			.clientIdleTimeout(TimeUnit.SECONDS.toMillis(60))//
			.build();
   ServerBootstrap server = new ServerBootstrap(serverDef);
   server.start();// Start Server
}

The Client

zh-CN: 你可以使用thrift原生客户端, 也可以使用这里的 client.* 项目,客户端项目主要适用于像app端这种追求依赖库尽可能小的场景.

en: you can use the orig thrift client, or this client.* project, the clients is used in android App Client Example: see the TestCase in project: io.nettythrift or the project client.* ;

the project "client.json" is A Client use Http and TSimpleJSONProtocol.

there is a also a Simple Connection Pool in project: client.framedCommpact

nettythrift's People

Contributors

hkx avatar houkx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nettythrift's Issues

io/ 业务分离

目前处理业务是在encode里面的。可以参考fb的nifty实现io/业务分离,有助于充分利用多核cpu的性能,又能降低排查故障的难度

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.