### Implement RPC Service with @NettyRpcService Annotation in Java Source: https://github.com/luxiaoxun/nettyrpc/blob/master/README.md This snippet shows how to implement the `HelloService` interface. The `@NettyRpcService` annotation marks the class as an RPC service, specifying the interface and version. It includes implementations for both `hello` methods, demonstrating the server-side service logic. ```Java @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(); } } ``` -------------------------------- ### Call RPC Service Using RpcClient in Java Source: https://github.com/luxiaoxun/nettyrpc/blob/master/README.md This snippet demonstrates how to call an RPC service using the `RpcClient`. It illustrates both synchronous and asynchronous call patterns, including service creation and retrieving results, showcasing client-side service consumption. ```Java final RpcClient rpcClient = new RpcClient("127.0.0.1:2181"); // Sync call HelloService helloService = rpcClient.createService(HelloService.class, "1.0"); String result = helloService.hello("World"); // Async call RpcService client = rpcClient.createAsyncService(HelloService.class, "2.0"); RPCFuture helloFuture = client.call("hello", "World"); String result = (String) helloFuture.get(3000, TimeUnit.MILLISECONDS); ``` -------------------------------- ### Define RPC Service Interface in Java Source: https://github.com/luxiaoxun/nettyrpc/blob/master/README.md This snippet defines a simple Java interface `HelloService` with two overloaded `hello` methods, demonstrating the contract for RPC services that can be exposed via NettyRpc. ```Java public interface HelloService { String hello(String name); String hello(Person person); } ``` -------------------------------- ### Inject RPC Service with @RpcAutowired Annotation in Java Source: https://github.com/luxiaoxun/nettyrpc/blob/master/README.md This snippet illustrates how to inject RPC services into a class using the `@RpcAutowired` annotation. It demonstrates injecting different versions of the same service, simplifying client-side service consumption by automatically wiring the RPC proxy. ```Java public class Baz implements Foo { @RpcAutowired(version = "1.0") private HelloService helloService1; @RpcAutowired(version = "2.0") private HelloService helloService2; @Override public String say(String s) { return helloService1.hello(s); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.