blob: 211d0e17b328101bb8658ee9baad3e66885838cd [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>6.6 路由扩展 · GitBook</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.2">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="负载均衡扩展.html" />
<link rel="prev" href="集群扩展.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../contribution.html">
<a href="../contribution.html">
1 contribution
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../版本管理.html">
<a href="../版本管理.html">
2 版本管理
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../源码构建.html">
<a href="../源码构建.html">
3 源码构建
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../框架设计.html">
<a href="../框架设计.html">
4 框架设计
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../扩展点加载.html">
<a href="../扩展点加载.html">
5 扩展点加载
</a>
</li>
<li class="chapter " data-level="1.7" data-path="introduction.html">
<a href="introduction.html">
6 SPI参考手册
</a>
<ul class="articles">
<li class="chapter " data-level="1.7.1" data-path="协议扩展.html">
<a href="协议扩展.html">
6.1 协议扩展
</a>
</li>
<li class="chapter " data-level="1.7.2" data-path="调用拦截扩展.html">
<a href="调用拦截扩展.html">
6.2 调用拦截扩展
</a>
</li>
<li class="chapter " data-level="1.7.3" data-path="引用监听扩展.html">
<a href="引用监听扩展.html">
6.3 引用监听扩展
</a>
</li>
<li class="chapter " data-level="1.7.4" data-path="暴露监听扩展.html">
<a href="暴露监听扩展.html">
6.4 暴露监听扩展
</a>
</li>
<li class="chapter " data-level="1.7.5" data-path="集群扩展.html">
<a href="集群扩展.html">
6.5 集群扩展
</a>
</li>
<li class="chapter active" data-level="1.7.6" data-path="路由扩展.html">
<a href="路由扩展.html">
6.6 路由扩展
</a>
</li>
<li class="chapter " data-level="1.7.7" data-path="负载均衡扩展.html">
<a href="负载均衡扩展.html">
6.7 负载均衡扩展
</a>
</li>
<li class="chapter " data-level="1.7.8" data-path="合并结果扩展.html">
<a href="合并结果扩展.html">
6.8 合并结果扩展
</a>
</li>
<li class="chapter " data-level="1.7.9" data-path="注册中心扩展.html">
<a href="注册中心扩展.html">
6.9 注册中心扩展
</a>
</li>
<li class="chapter " data-level="1.7.10" data-path="监控中心扩展.html">
<a href="监控中心扩展.html">
6.10 监控中心扩展
</a>
</li>
<li class="chapter " data-level="1.7.11" data-path="扩展点加载扩展.html">
<a href="扩展点加载扩展.html">
6.11 扩展点加载扩展
</a>
</li>
<li class="chapter " data-level="1.7.12" data-path="动态代理扩展.html">
<a href="动态代理扩展.html">
6.12 动态代理扩展
</a>
</li>
<li class="chapter " data-level="1.7.13" data-path="编译器扩展.html">
<a href="编译器扩展.html">
6.13 编译器扩展
</a>
</li>
<li class="chapter " data-level="1.7.14" data-path="消息派发扩展.html">
<a href="消息派发扩展.html">
6.14 消息派发扩展
</a>
</li>
<li class="chapter " data-level="1.7.15" data-path="线程池扩展.html">
<a href="线程池扩展.html">
6.15 线程池扩展
</a>
</li>
<li class="chapter " data-level="1.7.16" data-path="序列化扩展.html">
<a href="序列化扩展.html">
6.16 序列化扩展
</a>
</li>
<li class="chapter " data-level="1.7.17" data-path="网络传输扩展.html">
<a href="网络传输扩展.html">
6.17 网络传输扩展
</a>
</li>
<li class="chapter " data-level="1.7.18" data-path="信息交换扩展.html">
<a href="信息交换扩展.html">
6.18 信息交换扩展
</a>
</li>
<li class="chapter " data-level="1.7.19" data-path="组网扩展.html">
<a href="组网扩展.html">
6.19 组网扩展
</a>
</li>
<li class="chapter " data-level="1.7.20" data-path="Telnet命令扩展.html">
<a href="Telnet命令扩展.html">
6.20 Telnet命令扩展
</a>
</li>
<li class="chapter " data-level="1.7.21" data-path="状态检查扩展.html">
<a href="状态检查扩展.html">
6.21 状态检查扩展
</a>
</li>
<li class="chapter " data-level="1.7.22" data-path="容器扩展.html">
<a href="容器扩展.html">
6.22 容器扩展
</a>
</li>
<li class="chapter " data-level="1.7.23" data-path="页面扩展.html">
<a href="页面扩展.html">
6.23 页面扩展
</a>
</li>
<li class="chapter " data-level="1.7.24" data-path="缓存扩展.html">
<a href="缓存扩展.html">
6.24 缓存扩展
</a>
</li>
<li class="chapter " data-level="1.7.25" data-path="验证扩展.html">
<a href="验证扩展.html">
6.25 验证扩展
</a>
</li>
<li class="chapter " data-level="1.7.26" data-path="日志适配扩展.html">
<a href="日志适配扩展.html">
6.26 日志适配扩展
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.8" data-path="../技术兼容性测试.html">
<a href="../技术兼容性测试.html">
7 技术兼容性测试
</a>
</li>
<li class="chapter " data-level="1.9" data-path="../公共契约.html">
<a href="../公共契约.html">
8 公共契约
</a>
</li>
<li class="chapter " data-level="1.10" data-path="../坏味道.html">
<a href="../坏味道.html">
9 坏味道
</a>
</li>
<li class="chapter " data-level="1.11" data-path="../编码约定.html">
<a href="../编码约定.html">
10 编码约定
</a>
</li>
<li class="chapter " data-level="1.12" data-path="../检查列表.html">
<a href="../检查列表.html">
11 检查列表
</a>
</li>
<li class="chapter " data-level="1.13" data-path="../设计原则.html">
<a href="../设计原则.html">
12 设计原则
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >6.6 路由扩展</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h5 id="1-&#x6269;&#x5C55;&#x8BF4;&#x660E;">1. &#x6269;&#x5C55;&#x8BF4;&#x660E;</h5>
<p>&#x4ECE;&#x591A;&#x4E2A;&#x670D;&#x52A1;&#x63D0;&#x8005;&#x65B9;&#x4E2D;&#x9009;&#x62E9;&#x4E00;&#x4E2A;&#x8FDB;&#x884C;&#x8C03;&#x7528;&#x3002;</p>
<h5 id="2-&#x6269;&#x5C55;&#x63A5;&#x53E3;">2. &#x6269;&#x5C55;&#x63A5;&#x53E3;</h5>
<ul>
<li><code>com.alibaba.dubbo.rpc.cluster.RouterFactory</code></li>
<li><code>com.alibaba.dubbo.rpc.cluster.Router</code></li>
</ul>
<h5 id="3-&#x6269;&#x5C55;&#x914D;&#x7F6E;">3. &#x6269;&#x5C55;&#x914D;&#x7F6E;</h5>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">dubbo:protocol</span> <span class="hljs-attr">router</span>=<span class="hljs-string">&quot;xxx&quot;</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dubbo:provider</span> <span class="hljs-attr">router</span>=<span class="hljs-string">&quot;xxx&quot;</span> /&gt;</span> <span class="hljs-comment">&lt;!-- &#x7F3A;&#x7701;&#x503C;&#x8BBE;&#x7F6E;&#xFF0C;&#x5F53;&lt;dubbo:protocol&gt;&#x6CA1;&#x6709;&#x914D;&#x7F6E;loadbalance&#x65F6;&#xFF0C;&#x4F7F;&#x7528;&#x6B64;&#x914D;&#x7F6E; --&gt;</span>
</code></pre>
<h5 id="4-&#x5DF2;&#x77E5;&#x6269;&#x5C55;">4. &#x5DF2;&#x77E5;&#x6269;&#x5C55;</h5>
<ul>
<li><code>com.alibaba.dubbo.rpc.cluster.router.ScriptRouterFactory</code></li>
<li><code>com.alibaba.dubbo.rpc.cluster.router.FileRouterFactory</code></li>
</ul>
<h5 id="5-&#x6269;&#x5C55;&#x793A;&#x4F8B;">5. &#x6269;&#x5C55;&#x793A;&#x4F8B;</h5>
<p>Maven&#x9879;&#x76EE;&#x7ED3;&#x6784;</p>
<pre><code>src
|-main
|-java
|-com
|-xxx
|-XxxRouterFactory.java (&#x5B9E;&#x73B0;LoadBalance&#x63A5;&#x53E3;)
|-resources
|-META-INF
|-dubbo
|-com.alibaba.dubbo.rpc.cluster.RouterFactory (&#x7EAF;&#x6587;&#x672C;&#x6587;&#x4EF6;&#xFF0C;&#x5185;&#x5BB9;&#x4E3A;&#xFF1A;xxx=com.xxx.XxxRouterFactory)
</code></pre><blockquote>
<p>XxxRouterFactory.java</p>
</blockquote>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.xxx;
<span class="hljs-keyword">import</span> com.alibaba.dubbo.rpc.cluster.RouterFactory;
<span class="hljs-keyword">import</span> com.alibaba.dubbo.rpc.Invoker;
<span class="hljs-keyword">import</span> com.alibaba.dubbo.rpc.Invocation;
<span class="hljs-keyword">import</span> com.alibaba.dubbo.rpc.RpcException;
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">XxxRouterFactory</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">RouterFactory</span> </span>{
<span class="hljs-keyword">public</span> &lt;T&gt; List&lt;Invoker&lt;T&gt;&gt; select(List&lt;Invoker&lt;T&gt;&gt; invokers, Invocation invocation) <span class="hljs-keyword">throws</span> RpcException {
<span class="hljs-comment">// ...</span>
}
}
</code></pre>
<p>META-INF/dubbo/com.alibaba.dubbo.rpc.cluster.RouterFactory</p>
<pre><code>xxx=com.xxx.XxxRouterFactory
</code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="集群扩展.html" class="navigation navigation-prev " aria-label="Previous page: 6.5 集群扩展">
<i class="fa fa-angle-left"></i>
</a>
<a href="负载均衡扩展.html" class="navigation navigation-next " aria-label="Next page: 6.7 负载均衡扩展">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"6.6 路由扩展","level":"1.7.6","depth":2,"next":{"title":"6.7 负载均衡扩展","level":"1.7.7","depth":2,"path":"SPI参考手册/负载均衡扩展.md","ref":"./SPI参考手册/负载均衡扩展.md","articles":[]},"previous":{"title":"6.5 集群扩展","level":"1.7.5","depth":2,"path":"SPI参考手册/集群扩展.md","ref":"./SPI参考手册/集群扩展.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"SPI参考手册/路由扩展.md","mtime":"2017-08-02T06:13:38.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-08-02T07:36:57.834Z"},"basePath":"..","book":{"language":""}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
</body>
</html>