dubbo框架扩展


Dubbo框架扩展 2011-09 梁飞 1 Alibaba-B2B-Platform-Framework 2011-09 梁飞 What can I do? • Enhancement – monitor – security – control – convert –… • Integration – napoli – aranda – isearch – memcached –… 2 • Optimization – QoS – asm – protobuf – grizzly –… Feature Performance Easy Outline Framework •Layers & Modules SPI API 3 4 export RPC Remoting Biz connect bind connect bind refer received request connect bind connect bind send reply invoke invoke encode write read createProxy createInvoker export refer decode serialize select list register referred exported getExecutor unexported destroyed notified get merge subscribe get notified list invoke get get export parse parse invoke Provider Consumer Exporter Interface Proxy Filter Invoker Invoker Filter Implement Client Server Transporter LoadBalance Protocol NotificationListener Registry ExporterListener Protocol Registry Exchange Service Serialization Inherit Init Dubbo Framework Depend DubboInvoker DubboProtocol DubboExporter Interface Class ProxyFactory Invoker Proxy ReferenceConfig ServiceConfig Config Call Cluster Codec ObjectOutput ObjectInput Exchanger Requestor Responder Transport Serialize Directory Cluster ThreadPool Filter InvokerListener RegistryProtocol User API Contributor SPI RegistryLocator RegistryDirectory Config ConfigParser deserialize export invoke refer invoke invoke merge invoke ChannelHandler ExchangeHandler 5 Codec Codec Invoker Invoker Server Server Directory Filter Filter Filter LoadBalance Implement Implement Proxy Filter Interface Client Client Invoker Invoker random, roundrobin, leastactive context, deprecated, generic, count, limit, monitor, collect jdk, javassist, cglib dubbo, normandy failover, failsafe, failfast, failback, forking netty, mina, grizzly netty, mina, grizzly context, token, accesslog, exception, classloader, echo, generic … jdk, javassist, cglib dubbo, hessian, java, json dubbo, rmi, hessian, http java, generic ThreadPool ThreadPool fixed, cached Provider Consumer Inherit Interface Class Call Dubbo Extension Invoker Filter local, mock, cache Remoting RPC Serialization Serialization telnet, transport, exchange Common retry Protocol Transporter Transporter Registry Exporter Exporter Protocol dubbo, rmi, hessian, http ProxyFactory ProxyFactory Init Cluster Modules 6 Outline Framework SPI • Microkernel & SPI • Protocol & ProxyFactory & Filter • Cluster & Directory & Router & LoadBalance • Transporter & Serialization & ThreadPool • TelnetHandler & StatusChecker API 7 Microkernel (Lifecycle Manager) • OSGi – Equinox – Eclipse,HSF – META-INF/MANIFEST.MF • IoC – Spring – META-INF/spring/beans.xml • SPI – java.util.ServiceProvider – JDBC, MessageDigest, ScriptEngine – META-INF/services/com.xxx.Xxx 8 SPI Contract • Contract: – Singleton-instance – Thread-safe • Reference: – http://download.oracle.com/javase/1.4.2/docs/guide/jar/jar.html#Service%20Provider – http://download.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html 9 package com.xxx; import com.alibaba.dubbo.common.Extension; import com.alibaba.dubbo.rpc.Protocol; @Extension("xxx") public class XxxProtocol implemenets Protocol { // ... } src |-main |-java |-com |-xxx |-XxxProtocol.java |-resources |-META-INF |-services |-com.alibaba.dubbo.rpc.Protocol com.xxx.XxxProtocol IoC & AOP • IoC by setter • AOP by constructor 10 public XxxCluster implements Cluster { private LoadBalance loadbalance; public void setLoadBalance(LoadBalance loadbalance) { this.loadbalance = loadbalance; } } public XxxCluster implements Cluster { private Cluster cluster; public XxxCluster(Cluster cluster) { this.cluster = cluster; } } Protocol 11 @Extention(“xxx”) public class XxxProtocol implements Protocol { public Exporter export(Invoker invoker) { return new XxxExporter(invoker); } public Invoker refer(Class type, URL url) { return new XxxInvoker(type, url); } } Protocol Exporter Invoker ProxyFactory Proxy Invoker Implement export refer invoke(invocation) invoke(invocation) xxx(args) xxx(args) napoli aranda isearch memcached dubbo rmi hession http Filter 12 Proxy Filter Invoker < dubbo:reference filter=“xxx” /> Impl Filter Invoker Protocol @Extension(“xxx”) public class XxxFilter implements Filter { public Result invoke(Invoker invoker, Invocation invocation) { // before Result result = invoker.invoke(invocation); // after return result; } } context monitor token accesslog exception trace count limit … ProxyFactory 13 ProxyFactory Interface Implement Proxy Invoker createInvoker createProxy @Extention(“xxx”) public class XxxProxyFactory implements ProxyFactory { public T createProxy(Invoker invoker, Class... types) { } public Invoker createInvoker(T instance, Class type, URL url) { } } JDK vs. Javassist • Proxy • Invoker 14 public class Invoker$1 implements Invoker { public Object invoke(String methodName, Class[] parameterTypes, Object[] args) throws Exception { if (“xxx”.equals(methodName)) { impl.xxx(args[0], args[1]); - else if (“yyy”.equals(methodName)) { impl.yyy(args[0]); - // …… } } impl.getClass().getMethod(methodName, parameterTypes).invoke(impl, args); public class Proxy$1 implements XxxService { // …… } Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class [] {interfaceClass}, new RemoteInvocationHandler()); Cluster 15 Directory Router Cluster LoadBalance Invoker list route select merge Invoker invoke List List Invoker Registry Static Failover Failfast Failsafe Failback Forking Script Condition Random RoundRobin LeastActive Remoting • Transporter – – netty, mina, grizzly • Serialization – – dubbo, hessian2, java, json • ThreadPool – – fixed, cached 16 Client Server Header Body Codec Serialization Proxy Implement Dispather Transporter ThreadPool Telnet • ls -l • ps -l • status -l • trace XxxService 10 • count XxxService • invoke XxxService.xxxMethod(args) • log 100 • help 17 C:\> telnet localhost 20880 dubbo> help TelnetHandler & StatusChecker 18 @Extension(“xxx”) public class XxxTelnetHandler implements TelnetHandler { public String telnet(String command) throws RemotingException { return “echo: ” + command; } } @Extension(“xxx”) public class XxxStatusChecker implements StatusChecker { public Status check() { return new Status(Status.Level.OK, “Fine!”); } } dubbo> xxx hello echo: hello dubbo> status -l | Xxx | OK | Fine! | Outline Framework SPI API • Config & URL • Context & Generic & Local 19 Configs • Application Shared: – • Provider Side: – • Consumer Side: – 20 Config Relation 21 Config Type • Service Identification – group – interface – version • Service Governance – application – deprecated –… • Performance Optimize – timeout – threads –… 22 Config Override 23 Method Interface Default Consumer Provider Config URL Provider • dubbo://10.20.153.10:20880/xxxService?timeout=10 00&xxx.timeout=1000&default.timeout=1000 Registry • dubbo://10.20.153.10:20880/xxxService?timeout=20 00&xxx.timeout=2000&default.timeout=2000 Consumer • dubbo://10.20.153.10:20880/xxxService?timeout=30 00&xxx.timeout=3000&default.timeout=3000 24 Programmable Config • ServiceConfig – setApplication(new ApplicationConfig(“xxx”)); – setRegistry(new RegistryConfig(“10.20.153.186”)); – setInterface(“com.xxx.XxxService”); – export(); • ReferenceConfig – setApplication(new ApplicationConfig(“yyy”)); – setRegistry(new RegistryConfig(“10.20.153.186”)); – setInterface(“com.xxx.XxxService”); – get(); 25 Context & Trace • ThreadLocal Context – RpcContext.getContext().getRemoteHost(); – RpcContext.getContext().setAttachment("index", "1"); – RpcContext.getContext().getAttachment("index"); • Like HTTP Cookie 26 Proxy Filter Context Context invocation attachment Action Implement getRemoteHost Filter setAttachment getRemoteHost getAttachment Generic Service • Java interface • Generic interface • Java implementation • Generic implementation 27 GenericService memberService = applicationContext.getBean(“memberService”); memberService.invoke(“findPerson”, new String*+ ,“java.lang.String”-, new Object*+ ,memberId}); public class MemberSericeImpl implements GenericService { public Object invoke(String method, String[] ptypes, Object[] args) { } } public class MemberSericeImpl implements MemberService { } MemberService memberService = (MemberService) applicationContext.getBean(“memberService”); memberService.findPerson(memberId); POJO Map Consumer Provider Dubbo API Local & Mock • dubbo://10.20.153.10?local=true&mock=true • Constructor: – public XxxServiceLocal(XxxService xxxService) {} – public XxxServiceMock() {} 28 XxxServiceLocal XxxServiceMock XxxServiceImpl XxxServiceProxy Action Remote Failed XxxService refer invoke inherit Summary Framework • Layers & Modules SPI • Microkernel & SPI • Protocol & ProxyFactory & Filter • Cluster & Directory & Router & LoadBalance • Transporter & Serialization & ThreadPool • TelnetHandler & StatusChecker API • Config & URL • Context & Generic & Local 29 Resources • Documents: – http://b2b-doc.alibaba-inc.com/display/RC/Dubbo – http://b2b-doc.alibaba-inc.com/display/RC/Dubbo_SPI_Reference – http://b2b-doc.alibaba-inc.com/display/RC/Dubbo_API_Reference – http://b2b-doc.alibaba-inc.com/display/RC/Dubbo_Contribute • Supports: – 梁飞 (william.liangf@alibaba-inc.com) – 刘超(chao.liuc@alibaba-inc.com) – 李鼎(ding.lid@alibaba-inc.com) – 刘昊旻(haomin.liuhm@alibaba-inc.com) – 陈雷(tony.chenl@alibaba-inc.com) 30 Q & A • Q & A 31
还剩30页未读

继续阅读

下载pdf到电脑,查找使用更方便

pdf的实际排版效果,会与网站的显示效果略有不同!!

需要 10 金币 [ 分享pdf获得金币 ] 0 人已下载

下载pdf

pdf贡献者

pro_lv

贡献于2017-02-23

下载需要 10 金币 [金币充值 ]
亲,您也可以通过 分享原创pdf 来获得金币奖励!
下载pdf