I have enabled RA-GRS replication on my Azure storage table service. Is there a option to read from secondary when even there is no failover. What changes need to be done in connection string other than appending -secondary in account name?
1
votes
2 Answers
2
votes
0
votes
If you're using .Net SDK, you don't have to manually append -secondary
to the account name. To connect to a secondary endpoint, you can make use of TableRequestOptions.LocationMode
property and that will automatically connect to the secondary endpoint.
Take a look at the code sample below. It lists tables in a storage account from secondary location:
static void ConnectToSecondary()
{
var cred = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudTableClient();
var requestOptions = new TableRequestOptions()
{
LocationMode = Microsoft.WindowsAzure.Storage.RetryPolicies.LocationMode.SecondaryOnly
};
var tables = client.ListTables(null, requestOptions);
foreach (var table in tables)
{
Console.WriteLine(table.Uri.AbsoluteUri);
}
}
and here's the output from fiddler:
GET https://account-secondary.table.core.windows.net/Tables HTTP/1.1
User-Agent: Azure-Storage/7.0.0 (.NET CLR 4.0.30319.42000; Win32NT 6.2.9200.0)
x-ms-version: 2015-07-08
Accept-Charset: UTF-8
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
x-ms-client-request-id: 0f123ca9-1f35-4e46-9590-ebca0912baa8
x-ms-date: Fri, 11 Nov 2016 10:59:14 GMT
Authorization: SharedKey account:sEsvrm3W0Tn7QhkHqHDrS5o2IvldI4NVUL4U276JudQ=
Host: account-secondary.table.core.windows.net
Connection: Keep-Alive