2.客服端与服务端交互过程是异步的,只要一方写入channel另一方的channelRead方法就能获取到并执行,服务端的initChannel方法等待客户端请求之后才会开始执行handler。
3.我们将Rpc部分单独分离出来,服务端只需要引入netty-Rpc的maven,spring初始化的时候就会将maven引入的module扫描到并执行相应的初始化代码,这样一来可以实现解耦,Rpc部分分离出来,服务端只保留服务代码,引入Rpcmaven即可。客户端同理spring扫描引入的包即可。类似如下客户端代码引入consumer消费方maven,扫描consumer的包,spring加载时会进行初始化对加了@RemoteInvoke注解的类进行处理。(对接口中的方法进行动态代理拦截方法并执行Rpc)
@ComponentScan("com.netty")
@Controller
public class RemoteInvokeController {
public void test(){
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringServer.class);
UserService userservice = applicationContext.getBean(UserService.class);
userservice.getUser();
}
}
@Service
pulic class UserService{
@RemoteInvoke
private UserRemote userRemote;
public User getUser(){
User u = new User();
u.setId(1);
u.setName("张三");
Response response = userRemote.saveUser(u);
System.out.println(response);
}
}