Пример #1
0
        public async Task SendMessageAsync(string queueName, object obj)
        {
            string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];

            // create a Service Bus client
            await using (ServiceBusClient client = new ServiceBusClient(connectionString))
            {
                // create a sender for the queue
                ServiceBusSender sender = client.CreateSender(queueName);


                string messageBody = JsonConvert.SerializeObject(obj);
                // create a message that we can send
                ServiceBusMessage message = new ServiceBusMessage(Encoding.UTF8.GetBytes(messageBody));

                // send the message
                await sender.SendMessageAsync(message);

                Console.WriteLine($"Sent a single message to the queue: {queueName}");
            }
        }