【问题标题】:Service Bus Not Reading from Subscription服务总线未从订阅中读取
【发布时间】:2017-06-09 19:40:03
【问题描述】:

我正在创建一个示例 Azure 服务总线应用程序。我创建了一个命名空间、主题和订阅。我已经为该主题编写了测试消息,如果我转到门户中的订阅,我会看到每次使用编写器应用程序编写新消息时都会收到一条新消息。

但是当我去拉消息时,什么都没有检索到。在故障排除中,我将订阅名称更改为不正确的值并收到错误消息。我改回来了,当我查看 Azure 门户时,我没有得到任何输出,也没有删除任何消息。我被卡住了……这看起来很简单,但它不起作用。

string connectionString = "Endpoint=sb://redacted for obvious reasons";

        SubscriptionClient Client = SubscriptionClient.CreateFromConnectionString(connectionString, "NewOrders", "AllOrders");

        // Configure the callback options.
        OnMessageOptions options = new OnMessageOptions();
        options.AutoComplete = false;
        options.AutoRenewTimeout = TimeSpan.FromMinutes(1);

        Client.OnMessage((message) =>
        {
            try
            {
                Console.WriteLine("Body: " + message.GetBody<string>());

                message.Complete();
                Console.ReadLine();
            }
            catch (Exception)
            {
                // Indicates a problem, unlock message in subscription.
                message.Abandon();
            }
        }, options);

【问题讨论】:

  • 您的订阅 AllOrders 是如何配置的?你能在 GitHub 上分享你的代码复制吗?
  • 您正在运行控制台应用程序吗?你阻止线程不终止应用程序吗?

标签: azure azureservicebus


【解决方案1】:

似乎不是代码问题。我创建了一个演示来从主题中检索消息,它可以正常工作。 在我尝试从主题检索消息之前,我将消息发送到主题或确保有订阅消息。我们可以从门户网站上查看

发送消息代码演示。

 private static void SendMessages()
 {
    topicClient = TopicClient.Create(TopicName);

    List<BrokeredMessage> messageList = new List<BrokeredMessage>
    {
       CreateSampleMessage("1", "First message information"),
       CreateSampleMessage("2", "Second message information"),
       CreateSampleMessage("3", "Third message information")
    };

    Console.WriteLine("Sending messages to topic...");
    foreach (BrokeredMessage message in messageList)
    {
       while (true)
       {
          try
          {
             topicClient.Send(message);
          }
          catch (MessagingException e)
          {
              if (!e.IsTransient)
              {
                  Console.WriteLine(e.Message);
                  throw;
              }
           }
           Console.WriteLine($"Message sent: Id = {message.MessageId}, Body = {message.GetBody<string>()}");
           break;
        }
    }

      topicClient.Close();
}

我也尝试了您提到的代码,它对我来说也可以正常工作。

我们也可以从模板中的云项目中获取演示项目。我们还可以从文档中获得有关How to use Service Bus topics and subscriptions 的更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2019-02-12
    • 2013-02-12
    相关资源
    最近更新 更多