Exemple #1
0
        public async static Task ProcessAddStudentMessageAsync([QueueTrigger("%queueName%")] AddStudentMessage message, TextWriter logger)
        {
            await Console.Out.WriteAsync($"Starting processing request for user: '******'");

            try
            {
                var repository = new StudentRepository();
                var student    = new Student
                {
                    Id        = message.Id,
                    Age       = message.Age,
                    FirstName = message.FirstName,
                    LastName  = message.LastName
                };

                await repository.AddStudent(student);
            }
            catch (Exception ex)
            {
                var baseException = ex.GetBaseException();
                var messageJson   = JsonConvert.SerializeObject(message);
                var error         = $"Error Message: '{baseException.Message}'; Stack Trace: '{baseException.StackTrace}'; Queue Message: {messageJson}";
                await logger.WriteAsync(error);
            }

            await Console.Out.WriteAsync($"Completed processsing request for user: '******'");
        }
Exemple #2
0
        public async Task <Guid> Post(Student student)
        {
            var message = new AddStudentMessage(student.FirstName, student.LastName, student.Age);
            await _bus.PublishAsync(message);

            return(message.Id);
        }