public static async Task <HttpResponseMessage> UpdateCounter( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, [Table(c_tableName)] CloudTable cloudTable, [SignalR(HubName = c_eventHubName, ConnectionStringSetting = c_signalRConnectionString)] IAsyncCollector <SignalRMessage> signalRMessages, ILogger log) { try { log.LogInformation($"Incoming request to {nameof(UpdateCounter)}"); var dto = await ExtractContent <CounterDTO>(req); var counter = (Counter)dto; var counterProvider = new CounterProvider(); // write counter to table var updateTask = counterProvider.UpdateCounter(cloudTable, counter); // update signal r var sendMessageTask = SendSignlRMessage(signalRMessages, counter.ToDTO()); await Task.WhenAll(updateTask, sendMessageTask); } catch (Exception ex) { log.LogError(ex, $"Exception in {nameof(UpdateCounter)}: {ex.Message}"); return(req.CreateResponse(HttpStatusCode.InternalServerError)); } return(req.CreateResponse(HttpStatusCode.OK)); }
public static async Task MessageReceiver( [EventHubTrigger(c_eventHubName, Connection = c_eventHubConnectionString)] EventData message, [Table(c_tableName)] CloudTable cloudTable, [SignalR(HubName = c_eventHubName, ConnectionStringSetting = c_signalRConnectionString)] IAsyncCollector <SignalRMessage> signalRMessages, ILogger log) { try { log.LogInformation($"Incoming request to {nameof(MessageReceiver)}"); var counterProvider = new CounterProvider(); // get counter var counter = await counterProvider.GetCounter(cloudTable, "counter"); // update counter value counter.Count++; log.LogInformation($"New counter value {counter.Count}"); // write counter to table var updateTask = counterProvider.UpdateCounter(cloudTable, counter); // update signal r var sendMessageTask = SendSignlRMessage(signalRMessages, counter.ToDTO()); await Task.WhenAll(updateTask, sendMessageTask); } catch (Exception ex) { log.LogError(ex, $"Exception in {nameof(MessageReceiver)}: {ex.Message}"); } }