Define and implement a NettyRpc service
masterTo create a service in NettyRpc, first define a standard Java interface. Then, implement that interface using the @NettyRpcService annotation. This annotation allows you to specify the interface class and a service version for versioning support.
// 1. Define the interface
public interface HelloService {
String hello(String name);
String hello(Person person);
}
// 2. Implement with @NettyRpcService
@NettyRpcService(HelloService.class, version = "1.0")
public class HelloServiceImpl implements HelloService {
public HelloServiceImpl(){}
@Override
public String hello(String name) {
return "Hello " + name;
}
@Override
public String hello(Person person) {
return "Hello " + person.getFirstName() + " " + person.getLastName();
}
}