BootNettyRpc is a open resource of rpc with netty and spring boot !
--oops--@Deprecated--
1.Add the dependency to your maven pom file.
<dependency>
<groupId>io.github.forezp</groupId>
<artifactId>boot-netty-rpc-core</artifactId>
<version>1.0.3</version>
</dependency>
2.Add @EnableNettyRpc annotation config to your project ,for example:
@SpringBootApplication
@EnableNettyRpc(basePackages = "com.forezp")
@RestController
public class ExampleRpcServerApplication {
public static void main(String[] args) {
SpringApplication.run( ExampleRpcServerApplication.class, args );
}
}
- config the netty server port in your springboot config file,like application.yml:
server:
port: 7001
netty.server.name: server
netty.server.port: 6001
- As a service provider ,expose the service to other client
@RpcClient(name = "server", rpcClz = "com.forezp.examplerpcserver.api.Greeting")
public interface IGreeting {
String sayHello(String name);
}
Implement the service:
@Service
public class Greeting implements IGreeting {
@Override
public String sayHello(String name) {
return "hi "+name;
}
}
1.Add the dependency to your maven pom file.
<dependency>
<groupId>io.github.forezp</groupId>
<artifactId>boot-netty-rpc-core</artifactId>
<version>1.0.3</version>
</dependency>
2.Add @EnableNettyRpc annotation config to your project ,for example:
@SpringBootApplication
@EnableNettyRpc(basePackages = "com.forezp")
@RestController
public class ExampleRpcClientApplication {
public static void main(String[] args) {
SpringApplication.run( ExampleRpcClientApplication.class, args );
}
}
- config the netty server port in your springboot config file,like application.yml:
netty:
clients:
- name: server
host: localhost
port: 6001
- name: server
host: localhost
port: 6001
4.comsume the provider service:
IGreeting invoker = (IGreeting) Invoker.invoke( IGreeting.class );
Object result = invoker.sayHello( "sww" );
If there is any problem, let me know. My email: [email protected]