Cloud Native 6 min read

Master Dubbo Service Governance: Dynamic Routing, Config & Mocking

This guide explains how to use Dubbo's cloud‑native features—service listings, dynamic routing (conditional, tag, and mesh), runtime configuration, testing, and mock support—providing step‑by‑step examples, YAML definitions, and Maven snippets for effective service governance.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Master Dubbo Service Governance: Dynamic Routing, Config & Mocking

01 Service Information

Dubbo displays services by interface, separating them by registration source at the interface‑level or application‑level. The service detail page lists provider and consumer information together with method signatures.

02 Dynamic Routing

Conditional Routing lets you write custom rules for service governance scenarios such as black‑/white‑lists or read‑write separation. Rules can be created at the interface level or for a specific consumer application. Example: a blacklist rule where the consumer IP 192.168.1.3 matches no provider.

Tag Routing groups providers under a common tag, restricting traffic to that group. This enables blue‑green or gray releases. Example configuration:

dubbo.provider.tag=tag1
@DubboService(tag = "tag2")

Mesh Routing (Dubbo 3.0) splits traffic management into VirtualService (inbound) and DestinationRule (outbound). The following YAML routes calls to HelloService#hi(Integer) based on whether the argument is even or odd:

apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
  name: demo/oddEvenRouter
spec:
  dubbo:
  - routedetail:
    - match:
      - method:
          argc: 1
          args:
          - index: 0
            num_value:
              oneof:
              - exact: 0.0
                mod: 2.0
            type: int
          name_match:
            exact: hi
      name: even-route
      route:
      - destination:
          host: demo
          subset: v1
    - match:
      - method:
          argc: 1
          args:
          - index: 0
            num_value:
              oneof:
              - exact: 1.0
                mod: 2.0
            type: int
          name_match:
            exact: hi
      name: odd-route
      route:
      - destination:
          host: demo2
          subset: v2
  services:
  - exact: org.test.apache.dubbo.interfaces.HelloService
---
apiVersion: service.dubbo.apache.org/v1alpha1
kind: DestinationRule
metadata:
  name: test-route
spec:
  host: demo
  subsets:
    - name: v1
      labels:
        test-version: v1
    - name: v2
      labels:
        test-version: v2

03 Dynamic Configuration

Dubbo allows runtime adjustment of RPC behavior without restarting services, such as changing timeout, weight, or load‑balancing strategy. The example below sets the consumer‑side timeout to 6000 ms.

04 Service Testing

Use the admin console to test Dubbo services; request parameters are auto‑generated as a JSON template based on service metadata.

05 Service Mock

Configure mock rules in the admin UI and enable them by adding the JVM flag -Denable.dubbo.admin.mock=true. This allows a consumer to receive mock responses when no provider is available.

<dependency>
    <groupId>org.apache.dubbo.extensions</groupId>
    <artifactId>dubbo-mock-admin</artifactId>
    <version>last</version>
</dependency>

06 New Features

Application‑level service discovery

Mesh routing

Service mock

Permission SPI extension

07 Related Links

Official documentation: https://dubbo.apache.org/zh/docs/advanced/routing-rule/

Traffic management concepts: https://dubbo.apache.org/zh/docs/concepts/traffic-management/

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeMockingService Meshdynamic routing
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.