4Manuals

  • PDF Cloud HOME

如何在Azure中使用Node.js以编程方式为Eventhub创建ConsumerGroups? Download

    如何删除外部索引并合并内部json Mocha-无法实现TestFunction接口方法 如何使用ffmpeg创建带下划线的水印文本 如何将自定义错误从Lambda发送到Api网关 使用Node和Python哈希页面源时的区别 清单提取失败,返回状态404 构建StaticInjectorError时出现Angular 7 HttpContext.User.Identity.Name在Azure服务器上不起作用 如何设置偏执狂:sequelize中的所有查询都为false? 如何在Godadday上使用托管网址解决bot框架模拟器中的404发布错误?

如何在Azure中使用nodejs在eventhub中创建使用者组?

试图复制.net SDK提供的内容,但无效。

const { NamespaceManager } = require("@azure/service-bus");                                                                                                   
let namespaceManager = NamespaceManager.CreateFromConnectionString(eventHubConnectionString);                                                                 
let ehd = namespaceManager.GetEventHub(eventHubPath);                                                                                                         
namespaceManager.CreateConsumerGroupIfNotExists(ehd.Path, consumerGroupName);

任何指针都会有所帮助。

2 个答案:

答案 0 :(得分:1)

这是有效的过程:

https://docs.microsoft.com/en-us/rest/api/eventhub/create-consumer-group

步骤:

  1. 创建SAS令牌
  2. 提供正确的标题并对REST api进行https调用
  3. 您只能创建一次,如果第二次调用,它将抛出409错误。如果要更新或插入呼叫,则需要检查。

SAS令牌:

https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token

uri-您的eventhub的网址 saName-您的托管策略的名称 saKey-EventHub管理策略的主键/辅助键(确保它具有Manage)

function createSharedAccessToken(uri, saName, saKey) { 
    if (!uri || !saName || !saKey) { 
            throw "Missing required parameter"; 
        } 
    var encoded = encodeURIComponent(uri); 
    var now = new Date(); 
    var week = 60*60*24*7;
    var ttl = Math.round(now.getTime() / 1000) + week;
    var signature = encoded + '\n' + ttl; 
    var signatureUTF8 = utf8.encode(signature); 
    var hash = crypto.createHmac('sha256', saKey).update(signatureUTF8).digest('base64'); 
    return 'SharedAccessSignature sr=' + encoded + '&sig=' +  
        encodeURIComponent(hash) + '&se=' + ttl + '&skn=' + saName; 
}

请求参数:

URL:

  

https://your-namespace.servicebus.windows.net/your-event-hub/consumergroups/testCG?timeout=60&api-version=2014-01

标题:

Content-Type: application/atom+xml;type=entry;charset=utf-8
Host: your-namespace.servicebus.windows.net
Authorization: {replace with the content from your SAS Token}

有效载荷:

<entry xmlns="http://www.w3.org/2005/Atom">  
   <content type="application/xml">  
      <ConsumerGroupDescription xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">Any name you want</ConsumerGroupDescription>  
   </content>  
</entry>

可能的退货状态:

201 -- Successful Creation
404 -- Not found, you are using a name that does not exist
409 -- The messaging entity 'XXX' already exists.

如果您发现任何其他问题,请发表评论。

答案 1 :(得分:0)

事件中心Node.JS SDK不支持管理操作。

尝试使用https://www.nuget.org/packages/Microsoft.Azure.Management.EventHub/之类的管理客户端



Similar searches
    用可选参数调用类 在协程中使用runBlocking会发生什么不好的事情吗? 如何在Power Apps应用程序中使用单个电子邮件发送电子邮件而无需用户的Outlook电子邮件 TypeError:__init __()接受1个位置参数,但给出了2个(无继承) 清除输入类型=“日期”时如何捕获?