简体   繁体   English

读取Azure Service Bus队列

[英]Reading Azure Service Bus Queue

I'm simply trying to work out how best to retrieve messages as quickly as possible from an Azure Service Bus Queue. 我只是在尝试找出如何最好地从Azure Service Bus队列中尽快检索消息。

I was shocked that there wasn't some way to properly subscribe to the queue for notifications and that I'm going to have to poll. 我感到震惊的是,没有任何方法可以正确地订阅通知队列,而我将不得不进行轮询。 (unless I'm wrong in which case the documentation is terrible). (除非我错了,在这种情况下文档很糟糕)。

I got long polling working, but checking a single message every 60 seconds looks like it'll cost around £900 per month (again, unless I've misunderstood that). 我的轮询工作很长,但是每60秒检查一条消息似乎每月大约需要花费900英镑(再次,除非我误解了)。 And if I add a redundant/second service to poll it'll double. 而且,如果我添加一个冗余/秒服务来进行轮询,它将会加倍。

So I'm wondering what the best/most cost efficient way of doing it is. 所以我想知道最好/最经济的方式是什么。

Essentially I just want to take a message from the queue, perform an API lookup on some internally held data (perhaps using hybrid services?) and then perhaps post a message back to a different queue with some additional information . 本质上,我只是想从队列中获取一条消息,对一些内部保存的数据执行API查找(也许使用混合服务?),然后再将消息与一些其他信息一起发回到另一个队列中。

I looked at worker roles(?) -- is that something that could do it? 我看着工人角色(?)-可以做到吗?

I should mention that I've been looking at doing this with node.js. 我应该提到的是,我一直在考虑使用node.js做到这一点。

Check out these videos from Scott Hanselman and Mark Simms on Azure Queues. 在Azure Queues上查看Scott Hanselman和Mark Simms的这些视频。 It's C# but you get the idea. 它是C#,但您明白了。

https://channel9.msdn.com/Search?term=azure%20queues%20simms#ch9Search https://channel9.msdn.com/Search?term=azure%20queues%20simms#ch9Search

Touches on: 涉及:

  • Storage Queues vs. Service Bus Queues 存储队列与服务总线队列
  • Grabbing messages in bulk vs. one by one (chunky vs. chatty) 批量处理邮件,而不是一对一地处理(粗俗与闲聊)
  • Dealing with poison messages (bad actors) 处理有毒信息(坏演员)
  • Misc implementation details 杂项实施细节
  • Much more stuff i can't remember now 我现在不记得了更多的东西

As for your compute, you can either do a VM, a Worker Role (Cloud Services), App Service Webjobs, or Azure Functions. 至于您的计算,您可以执行VM,辅助角色(云服务),App Service Webjob或Azure Functions。

The Webjobs SDK and Azure Functions bot have a way to subscribe to Queue events (notify on message). Webjobs SDK和Azure Functions机器人可以订阅队列事件(在消息中通知)。

(Listed from IaaS to PaaS to FaaS - Azure Functions - if such a thing exists). (从IaaS到PaaS到FaaS列出-Azure Functions-如果存在这种情况)。

Azure Functions already has sample code provided as templates to do all that with Node. Azure Functions已经提供了示例代码作为模板,以对Node进行所有操作。 Just make a new Function and follow the wizard. 只需创建一个新功能并按照向导进行操作即可。

If you need to touch data on-prem you either need to look at integrating with a VNET that has site-to-site connectivity back to your prem, or Hybrid Connections (App Service only!). 如果您需要在企业内部接触数据,则需要考虑与具有回到企业内部的站点到站点连接的VNET或混合连接(仅适用于App Service!)集成。 Azure Functions can't do that yet, but every other compute is a go. Azure Functions尚不能做到这一点,但是其他所有计算都是可以的。

https://azure.microsoft.com/en-us/documentation/articles/web-sites-hybrid-connection-get-started/ (That tutorial is Windows only but you can pull data from any OS. The Hybrid Connection Manager has to live on a Windows box, but then it acts as a reverse proxy to any host on your network). https://azure.microsoft.com/zh-cn/documentation/articles/web-sites-hybrid-connection-get-started/ (该教程仅适用于Windows,但您可以从任何操作系统中提取数据。Hybrid Connection Manager具有(位于Windows机器上),但它充当网络上任何主机的反向代理)。

To deal with Azure ServiceBus Queue easily, the best option seems to be Azure Webjob . 为了轻松处理Azure ServiceBus队列,最好的选择似乎是Azure Webjob

There is a ServiceBusTrigger that allows you to get messages from an Azure ServiceBus queue. 有一个ServiceBusTrigger ,可让您从Azure ServiceBus队列中获取消息。

For node.js integration, you should have a look at Azure Function . 对于node.js集成,您应该看看Azure Function It is built on top of the webjob SDK and have node.js integration : 它基于webjob SDK构建,并具有node.js集成:

In the second article, there is an example on how get messages from a queue using Azure Function and nodejs : 在第二篇文章中,有一个示例如何使用Azure Function和nodejs从队列获取消息:

module.exports = function(context, myQueueItem) {
    context.log('Node.js ServiceBus queue trigger function processed message', myQueueItem);
    context.done();
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM