【问题标题】:How to send a message to azure service bus & event to event hub bus from single azure functions in NodeJS?如何从 NodeJS 中的单个 azure 函数将消息发送到 azure 服务总线和事件到事件中心总线?
【发布时间】:2019-04-29 07:56:11
【问题描述】:

我有一个 azure 函数,它发出基于承诺的 http post 请求并得到响应;现在我想将此响应发送到服务总线和不同的事件中心(天蓝色功能由不同的事件中心触发)。

函数表示在事件中心的情况下它已成功执行,但没有发送任何事件。 在服务总线的情况下,我收到此错误NamespaceConnectionString should not contain EntityPath.

module.exports = async function (context, eventHubMessages) {
    context.log(`JavaScript eventhub trigger function called for message array ${eventHubMessages}`);

    var completeData = '';

    eventHubMessages.forEach((message, index) => {
        context.log(`Processed message ${message}`);
        completeData = message;
    });

    var output = '';

    const axios = require('axios');

    try {
        const response =  await axios.post('http://fake-endpoint', 
        {  data-json : completeData
        })
        context.log(`statusCode: ${response.statusCode}`);
        context.log(response.data);
        output += response.data;

        var time = new Date().toString(); 
        context.log('Event Hub message created at: ', time);
        context.bindings.outputEventHubMessage = out;
        context.bindings.outputSbMsg = out;
        context.done()
        return response.data; // or return a custom object using properties from response
    } catch (error) {
        // If the promise rejects, an error will be thrown and caught here
        context.done(error);
    }

};

预期输出:成功执行;可在服务总线和事件中心接收的数据。 实际输出:Error: NamespaceConnectionString should not contain EntityPath.

【问题讨论】:

  • 你的连接字符串有实体路径吗?如果可以,您可以尝试删除它吗?
  • 连接字符串通常由ARM模板动态生成。

标签: node.js azure-functions httpresponse azureservicebus azure-eventhub


【解决方案1】:

正如错误消息所说,您需要查看连接字符串并删除 EntityPath 变量。 This is included 如果您在查看特定主题或队列时复制连接字符串,而不是从主服务总线刀片复制它。

Endpoint=sb://{servicebus-name}.servicebus.windows.net/;SharedAccessKeyName=test-queue-sender;SharedAccessKey={SharedAccessKey}=;EntityPath=test-queue;

对比

Endpoint=sb://{servicebus-name}.servicebus.windows.net/;SharedAccessKeyName=test-queue-sender;SharedAccessKey={SharedAccessKey};

【讨论】:

  • 这是有道理的,谢谢你的信息。问题是这个连接字符串通常是由 ARM 模板生成的。如何修改 ARM 模板以在连接字符串中不提供 EntityPath?
  • 您能否分享一下您正在使用的 ARM 模板以及如何部署它以获取该连接字符串?模板中可能有一些需要更改的地方,或者我需要向产品团队提出一些建议。如果您不想在 cmets 中讨论它,因为它与问题无关,您可以给我发送电子邮件至 azcommunity (at) microsoft.com,我们可以通过这种方式进行讨论。确保在电子邮件中包含指向此主题的链接,以便将其发送给我。
  • 感谢您的回复,我实际上设法使用字符串操作函数修剪了EntityPath。 "value": "[first(split(listkeys(variables('defaultAuthRuleResourceId'), variables('sbVersion')).primaryConnectionString, ';EntityPath='))]" 这是我的函数应用触发器所必需的,它不喜欢正在附加的 EntityPath。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-30
  • 1970-01-01
  • 2020-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多