【发布时间】:2022-08-24 14:01:57
【问题描述】:
我正在尝试使用以下代码向 Azure 事件中心发送消息:
var producer = new EventHubProducerClient(
ConfigurationManager.AppSettings[\"EventHubConnectionString\"],
ConfigurationManager.AppSettings[\"EventHubName\"]
);
SAS 密钥(连接字符串)是正确的,它位于实例级别(不是命名空间),这是 Azure.Messaging.EventHubs.Producer 库所要求的(但我都尝试了), 不幸的是,它返回以下错误:
---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebRequest.<>c.<GetResponseAsync>b__68_2(IAsyncResult iar)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)...
-
这似乎不是事件中心错误。事件中心没有 HTTP 堆栈,客户端完全基于 AMQP。还值得注意的是,客户端会懒惰地建立连接;如果您在该 sn-p 中看到它,则表明配置系统中正在发生某些事情。
标签: c# azure events azure-eventhub