Beispiel #1
0
        private static void StartSender()
        {
            var sender = new ServiceBusQueueSender(QueueConnectionString, DataQueueName);

            while (true)
            {
                Console.WriteLine("Enter number of messages.");
                var messageCount = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());

                var sessionId = Guid.NewGuid().ToString();
                var messages  = Enumerable.Range(0, messageCount)
                                .Select(i => new Message(Encoding.UTF8.GetBytes($"Hello world {i}"))
                {
                    SessionId = sessionId
                });

                Console.WriteLine($"SessionId: {sessionId}");

                try
                {
                    foreach (var message in messages)
                    {
                        sender.SendAsync(message).GetAwaiter().GetResult();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
 public HomeController(ServiceBusQueueSender queueSender)
 {
     this.queueSender = queueSender;
 }