[英]Using a Node js Azure function to send custom properties on a message to a service bus topic
[英]Azure Service Bus Topic - delays when receiving a message using the Node.js SDK
我正在使用最新的可用 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,我也會觀察到所描述的延遲。
如果有人能幫助我了解導致這種行為的原因,我將不勝感激。 先感謝您。
嘗試對分區實體使用會話。 在我的測試中,在消息中添加sessionId
后,延遲平均下降到 2 秒。
例如
var topicMsg = {
body: new Date().toISOString(),
brokerProperties:{
SessionId:'mysession'
}
};
看起來您正在使用依賴於 HTTP REST api 的舊版azure-sb
包。 我建議使用較新的@azure/service-bus
包,它使用更快的 AMQP 實現,並且沒有您發現會導致延遲的調用
我知道這是一個遲到的回復,但以防萬一有人遇到舊服務總線節點 SDK 的問題並登陸這里,請參閱下面的鏈接。
@azure/service-bus
的最新版本 7.0.0(基於 AMQP - 更快/性能更好)已經發布。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.