You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2018/04/04 02:47:19 UTC

[incubator-servicecomb-website] 02/03: add init method example

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-website.git

commit 091da78c2adee6ac94523de0fc4ea47a70c32173
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Tue Apr 3 11:28:08 2018 +0800

    add init method example
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 _users/cn/edge-in-1.0.0-m1.md | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/_users/cn/edge-in-1.0.0-m1.md b/_users/cn/edge-in-1.0.0-m1.md
index 2b9d374..9950340 100644
--- a/_users/cn/edge-in-1.0.0-m1.md
+++ b/_users/cn/edge-in-1.0.0-m1.md
@@ -49,7 +49,23 @@ Edge Service转发Operation1的请求将允许1.0.0版本和1.1.0版本的微服
 Dispatcher向Vertx注入路由规则时的优先顺序,值越小优先级越高。
 
 #### init方法
-初始化Dispatcher的路由规则,使用的是[Vertx路由规则](https://vertx.io/docs/vertx-web/java/#_routing_by_exact_path)
+初始化Dispatcher的路由规则,使用的是[Vertx路由规则](https://vertx.io/docs/vertx-web/java/#_routing_by_exact_path),例如我们添加两条匹配策略:
+```java
+public void init(Router router) {
+  String regex = "/([^\\\\/]+)/([^\\\\/]+)/(.*)";
+  router.routeWithRegex(regex).handler(CookieHandler.create());
+  router.routeWithRegex(regex).handler(createBodyHandler());
+  router.routeWithRegex(regex).failureHandler(this::onFailure).handler(this::onRequest);
+
+  regex = "/([^\\\\/]+)/(.*)";
+  router.routeWithRegex(regex).handler(CookieHandler.create());
+  router.routeWithRegex(regex).handler(createBodyHandler());
+  router.routeWithRegex(regex).failureHandler(this::onFailure).handler(this::onRequest);
+}
+```
+
+1. /([^\\/]+)/([^\\/]+)/(.*) : 这条策略我们希望匹配带版本的微服务请求,例如/user-service/v0/validate;
+2. /([^\\/]+)/(.*) : 这条策略用于匹配不带版本的微服务请求,例如/user-service/validate。
 
 #### onRequest方法
 转发策略,方法原型为:

-- 
To stop receiving notification emails like this one, please contact
ningjiang@apache.org.