netty实现高性能rpc服务器,GitHub - halolzh/forest: 基于netty轻量的高性能分布式RPC服务框架...

Forest

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d626c75652e737667

68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f64656d70655a68656e672f666f726573742f6d61737465722e7376673f6c6162656c3d4275696c64

Overview

基于netty轻量的高性能分布式RPC服务框架。简单,易用,高效。

Features

服务端支持多种序列化方式:fastjson,hession,kryo

服务端支持多种压缩方式:gzip,snappy

服务端支持同时基于jersey暴露restful服务

支持注解配置,也支持spring xml配置

支持服务发现服务注册

client端支持多种负载均衡策略和容灾策略

client内置连接池

client支持熔断,一个时间段错误次数达到一定阈值,自动熔断

基于netty 4.x版本实现,高性能(win 8cpu单机8w+)

Protocol

8f3d9e68ed397f8d094b67fa0be715c3.png

Quick Start

Add dependencies to pom.

com.zhizus

forest-rpc

0.0.2

com.zhizus

forest-common

0.0.2

1.定义接口

通过注解@ServiceProvider暴露服务,通过@MethodProvider暴露方法默认配置,如:压缩方式,序列化方式,客户端超时时间

@ServiceProvider(serviceName = "sampleService", haStrategyType = HaStrategyType.FAIL_FAST,

loadBalanceType = LoadBalanceType.RANDOM, connectionTimeout = Constants.CONNECTION_TIMEOUT)

public interface SampleService {

@MethodProvider(methodName = "say")

String say(String str);

@MethodProvider(methodName = "echo", serializeType = SerializeType.Hession2, compressType = CompressType.None)

String echo(String msg);

}

2.实现接口

基于注解@ServiceExport发布服务,基于注解 @MethodExport发布方法,

@Path("/sample")

@ServiceExport

public class SampleServiceImpl implements SampleService {

/**

* 支持jersey,可以通过配置打开,同时启动http服务

*

* @param str

* @return

*/

@Path("/hello/{str}")

@GET

@Produces("text/plain")

@MethodExport

@Rate(2)

@Override

public String say(@PathParam("str") String str) {

return "say " + str;

}

@Interceptor("metricInterceptor")

@MethodExport

@Override

public String echo(String msg) {

return "echo>>> " + msg;

}

}

3.服务端开发

spring context 配置:

application.xml

xmlns:context="http://www.springframework.org/schema/context"

xmlns="http://www.springframework.org/schema/beans" xmlns:forest="http://api.zhizus.com/schema/forest"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://api.zhizus.com/schema/forest http://api.zhizus.com/schema/forest.xsd">

Server开发

public class SampleServer {

public static void main(String[] args) throws Exception {

new ClassPathXmlApplicationContext(new String[]{"application.xml"});

}

}

4.客户端开发

xmlns:context="http://www.springframework.org/schema/context"

xmlns="http://www.springframework.org/schema/beans"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:forest="http://api.zhizus.com/schema/forest"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://api.zhizus.com/schema/forest http://api.zhizus.com/schema/forest.xsd">

ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"application-client.xml"});

SampleService bean = (SampleService) context.getBean("sampleService");

String test = bean.say("hello");

Console输出

23:10:10.295 [pool-1-thread-1] INFO MetricInterceptor 34 - methodName:/sampleService/say, current tps:83342, avgTime:0, maxTime:63, minTime:0

23:10:11.298 [pool-1-thread-1] INFO MetricInterceptor 34 - methodName:/sampleService/say, current tps:86271, avgTime:0, maxTime:63, minTime:0

23:10:12.295 [pool-1-thread-1] INFO MetricInterceptor 34 - methodName:/sampleService/say, current tps:86063, avgTime:0, maxTime:63, minTime:0

23:10:13.295 [pool-1-thread-1] INFO MetricInterceptor 34 - methodName:/sampleService/say, current tps:84305, avgTime:0, maxTime:63, minTime:0

Documents

TODO

跨语言协议支持

服务治理管理后台

License

Forest is released under the Apache License 2.0.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值