Ich rufe eine asynchrone Methode InsertOperation von einer asynchronen Methode ConfigureConnectionString. Benutzt ich den client.OnMessage-Aufruf richtig? Ich möchte die Nachrichten in einer Warteschlange asynchron verarbeiten und sie dann im Warteschlangenspeicher speichern.Ist die Verwendung von QueueClient.OnMessage innerhalb einer asynchronen Methode sinnvoll?
private static async void ConfigureConnectionString()
{
var connectionString =
"myconnstring";
var queueName = "myqueue";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference("test");
table.CreateIfNotExists();
Stopwatch sw = Stopwatch.StartNew();
await Task.Run(() => InsertOperation(connectionString, queueName, table));
sw.Stop();
Console.WriteLine("ElapsedTime " + sw.Elapsed.TotalMinutes + " minutes.");
}
private static async Task InsertOperation(string connectionString, string queueName, CloudTable table)
{
var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
client.OnMessage(message =>
{
var bodyJson = new StreamReader(message.GetBody<Stream>(), Encoding.UTF8).ReadToEnd();
var myMessage = JsonConvert.DeserializeObject<VerifyVariable>(bodyJson);
Console.WriteLine();
var VerifyVariableEntityObject = new VerifyVariableEntity()
{
ConsumerId = myMessage.ConsumerId,
Score = myMessage.Score,
PartitionKey = myMessage.ConsumerId,
RowKey = myMessage.Score
};
});
}
Ihr Code, so wie er steht, ist etwas verwirrend - Sie verwenden beispielsweise nicht die Tabellenvariable, die Sie an InsertOperation übergeben. Kannst du die Logik erklären, die du erreichen willst? – PartlyCloudy