[Azure] 建立一個新的 Traffic Manager Profile + External Endpoint
2020-12-24
今天要做的是我們要建立一個 新的 Traffic Manager Profile ,並且加入一個 External Endpoint 指向一個 FQDN
1. 首先你要拿一個大一點的權限,拿權限方法
https://blog.no2don.com/2020/09/azurec-appservice-application-settings.html
2. 專案這邊 安裝該安裝的 nuget
https://www.nuget.org/packages/Microsoft.Azure.Management.Fluent/
https://www.nuget.org/packages/Microsoft.Azure.Management.ResourceManager.Fluent/
3. 接下來,在 code 裡面 我會去建立一個 結果是 donmatm.trafficmanager.net 的 Traffic Manager , 並且設定他在東南亞 ,位於 SPINUS 的群組,指向一個 External Point “endpoint1” 指向 tm.ina9.win 且自訂 header , Priority 為 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal( | |
"aaaaaaaa-bbbb-cccc-dddd-6fd11866e9cd", | |
"KfgTfMZVY-I_AM_PASS_WORD~lW8", | |
"zzzzzzzz-xxxx-yyyy-wwww-1234567897", AzureEnvironment.AzureGlobalCloud); | |
var azure = Azure | |
.Configure() | |
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic) | |
.Authenticate(credentials) | |
.WithDefaultSubscription(); | |
var trfficmanagerName = "donmatm"; | |
var tmDefinition = azure.TrafficManagerProfiles.Define(trfficmanagerName) | |
.WithExistingResourceGroup("SPINUS") | |
.WithLeafDomainLabel(trfficmanagerName) | |
.WithPriorityBasedRouting(); | |
Microsoft.Azure.Management.ResourceManager.Fluent.Core.ResourceActions.ICreatable<Microsoft.Azure.Management.TrafficManager.Fluent.ITrafficManagerProfile> | |
tmCreatable = tmDefinition.DefineExternalTargetEndpoint("endpoint1").ToFqdn("tm.ina9.win") | |
.FromRegion(Region.AsiaSouthEast).WithCustomHeader("testheader", "20201224_1423") | |
.WithRoutingPriority(1) | |
.Attach(); | |
var trafficManagerProfileNew = tmCreatable.Create(); | |
Console.WriteLine("-- AFTER ADD AND READ DATA--"); | |
var externalEndpoints = trafficManagerProfileNew.ExternalEndpoints; | |
foreach (var endpoint in externalEndpoints) | |
{ | |
Console.WriteLine("IsEnable:" + trafficManagerProfileNew.ExternalEndpoints[endpoint.Key].IsEnabled); | |
Console.WriteLine("Name:" + trafficManagerProfileNew.ExternalEndpoints[endpoint.Key].Name); | |
Console.WriteLine("CustomHeader:" + JsonConvert.SerializeObject(trafficManagerProfileNew.ExternalEndpoints[endpoint.Key].CustomHeaders)); | |
Console.WriteLine("FQDN:" + trafficManagerProfileNew.ExternalEndpoints[endpoint.Key].Fqdn); | |
Console.WriteLine("RoutingPriority:" + trafficManagerProfileNew.ExternalEndpoints[endpoint.Key].RoutingPriority); | |
Console.WriteLine("-"); | |
} | |
結果

其實,做出來之後不會很難,只是因為他設計的 pattern 關係測試了一下也花了點時間…
之後有碰到其他問題我們再說吧 :)