.net core отправка и получение сообщений Azure ServiceBus - PullRequest
0 голосов
/ 11 февраля 2019

У меня ошибка тайм-аута с этим кодом

Попытка подключения не удалась, потому что подключенная сторона не ответила должным образом через некоторое время, или не удалось установить соединение, так как подключенный хост не смог ответить ErrorCode: TimedOut

Я думал, что это проблема с брандмауэром, но я могу написать тот же код в .net Framework (используя ту же строку подключения), и я успешно отправил сообщение, поэтому оно не может бытьпроблема с брандмауэром?но с этим попробовать ядро ​​.net у меня эта ошибка TimedOut

public static void Main(string[] args)
        {
            MainAsync(args).GetAwaiter().GetResult();
        }
private static async Task MainAsync(string[] args)
                      {
                          var builder = new ConfigurationBuilder()
                              .SetBasePath(Directory.GetCurrentDirectory())
                              .AddJsonFile("AppSettings.json", true, true).Build();

                          // Read the Azure Service Bus endpoint connection string from App.config file.
                          _connectionString = builder["Value"];

                          _queueName = builder["QueueName"];


                          Console.WriteLine("\nCreating Queue '{0}'...", _queueName);
                          queueClient = new QueueClient(_connectionString, _queueName, ReceiveMode.PeekLock);
                          await SendMessagesToQueue("sending a message to a service bus from.net core app");
                          // Close the client after the ReceiveMessages method has exited.
                          await queueClient.CloseAsync();
                          Console.WriteLine("Press any key to exit.");
                          Console.ReadLine();
                      }

              private static async Task SendMessagesToQueue(string messageBody)
              {

                  try
                  {

                      // Create a new brokered message to send to the queue
                      var message = new Message(Encoding.UTF8.GetBytes(messageBody));
                      // Write the body of the message to the console
                      Console.WriteLine($"Sending message: {Encoding.UTF8.GetString(message.Body)}");
                      // Send the message to the queue


                      await queueClient.SendAsync(message);

                  }

                  catch (Exception exception)
                  {
                      Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");

                  } // Delay by 10 milliseconds so that the console can keep up
                  await Task.Delay(1000);
              }`
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...