使用案例

    1. 10.0.0.2:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    2. 10.0.0.3:12200?_p=hessian2&APP=demo&st=na610&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    3. 10.0.0.4:12200?_p=hessian2&APP=demo&st=na620&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    4. 10.0.0.4:12200?_p=hessian2&APP=demo&st=et12&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNSH
    5. 10.0.0.5:12200?_p=hessian2&APP=demo&st=et12&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNSH
    6. 10.0.0.6:12200?_p=hessian2&APP=demo&st=SA128&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNSZ
    7. 10.0.0.7:12200?_p=hessian2&APP=demo&st=SA128&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNSZ
    8. 10.0.0.8:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNZBMIX
    9. 10.0.0.9:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNZBMIX
    10. 10.0.0.10:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNZBMIX
    1. apiVersion: service.dubbo.apache.org/v1alpha1
    2. kind: VirtualService
    3. metadata:
    4. name: demo/UnitRouter
    5. spec:
    6. hosts:
    7. - demo
    8. dubbo:
    9. - name: UnitServiceRoute
    10. services:
    11. - exact: com.taobao.hsf.DemoService:1.0.0
    12. routedetail:
    13. - name: center-env
    14. match:
    15. - context:
    16. hsfcontext:
    17. user_unit:
    18. exact: CENTER
    19. route:
    20. - destination:
    21. host: demo
    22. subset: CENTER
    23. fallback: // 单元化没有 fallback,直接报错
    24. - name: unsh-env
    25. match:
    26. - context:
    27. hsfcontext:
    28. user_unit:
    29. exact: UNSH
    30. route:
    31. - destination:
    32. host: demo
    33. subset: UNSH
    34. - name: unsz-env
    35. match:
    36. - context:
    37. hsfcontext:
    38. user_unit:
    39. exact: UNSZ
    40. route:
    41. - destination:
    42. host: demo
    43. subset: UNSZ
    44. - name: zbmix-env
    45. match:
    46. - context:
    47. hsfcontext:
    48. exact: ZBMIX
    49. - destination:
    50. host: demo
    51. subset: ZBMIX
    52. ----
    53. apiVersion: service.dubbo.apache.org/v1alpha1
    54. kind: DestinationRule
    55. metadata:
    56. name: demo/UnitRouter
    57. spec:
    58. host: demo // 这个和上面的保持一致
    59. subsets:
    60. - name: CENTER
    61. labels:
    62. sigma.ali/unit: CENTER
    63. - name: UNSH
    64. labels:
    65. sigma.ali/unit: UNSH
    66. - name: UNSZ
    67. labels:
    68. sigma.ali/unit: UNSZ
    69. - name: ZBMIX
    70. labels:
    71. sigma.ali/unit: ZBMIX
    72. ----
    73. apiVersion: service.dubbo.apache.org/v1alpha1
    74. kind: VirtualService
    75. metadata:
    76. name: demo/MachineRouter
    77. spec:
    78. hosts:
    79. - demo
    80. dubbo:
    81. - name: MachineRoomRouteDefault // 同机房
    82. services:
    83. - regex: *
    84. routedetail:
    85. - name: na61-samesite-route // 把 na61 机房的流量打到 na61、na610 机房
    86. match:
    87. - sourcelables:
    88. sigma.ali/site: na61
    89. route:
    90. - destination:
    91. host: demo
    92. subset: na61
    93. - destination:
    94. host: demo
    95. subset: na610
    96. weight: 40
    97. - name: na62-samesite-route // 把 na62 机房的流量打到 na62 机房
    98. match:
    99. - sourcelables:
    100. sigma.ali/site: na62
    101. route:
    102. - destination:
    103. host: demo
    104. subset: na62
    105. - name: default // 兜底路由,其他机房的流量随意打
    106. - destination:
    107. .....
    108. ----
    109. ----
    110. apiVersion: service.dubbo.apache.org/v1alpha1
    111. kind: DestinationRule
    112. metadata:
    113. name: demo/MachineRouter
    114. spec:
    115. host: demo// 这个和上面的保持一致
    116. subsets:
    117. - name: na61
    118. labels:
    119. sigma.ali/site: na61
    120. - name: na610
    121. labels:
    122. sigma.ali/site: na610
    123. - name: na62
    124. labels:
    125. sigma.ali/site: na62
    126. - name: na620
    127. labels:
    128. sigma.ali/site: na620
    129. .....

    以上面的配置为例,假设消费者在CENTER标的na62机房,请求上下文中的user_unit属于CENTER

    那么我们有以下路由流程:

    我们经过 UnitRouter 时,地址被划分为四个部份

    • CENTER:
    1. 10.0.0.1:12200?_p=hessian2&APP=demo&st=na61&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    2. 10.0.0.2:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    3. 10.0.0.3:12200?_p=hessian2&APP=demo&st=na610&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    4. 10.0.0.4:12200?_p=hessian2&APP=demo&st=na620&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    • UNSH
    1. 10.0.0.4:12200?_p=hessian2&APP=demo&st=et12&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNSH
    2. 10.0.0.5:12200?_p=hessian2&APP=demo&st=et12&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNSH
    • UNSZ
    1. 10.0.0.6:12200?_p=hessian2&APP=demo&st=SA128&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNSZ
    2. 10.0.0.7:12200?_p=hessian2&APP=demo&st=SA128&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNSZ
    • UNZBMIX

    因为 user_unit属于CENTER,所以我们选择CENTER的部分,作为MachineRoomRouter的地址输入,即为

    CENTER

    1. 10.0.0.1:12200?_p=hessian2&APP=demo&st=na61&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    2. 10.0.0.2:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    3. 10.0.0.3:12200?_p=hessian2&APP=demo&st=na610&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    4. 10.0.0.4:12200?_p=hessian2&APP=demo&st=na620&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER

    na61

    1. 10.0.0.1:12200?_p=hessian2&APP=demo&st=na61&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER

    na610

    1. 10.0.0.3:12200?_p=hessian2&APP=demo&st=na610&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER

    na62

    1. 10.0.0.2:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    2. 10.0.0.8:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNZBMIX
    3. 10.0.0.9:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNZBMIX
    4. 10.0.0.10:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNZBMIX

    na620

    1. 10.0.0.4:12200?_p=hessian2&APP=demo&st=na620&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    fallback

    由于消费者在 na62 机房发起调用,匹配了

    1. - name: na62-samesite-route // 把 na62 机房的流量打到 na62 机房
    2. match:
    3. - sourcelables:
    4. sigma.ali/site: na62
    5. route:
    6. - destination:
    7. host: demo
    8. subset: na62

    na62

    1. 10.0.0.2:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    2. 10.0.0.8:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNZBMIX
    3. 10.0.0.9:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNZBMIX
    4. 10.0.0.10:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=UNZBMIX

    而UnitRouter给MachineRoomRouter的输入为

    CENTER

    1. 10.0.0.1:12200?_p=hessian2&APP=demo&st=na61&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    2. 10.0.0.2:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    3. 10.0.0.3:12200?_p=hessian2&APP=demo&st=na610&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER
    4. 10.0.0.4:12200?_p=hessian2&APP=demo&st=na620&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER

    两个取交集的结果为

    这个结果将做为一下路由的输出,重复前面的动作;

    1. 10.0.0.2:12200?_p=hessian2&APP=demo&st=na62&v=2.0&_TIMEOUT=3000&_ih2=y&mg=demohost&_CONNECTTIMEOUT=1000&_SERIALIZETYPE=hessian&ut=CENTER