你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Azure Traffic Manager libraries for Java

Overview

Control the distribution of user traffic for service endpoints in different datacenters with Azure Traffic Manager.

To get started with Azure Traffic Manager, see Create a Traffic Manager profile.

Management API

Create Traffic Manager profiles, define endpoints, and change the routing method with the management API.

Add a dependency to your Maven pom.xml file to use the management API in your project.

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-mgmt-trafficmanager</artifactId>
    <version>1.3.0</version>
</dependency>

Example

Create a Traffic Manager profile and assign a single endpoint.

TrafficManagerProfile tmProfile = azure.trafficManagerProfiles().define("testTMProfile")
        .withNewResourceGroup(Region.US_EAST)
        .withLeafDomainLabel("testTMProfile")
        .withPriorityBasedRouting()
        .defineAzureTargetEndpoint("endpoint")
        .toResourceId(webAppId)
        .withRoutingPriority(1)
        .attach()
        .create();

Samples

Balance web app traffic across multiple regions

Explore more sample Java code for Azure Traffic Manager you can use in your apps.