Exemple #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log, ExecutionContext context)
        {
            ArcusEventGridClient.SaveContext(context);

            var events = new List <CarSpeedingEvent> {
            };

            try
            {
                var requestBody = new StreamReader(req.Body).ReadToEnd();
                log.LogInformation(requestBody);
                var speedingList = JsonConvert.DeserializeObject <IEnumerable <CarSpeedingData> >(requestBody);
                events.AddRange(speedingList.Select(carSpeedingData =>
                                                    new CarSpeedingEvent(
                                                        Guid.NewGuid().ToString("N"),
                                                        $"traffic/{carSpeedingData.TrajectId}",
                                                        carSpeedingData)));
                await ArcusEventGridClient.Publisher.PublishMany(events);

                return((ActionResult) new OkObjectResult("received"));
            }
            catch (Exception e)
            {
                log.LogError(e, $"Error occurred when sending event grid messages: {e.Message}");
                return(new InternalServerErrorResult());
            }
        }
Exemple #2
0
        public static async Task Run([EventHubTrigger("savanh-traffic-suspects", Connection = "suspected-cars-eventhub")]
                                     string suspectedCarMessage, ILogger log, ExecutionContext context)
        {
            ArcusEventGridClient.SaveContext(context);

            try
            {
                log.LogInformation($"C# Event Hub trigger function processed a message: {suspectedCarMessage}");
                var suspectedCar      = JsonConvert.DeserializeObject <SuspectedCarData>(suspectedCarMessage);
                var suspectedCarEvent =
                    new SuspectedCarDetectedEvent(
                        Guid.NewGuid().ToString("N"),
                        $"traffic/{suspectedCar.TrajectId}",
                        suspectedCar);
                await ArcusEventGridClient.Publisher.Publish(suspectedCarEvent);
            }
            catch (Exception e)
            {
                log.LogError(e, $"Error occurred when sending event grid messages: {e.Message}");
            }
        }