【问题标题】:Azure Service Bus Topic - delays when receiving a message using the Node.js SDKAzure 服务总线主题 - 使用 Node.js SDK 接收消息时出现延迟
【发布时间】:2016-01-06 19:47:43
【问题描述】:

我正在使用最新的可用 npm 包 - 0.10.6 (https://www.npmjs.com/package/azure) 试验 Azure Node.js SDK 和服务总线主题。 我想发布一条新消息并使用以下代码接收它:

var azure = require('azure');

var connectionString = "Endpoint=sb://sfbustest.servicebus.windows.net/;SharedAccessKeyName={key-name};SharedAccessKey={access-key}";
var topicName = "{topic-name}";
var subscriptionName = "{subscription-name}";

var serviceBusService = azure.createServiceBusService(connectionString);

serviceBusService.getSubscription(topicName, subscriptionName, function(error, subscription){
        //if(error) return callback(error);
        if(!subscription){
            serviceBusService.createSubscription(topicName, subscriptionName, function (error) {
                if (error) throw error;

                postMessage_retreiveMessage(null);
            });
        } else {
            postMessage_retreiveMessage(null);
        }

    });

//postMessage_retreiveMessage();
function postMessage_retreiveMessage(){
    var topicMsg = {
        body: new Date().toISOString()
    };

    serviceBusService.sendTopicMessage(topicName, topicMsg, function (error) {
        if(error) throw error;

        console.log("message sent: ");
        console.log(topicMsg);

        var receiveOptions = { /* isPeekLock: true, */ timeoutIntervalInS: 30 };

        serviceBusService.receiveSubscriptionMessage(topicName, subscriptionName, receiveOptions, function(error, receivedMessage){
            if(error) throw error;

            console.log("message received: ");
            console.log(receivedMessage);
        });
    });
}

问题: 当创建主题并启用 分区 - 如果主题是通过管理门户创建的,这是默认设置 - 在这种情况下,我在最终收到消息之前会遇到巨大的延迟。

但此行为无法通过 .NET SDK 重现。

此外,如果 分区已关闭,那么我不会再遇到任何明显的延迟,并且该行为也不再可重现。

查看适用于 Node.js 的 Azure SDK,我注意到调用了以下端点(当调用 receiveSubscriptionMessage 时):

https://sfbustest.servicebus.windows.net:443/{topic-name}/Subscriptions/{subscription-name}/Messages/Head?timeout=30&api-version=2013-10.

其文档可在此处获得:https://msdn.microsoft.com/en-us/library/azure/hh780770.aspx。 在文档的介绍部分中,说明 HTTP API 支持分区实体:https://msdn.microsoft.com/en-us/library/azure/dn798895.aspx

如果我手动调用该端点,例如使用 Fiddler,我也会观察到所描述的延迟。

如果有人能帮助我了解导致这种行为的原因,我将不胜感激。 提前谢谢你。

【问题讨论】:

    标签: node.js azure servicebus


    【解决方案1】:

    尝试Use sessions with partitioned entities。 在我的测试中,在消息中添加sessionId 后,延迟平均下降到 2 秒。

    例如

     var topicMsg = {
            body: new Date().toISOString(),
            brokerProperties:{
                SessionId:'mysession'
            }
        };
    

    【讨论】:

    【解决方案2】:

    看起来您正在使用依赖于 HTTP REST api 的较旧的 azure-sb 包。我建议使用较新的 @azure/service-bus 包,它使用更快的 AMQP 实现,并且不会发出您发现会导致延迟的呼叫

    【讨论】:

      【解决方案3】:

      我知道这是一个迟到的回复,但以防万一有人遇到旧的服务总线节点 SDK 的问题并登陆这里,请参阅下面的链接。

      @azure/service-bus(基于 AMQP - 更快/性能更好)的最新版本 7.0.0 已经发布。

      【讨论】:

        猜你喜欢
        • 2017-04-16
        • 1970-01-01
        • 1970-01-01
        • 2021-05-23
        • 2022-01-09
        • 2022-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多