示例#1
0
文件: Program.cs 项目: Knafox/School
        static async Task SendStudentInfo()
        {
            queueClient = new QueueClient(connectionString, queueName);

            Console.WriteLine("==================================");
            Console.WriteLine("====== Sending Student Info ======");
            Console.WriteLine("==================================");

            for (int i = 0; i < 25; i++)
            {
                // Create a new new student to send to the queue
                StudentInfo.StudentInfo newStudent = new StudentInfo.StudentInfo(1111, "Bob Smith",
                                                                                 "222-333-1111", "*****@*****.**", "215-777-8888", "123 Tulip Road, Ambler, PA 19002",
                                                                                 "321 Maple Avenue, Lion Town, PA 16800", "John Smith (215-222-6666)", 206, "1111-206", 1);

                string messageBody = JsonConvert.SerializeObject(newStudent);
                var    message     = new Message(Encoding.UTF8.GetBytes(messageBody));

                Console.WriteLine($"Sending new student");

                // Send the message to the queue
                await queueClient.SendAsync(message);
            }

            Console.ReadKey();

            await queueClient.CloseAsync();
        }
示例#2
0
        static async Task ProcessMessagesAsync(Message message, CancellationToken token)
        {
            Random random     = new Random();
            int    DeadLetter = random.Next(1, 3);

            if (DeadLetter == 1)
            {
                Console.WriteLine($"Purposefully Dead-Lettering.");
                await queueClient.AbandonAsync(message.SystemProperties.LockToken);
            }
            else
            {
                // Process the message
                StudentInfo.StudentInfo newStudent = JsonConvert.DeserializeObject <StudentInfo.StudentInfo>(Encoding.UTF8.GetString(message.Body));

                Console.WriteLine($"New Student Recieved: {newStudent.Name}");

                await queueClient.CompleteAsync(message.SystemProperties.LockToken);
            }
        }