目前RSF存在的问题:
2.不支持多语言客户端。这个是体力活,如果去支持的话RSF是可以做到的。因为RSF传输协议是自有的传输协议,多语言要解决的只有序列化的问题。
例子:
Server端:
RsfBootstrap bootstrap = new RsfBootstrap(); bootstrap.doBinder(new RsfStart() { public void onBind(RsfBinder rsfBinder) throws Throwable { rsfBinder.rsfService(EchoService.class, new EchoServiceImpl()).register(); } }).socketBind(8001); RsfContext rsfContext = bootstrap.sync();
客户端:
//1.使用 RSF 引导程序创建 RSF。 RsfBootstrap bootstrap = new RsfBootstrap(); bootstrap.doBinder(new RsfStart() { public void onBind(RsfBinder rsfBinder) throws Throwable { String hostAddress = InetAddress.getLocalHost().getHostAddress(); rsfBinder.bindAddress(hostAddress, 8001);//分布式的远程服务提供者:1 rsfBinder.bindAddress(hostAddress, 8002);//分布式的远程服务提供者:2 rsfBinder.rsfService(EchoService.class).register(); } }); RsfContext rsfContext = bootstrap.sync(); // //2.获取远程服务的包装类 EchoService myService = rsfContext.getRsfClient().wrapper("RSF", EchoService.class.getName(), "1.0.0", EchoService.class); //3.发起调用 for (int i = 0; i < 1000000; i++) { String echoMsg = myService.echo("你好.."); }
接口和实现类:
public interface EchoService { public String echo(String sayMessage); } public class EchoServiceImpl implements EchoService { public String echo(String sayMessage) { return "RE : " + sayMessage; } }
源码位置:
http://git.oschina.net/zycgit/rsf