.net核心发送和接收消息天蓝色serviceBus

时间:2019-02-11 10:02:24

标签: core azureservicebus

此代码出现超时错误

  

连接尝试失败,因为被连接方未   一段时间后正确响应或建立连接   失败,因为连接的主机未能响应错误代码:   超时

我认为这是防火墙问题,但是我可以在.net框架中编写相同的代码(使用相同的connectionString),并且我成功发送了消息,因此它不可能是防火墙问题吗?但是通过尝试.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);
              }`

0 个答案:

没有答案