Send message
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference("myqueue");
queue.CreateIfNotExists();
CloudQueueMessage message = new CloudQueueMessage("Hello, World");
queue.AddMessage(message);
Receive message
CloudQueueMessage peekedMessage = queue.PeekMessage();
CloudQueueMessage retrievedMessage = queue.GetMessage();
retrievedMessage.DeleteMessage(retrievedMessage);
Send batch to queue
QueueClient queueClient = new QueueClient(ServiceBusConnectionString, QueueName);
string messageBody = $"First Message";
Message message = new Message(Encoding.UTF8.GetBytes(messageBody));
await queueClient.SendAsync(message);
var messages = new List<Message>();
for (int i = 0; i < 10; i++)
{
var message = new Message(Encoding.UTF8.GetBytes($"Message {i:00}")};
messages.Add(message);
}
await queueClient.SendBatchAsync(messages);
CompleteAsync
or AbandonAsync
(you receive the message again)function.json
defines when the function is triggered.Example for webhooks
{
"disabled":false,
"bindings":[
{
"authLevel":"function",
"name":"req",
"type":"httpTrigger",
"direction":"in",
"methods":[
"post"
]
},
{
"name":"$return",
"type":"http",
"direction":"out"
}
]
}
Example for github trigger
{
"bindings":[
{
"type":"httpTrigger",
"direction":"in",
"webHookType":"github",
"name":"req"
},
{
"type":"http",
"direction":"out",
"name":"res"
}
],
"disabled":false
}
Using Azure CLI
az group create --name DemoGroup --location eastus
az storage account create --name demostor --location eastus --resource-group DemoGroup --sku Standard\_LRS --kind BlobStorage --access-tier Hot
az eventgrid event-subscription create --resource-id $storageid –name contosostoragesub --endpoint https://contoso.com/api/update
ValidationCode
handshake (programmatic)
ValidationURL
handshake (manual)
ws
package => WebSocket protocol client libraryhyco-ws
package => Extends ws where Azure Relay is built.hycows.Server
instead of ws.Server, mostly contract compatiblememberOf
json
specifies input/outputs.
{
"disabled": false,
"bindings":[
{
"type": "queueTrigger",
"direction": "in",
"name": "message",
"queueName": "announcementqueue", "connection":"StorageConnectionString"
}
]
}
C# script binds to “in” property as a method parameter:
public static void Run(string message, System.TraceWriter log)
{
log.Info($"New message: {message}");
}
Describe in a json template:
{
"$schema":"https://schema.management.azure.com/schemas/2016-06-01/Microsoft.Logic.json",
"contentVersion":"1.0.0.0",
"parameters":
{
"uri":
{
"type":"string"
}
},
"triggers":
{
"request":{
"type":"request","kind":"http"
}
},
"actions":
{
"readData":
{
"type":"Http",
"inputs":
{
"method":"GET","uri":"@parameters('uri')"
}
}
},
"outputs": {}
}
…. | …… |
. | . | . | . | . |
.. | .. | .. | . |
. | . | . | . | . | . | . |
You get starter object injected in JS & C# (DurableOrchestrationClient)
If starter => existing instance (instanceid) exists
return HttpStatusCode.Conflict
else
starter => start new instance
starter => create response from instanceid
return response from starter
ConnectionClosed
, TimeOut
, RequestCanceled
Delay = TimeSpan.FromSeconds(5)
) and wait for the delay (Task.Delay
)throw
if retry count is maximum-query
argument to execute a JMESPath
query
JMESPath
=> JSON query language.-query
argument is supported by all commands in the Azure CLI.select
in LINQaz vm list --query '[].{name:name image:storageProfile.imageReference.offer}'
where
in LINQaz vm list --query "[?starts\_with(storageProfile.imageReference.offer, 'WindowsServer')]"
Combine project + filter
az vm list --query "[?starts\_with(storageProfile.imageReference.offer, 'Ubuntu')].{name:name, id:vmId}
azure.auth
file (JSON file describing, secret, key url’s etc)az ad sp create-for-rbac --sdk-auth > azure.auth
Azure azure = Azure.Authenticate("azure.auth").WithDefaultSubscription();
See VM’s
var vms = await azure.VirtualMachines.ListAsync();
foreach(var vm in vms)
{
Console.WriteLine(vm.Name);
}
Gather virtual machine metadata to determine the IP address
INetworkInterface targetnic = targetvm.GetPrimaryNetworkInterface();
INicIPConfiguration targetipconfig = targetnic.PrimaryIPConfiguration;
IPublicIPAddress targetipaddress = targetipconfig.GetPublicIPAddress();
Console.WriteLine($"IP Address:\t{targetipaddress.IPAddress}");
DocumentClient.CreateDocumentAsync
, DocumentClient.ReadDocumentAsync
, DocumentClient.ReadDocumentFeedAsync
(read all documents), DocumentClient.CreateDocumentQuery
, DocumentClient.ReplaceDocumentAsync
, DocumentClient.UpsertDocumentAsync
, DocumentClient.DeleteDocumentAsync
.E.g.
{
"deviceId": "abc-123",
"date": 2018,
"partitionKey": "abc-123-2018"
}
OfferThroughput = 100000
Latin1_General_CS_AS_KS_WS
, or Traditional_Spanish_ci_ai
ServerProperty('InstanceName')
MAX(<Total number of DBs X average DTU utilization per DB>)
New-AzureRmSqlServerCommunicationLink
: Create a new communication relationship between two SQL Database servers in Azure SQL Database. The relationship is symmetric which means both servers can initiate transactions with the other server.TransactionScope
class establishes an ambient transaction.
Ex:
using (var scope = new TransactionScope())
{
using (var conn1 = new SqlConnection(connStrDb1))
{
conn1.Open();
SqlCommand cmd1 = conn1.CreateCommand();
cmd1.CommandText = string.Format("insert into T1 values(1)");
cmd1.ExecuteNonQuery();
}
using (var conn2 = new SqlConnection(connStrDb2))
{
conn2.Open();
var cmd2 = conn2.CreateCommand();
cmd2.CommandText = string.Format("insert into T2 values(2)");
cmd2.ExecuteNonQuery();
}
scope.Complete();
}
OpenConnectionForKey
method of the elastic database client library to open connections for a scaled out data tier.C#:
using (var scope = new TransactionScope())
{
using (var conn1 = shardmap.OpenConnectionForKey(tenantId1, credentialsStr))
{
conn1.Open();
SqlCommand cmd1 = conn1.CreateCommand();
cmd1.CommandText = string.Format("insert into T1 values(1)");
cmd1.ExecuteNonQuery();
}
using (var conn2 = shardmap.OpenConnectionForKey(tenantId2, credentialsStr))
{
conn2.Open();
var cmd2 = conn2.CreateCommand();
cmd2.CommandText = string.Format("insert into T1 values(2)");
cmd2.ExecuteNonQuery();
}
scope.Complete();
}
sys.dm_tran_active_transactions
, sys.dm_tran_database_transactions
, sys.dm_tran_locks
.Example:
string query = "UPDATE [guitarBrands] SET type = @type, name = @name, image = @image WHERE id = @id";
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["brandsConnection"].ToString()))
using (SqlCommand command = new SqlCommand(query, connection)
{
try
{
// open the connection, execute, etc
List<SqlParameter> p = new List<SqlParameter>();
p.Add(new SqlParameter("@type", newType.Text));
p.Add(new SqlParameter("@name", newName.Text));
p.Add(new SqlParameter("@image", newImage.Text));
p.Add(new SqlParameter("@id", id));
connection.Open();
/* Submit query
command.ExecuteNonQuery(); // Non query does not return results
*/
/* Read
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("{0} , {1} , {2} , {3} , {4}",
reader.GetGuid(0),
reader.GetString(1),
reader.GetInt32(2),
(reader.IsDBNull(3)) ? "NULL" : reader.GetString(3),
(reader.IsDBNull(4)) ? "NULL" : reader.GetString(4));
}
} */
}
catch
{
// log and handle exception(s)
}
}