为了账号安全,请及时绑定邮箱和手机立即绑定

BootNettyRpc:采用 Netty 实现的 RPC 框架

标签:
JavaScript


什么是 BootNettyRpc?
BootNettyRpc 是一个采用Netty实现的Rpc框架,适用于Spring Boot项目,支持Spring Cloud。 目前支持的版本为Spring Boot 1.5.x,Spring Cloud版本为D和E版本。

怎么使用?
分为本地启动和结合Spring Cloud启动。具体见example 案例,现在以本地案例来说明,Spring Cloud案例省略。

BootNettyRpc 包括Server端和Client端。

Server端
在pom文件中加上依赖:

<dependency>
<groupId>io.github.forezp</groupId>
<artifactId>boot-netty-rpc-core</artifactId>
<version>1.0.5</version>
</dependency>
在Spring Boot启动工程加上注解@EnableNettyRpc,需要开启包扫描,不填也可以,会全局扫描,有一点影响启动速度,比如例子中的ExampleRpcServerApplication:

@SpringBootApplication
@EnableNettyRpc(basePackages = "com.forezp")
public class ExampleRpcServerApplication {

public static void main(String[] args) {    SpringApplication.run( ExampleRpcServerApplication.class, args );}

}
在配置文件配置Netty Server的端口和Netty Server的name,该name会作client端的调用的name。

server:
port: 7001

netty.server.name: server
netty.server.port: 6001
写一个服务,接口如下:

public interface IGreeting {

String sayHello(String name);

}
实现类如下:

@Service
public class Greeting implements IGreeting {@Override

<dependency>
<groupId>io.github.forezp</groupId>
<artifactId>boot-netty-rpc-core</artifactId>
<version>1.0.5</version>
</dependency>
在SpringBoot的启动类加上@EnableNettyRpc注解,如下:

@Override
br/>@RestController<br <="" a="">public class ExampleRpcClientApplication {

@RestController
}@Autowired

Object object = greeting.sayHello( "hi" );
联系我
如果有任何问题和建议,请联系我,我的邮箱 miles02@163.com

已经实现的功能
rpc(实现同步、异步调用)
负载均衡
接口线程池隔离
接入Eureka
接入链路追踪
接入监控
接入报警邮箱
优化rpc性能 (需持续优化)
未来计划
接入多种序列化,做到可配置
自定义协议,trace的index不需要指定
接入consule
支持spring boot 2.0 Spring Cloud F

@Autowired<br/" rel="nofollow">

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消