コード例 #1
0
        public static async Task Run([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log)
        {
            var eventData = eventGridEvent.Data.ToString();

            log.LogInformation($"EventGridTrigger: event data: {eventData}");

            var response = await WebhookClient.PostAsync(eventData, log);

            if (response == null)
            {
                log.LogInformation("EventGridTrigger: No WebhookEndpointUrl is configured");
            }
        }
コード例 #2
0
        public static async Task Run([EventHubTrigger("%EventHubName%", Connection = "EventHubConnection")] EventData[] events, ILogger log)
        {
            var exceptions = new List <Exception>();

            foreach (EventData eventData in events)
            {
                try
                {
                    string messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);

                    // Replace these two lines with your processing logic.
                    log.LogInformation($"C# Event Hub trigger function processed a message: {messageBody}");
                    var response = await WebhookClient.PostAsync(messageBody, log);

                    if (response == null)
                    {
                        log.LogInformation("No WebhookEndpointUrl is configured");
                    }
                }
                catch (Exception e)
                {
                    // We need to keep processing the rest of the batch - capture this exception and continue.
                    // Also, consider capturing details of the message that failed processing so it can be processed again later.
                    exceptions.Add(e);
                }
            }

            // Once processing of the batch is complete, if any messages in the batch failed processing throw an exception so that there is a record of the failure.
            if (exceptions.Count > 1)
            {
                throw new AggregateException(exceptions);
            }

            if (exceptions.Count == 1)
            {
                throw exceptions.Single();
            }
        }