c# - 为什么我无法使用 Azure 服务总线队列获取队列消息?

标签 c# azure azure-servicebus-queues

我正在关注如何在 Azure 上使用服务总线队列文档。

我创建了 2 个不同的 Web 应用程序来测试我需要处理的项目是否使用队列。我创建了一个项目来将消息发布到队列中,然后另一个应用程序应该监听队列来处理消息。

我成功地将消息发布到队列,并且我可以看到 Azure 门户中的队列长度显示为 3。因此应该有 3 条消息等待我处理。但是,当我运行具有 QueueClient.OnMessage 的 Web 应用程序时,不会推送任何消息。这样做时我还遗漏了什么吗?

var client = QueueClient.CreateFromConnectionString(ConnectionString, "TestQueue");

        var options = new OnMessageOptions
        {
            AutoComplete = false,
            AutoRenewTimeout = TimeSpan.FromMinutes(1)
        };

        // Callback to handle received messages.
        client.OnMessage((message) =>
        {
            try
            {
                // Process message from queue.
                var messageBody = message.GetBody<string>();
                // Remove message from queue.
                message.Complete();
            }
            catch (Exception)
            {
                // Indicates a problem, unlock message in queue.
                message.Abandon();
            }
        }, options);
    }
}

两个应用程序中的 ConnectionString 是相同的,因此没有区别。 这是我用来连接队列并向队列发送消息的代码。

var client = QueueClient.CreateFromConnectionString(ConnectionString, "TestQueue");
        var message = new BrokeredMessage(value);

        message.Properties["TestProperty"] = "This is a test";
        message.Properties["UserId"] = "TestUser";

        client.Send(message);

如果有人对为什么会发生这种情况有任何见解,我们将不胜感激。

最佳答案

事实证明,当我尝试连接到服务总线时遇到了 407 Proxy Authentication required 错误,我在尝试通过不同的应用程序进行调试时注意到了这一点。 我所要做的就是将以下内容添加到 web.config 的 system.net 部分,一旦我能够接收消息。

<defaultProxy useDefaultCredentials="true">
<proxy bypassonlocal="True" usesystemdefault="True"/>
</defaultProxy>

关于c# - 为什么我无法使用 Azure 服务总线队列获取队列消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34188884/

相关文章:

Azure 服务总线消息生存时间设置

c# - Azure服务总线 "ReceiveAsync"

c# - LINQ 查询将列表中的几个项目变为选中状态

azure - 使用 AzureFileCopy 任务覆盖 Azure Blob 存储中的文件

azure - 尝试联系 Azure 中的认知服务时出现未经授权的异常消息

c# - 未收到 Azure 服务总线消息

c# - 从另一个应用程序添加/启动/停止 IoT Core 应用程序

c# - 动态 log4net 附加程序名称?

c# - 一个很好的 C# 集合

azure - 通过 ARM 模板将现有混合连接链接到 azure Web 应用程序