如何使用Azure中的nodejs创建用户组?
我试图复制.net SDK提供的内容,但它没有工作。
const { NamespaceManager } = require("@azure/service-bus");
let namespaceManager = NamespaceManager.CreateFromConnectionString(eventHubConnectionString);
let ehd = namespaceManager.GetEventHub(eventHubPath);
namespaceManager.CreateConsumerGroupIfNotExists(ehd.Path, consumerGroupName);发布于 2019-12-31 19:44:59
以下是起作用的过程:
https://learn.microsoft.com/en-us/rest/api/eventhub/create-consumer-group
步骤:
SAS令牌:
https://learn.microsoft.com/en-us/rest/api/eventhub/generate-sas-token
uri --即使是saName的url --托管策略saKey的名称-- eventhub管理策略的主/次键(确保它有管理)
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;
}请求参数:
网址:
头:
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.如果您注意到任何其他问题,请留下评论。
发布于 2019-12-31 01:00:52
事件中心Node.JS SDK不支持管理操作。
尝试像https://www.nuget.org/packages/Microsoft.Azure.Management.EventHub/这样的管理客户端
https://stackoverflow.com/questions/59536605
复制相似问题