带有 amqp.net lite 的 azure eventhub 的 SAS 令牌身份验证

SAS Token auth for azure eventhub with amqp.net lite

我目前正在使用 amqp.net lite 和单声道从我的 raspberry pi 向 azure eventhub 发送消息。

我的连接字符串如下所示:amqps://SendMessage:[url encoded key]@[sb namespace]

这很好用,但现在我想改用 SAS 令牌。 在这种情况下,有效的连接字符串会是什么样子? 到目前为止,我尝试过的都没有用。

P.S。我没有使用 Microsoft 的官方 NuGet 包,因为它不适用于 mono

amqps://[SharedAccessKeyName]:[url 编码的 SharedAccessKey]@[sb 命名空间]

SharedAccessKeyName 和 SharedAccessKey 是从门户获取的策略名称和令牌。

        string eventhubHostFormat = "amqps://{0}:{1}@{2}.servicebus.windows.net";

        var address = new Address(string.Format(eventhubHostFormat, "your SAS policy name", Uri.EscapeUriString("your SAS key"), "your servicebus name"));
        var eventHubConnection = new Connection(address);
        var eventHubSession = new Session(eventHubConnection);
        var eventHubSender = new SenderLink(eventHubSession, "0" /* partition ID */, "your eventhub name");

好的,here does work. Read the last section titled "Using the Shared Access Signature (at AMQP level)". It describes how to use SAS tokens with Amqp.NET Lite which is pretty low level. Use Azure SB Lite 描述的机制更简单。它仍然基于 Amqp.NET Lite,但提供了更多抽象。