MyThrift是基于Facebook thrift 0.9.3 基础上开发的轻量级微服务框架, 支持:服务注册、服务发现,client端负载均衡。 http://git.oschina.net/qiangzigege/MyThrift V0.4的版本:注重提升用户体验,降低编码复杂性,屏蔽具体的技术细节。 用户具体使用时 1)客户端:几行就可以完成一个client端调用 public static void test() throws Exception {
String group = "test";
String service = "HelloWorldService";
TMultiplexedProtocol tMultiProtocol = null;
try {
tMultiProtocol = SocketUtils.getProtocol(group, service);
HelloWorldService.Client client = new HelloWorldService.Client(tMultiProtocol);
logger.info(client.helloWorldString("https://git.oschina.net/qiangzigege/MyThrift"));
} catch (Exception e) {
SocketUtils.setAlive(tMultiProtocol, false, e);
throw e;
} finally {
SocketUtils.returnObject(tMultiProtocol);
}
} 需要在client.properties中配置关心的服务信息 格式如下/组名/服务名:版本号,多个的话用逗号隔开 #used service,seperated by ,
service=/test/HelloWorldService:0.2 2)服务端 只需要2行完成服务自动注册 server.properties中增加一行添加扫描包 #package to be scanned,to get processor,so that we can register it. 业务实现类添加注解:组名,服务名,版本号 @Processor(group = "test", service = "HelloWorldService", edition = "0.2")
public class HelloWorldServiceImpl implements HelloWorldService.Iface { 就完成服务的自动注册。 ------------------------------------------------------------------------------------ V0.5将专注于移植netflix的优秀组件增强client端的智能特性。 源码地址: |