Unitization configuration

更新时间:
复制 MD 格式

This topic describes how to configure unitization on a local client and how to publish and reference RPC services.

Note

This feature is available only to users who have enabled unitization.

Upgrade dependencies

Upgrade the SOFABoot version to 3.3.0 or later. For more information, see Version Guide.

<parent>
    <groupId>com.alipay.sofa</groupId>
    <artifactId>sofaboot-enterprise-dependencies</artifactId>
    <version>3.3.0</version>
</parent>

Application parameter settings

In the application.properties global configuration file of your local project, configure the following parameters:

  • Configure AntVIP, instanceid, AccessKey ID, and AccessKey secret.For configuration instructions, see Import SOFA middleware.

  • Configure zone information. The following code provides an example:

    com.alipay.ldc.zone=LCD-Test-A-1
    com.alipay.ldc.datacenter=LCD-Test-A
    // Enable strict mode for LDC.
    com.alipay.ldc.strictmode=true
    zmode=true
    // Ensure that the configured zonemng-pool can be reached using the ping command.
    zonemng_zone_url=http://zonemng-pool

Publishing a service

By default, a service is published to the zone where it is deployed. For example, if you deploy the service in RZone, the service is published in RZone. If you deploy the service in CZone, the service is published in CZone. If you deploy the service in both zones, the service is published in both zones.

By default, a service is published to all zones. To publish a service to specific zones, configure the following DRM dynamic configuration.

  • Resource: com.alipay.sofa.rpc.ldc.route.drm.config

  • Field: publishConfig

  • Content: [{"serviceName":"interface:1.0:uniqueId","cell":"RZ,CZ"}]

For example, if your current zone is RZ00A, you can use the preceding DRM configuration to publish your service in RZ00A. If your zone name is TZ00A, the service is not published.

After the configuration is complete, restart the application for the changes to take effect. These settings cannot be changed dynamically at runtime and require an application restart to take effect.

Referencing a service

If you set com.alipay.ldc.strictmode=true (strict mode), the first request parameter for routing must contain the userId routing information. The RPC framework calculates the route based on the second-to-last and third-to-last digits of the parameter. If this condition is not met, the system determines that no LDC logic is used and prioritizes the local zone.

If the default rule is insufficient, you can use advanced settings. These settings can be configured at the method level.

  • Resource: com.alipay.sofa.rpc.ldc.route.drm.config

  • Field: routeConfig

The system first matches the method and then the interface. The route is calculated based on the second and third digits of the first parameter. For example, for the value 123, the result is 23.

[
    {
        "serviceName":"interface:1.0:uniqueId",
        "rule":"string.substring(args[0], 1, 3)"
    },
    {
        "serviceName":"interface:1.0:uniqueId:methodA",
        "rule":"string.substring(args[0], 1, 3)"
    }
]

For complex objects, use the following configuration:

[
    {
        "serviceName":"interface:1.0:uniqueId",
        "rule":"string.substring(#args.[0].uid, 1, 3)"
    }
]

For simple objects, you can also use the following configuration:

[
    {
        "serviceName":"interface:1.0:uniqueId",
        "rule":"string.substring(#args.[0], 1, 3)"
    }
]