使用SignalR天青与表的存储 - 什么架构? [英] Using SignalR with Azure Table Storage - What architecture?

查看:101
本文介绍了使用SignalR天青与表的存储 - 什么架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在多个硬件设备发送的原始传感器数据到Azure的队列中的智能电网系统。每个设备每分钟发送一个数据分组一次。多个工作者角色处理在队列中的数据报文和推的数据表的存储。我有一个包含应用程序供用户查看他们的设备的数据和有关其智能能源系统中的其他警报和消息的主机Web角色。目前,Web应用程序只使用Ajax轮询每隔一分钟,以获得最新的数据更新和任何其他消息和警报。相反,用ajax'拉',我想使用SignalR来代替,而推从云更新可用时。我不知道在整体架构可能的样子。

I have a smart grid system where multiple hardware devices are sending raw sensor data to an Azure Queue. Each device sends a single data packet once every minute. Multiple Worker Roles process the data packets on the queue and push the data to Table Storage. I have a Web Role which holds the application for users to view their device data and a host of other alerts and messages relating to their smart energy system. At the moment the web application just uses ajax polling at one minute intervals to get the latest data updates and any other messages and alerts. Instead of using ajax 'pulling', I'd like to use SignalR instead and 'push' the updates from the cloud when they become available. I'm not sure on what the overall architecture might look like.

到目前为止,我已经加了SignalR集线器到我的Web角色,只是为了看看,如果我能做到这一点。并能正常工作。然而,如何从这个枢纽触发更新,当有表存储的变化?我是否应该举办集线器与处理原始数据的工作者角色,然后进行从Web应用程序(客户端)跨域SignalR连接?我可以即使有工作者角色端点关联?如果我有很多工作者角色不会,我只能够连接到其中的一个,因此错过其他工作者角色数据更新?

So far I have added a SignalR Hub to my Web Role, just to see if I could do that. And it works fine. However, how do I trigger updates from this Hub when there are changes in Table Storage? Should I host the Hub with the Worker Roles that process the raw data, and then make a cross-domain SignalR connection from the web app (client)? Can I even associate an endpoint with a Worker Role? If I have many Worker Roles wouldn't I only be able to connect to one of them, and therefore miss data updates from other Worker Roles?

也许我应该创建一个单独的Web角色来承载SignalR枢纽,那我怎么沟通从处理原始数据到集线器的工作者角色的变化?也许我需要包括另一个天青队列,从有关的数据的更新,提醒工作者角色采取消息,以及任何其他消息,并且该队列由SignalR服务器处理。但是,将这种方法具有可扩展性?如果我有SignalR服务器处理消息队列(S)的多个实例,它们将共享同一个终点,了解整个情况下,所有客户端连接的?或者,也许工作者角色本身作为连接客户端的SignalR服务器和邮件转发从有到客户端。

Perhaps I should create a separate Web Role to host the SignalR hub, but then how do I communicate the changes from the Worker Roles that process the raw data to the hub? Maybe I need to include another Azure Queue that takes messages from the Worker Roles regarding data updates, alerts, and any other messaging, and that queue is processed by the SignalR server. However, would this approach be scalable? If I have multiple instances of the SignalR server processing the message queue(s), would they share the same end point and be aware of all the client connections across the instances? Or maybe the Worker Roles themselves connect as clients to the SignalR server and the messages forwarded from there to the clients.

时SignalR即使是在每分钟为每个设备一次的predictable率所产生的数据采取正确的方法。也许对于这种常规数据阿贾克斯'拉'是最好的方法,我应该只使用SignalR为罕见的警报和消息,虽然,再次,我怎么沟通从工作者角色,这些事件给SignalR服务器?的更新

Is SignalR even the right approach to take if data is being generated at a predictable rate of once every minute for each device. Maybe for updates of this regular data ajax 'pulling' is the best approach, and I should just be using SignalR for the infrequent alerts and messages, although, again, how do I communicate these events from the Worker Roles to the SignalR server?

什么整体架构会在这里适合我的需要?

What overall architecture would suit my needs here?

编辑2014年6月9日有一半的问题就迎刃而解了。

EDIT 06-09-2014 Half the problem solved

我碰到<少时href=\"http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/scaleout-with-windows-azure-service-bus\" rel=\"nofollow\">http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/scaleout-with-windows-azure-service-bus这似乎是我到底是什么了。这本书以多个集线器服务器(Web角色)实例的问题。现在我只需要一个可以在工作者角色运行,使他们可以通知新的数据可用集线器一个SignalR客户端库,然后集线器类可以提高路由新的数据到相应的连接的Web客户端。

I came across http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/scaleout-with-windows-azure-service-bus which seems to be exactly what I am after. This deals with the problem of multiple Hub server (Web Role) instances. Now I just need a SignalR client library that can run on the Worker Roles so that they can notify the Hub that new data is available, and the Hub class can then be enhanced to route the new data to the appropriate connected web clients.

编辑2014年6月10日一个可行的解决方案找到

EDIT 06-10-2014 A workable solution found

我添加了一个答案,我的什么建筑的问题。我以为我的设置的简单总结可能是有用的。我有不同的用户发布的实时数据天青队列相关的许多远程设备。发布到这些队列中的数据进行解析,并保存到表的存储,由多个工人角色。 Web角色为用户提供(客户端)的MVC5 Web应用程序登录并查看他们的数据。我想通过其中,当新的数据被张贴,任何连接的客户端会收到一个实时通知(和数据表格和图表中的客户端应用程序可以进行相应的更新)的机制。 SignalR与服务总线scaleout被证明是答案。

I have added an answer to my question of "What architecture". I thought a quick summary of my setup might be useful. I have many remote devices associated with different users posting real-time data to Azure Queues. The data posted to these queues are parsed and saved to Table Storage, by a number of Worker Roles. Web Roles provide the MVC5 web application for the users (clients) to log on and review their data. I wanted a mechanism by which when new data was posted, any connected clients would receive a real-time notification (and data tables and charts in the client apps could be updated accordingly). SignalR with Service Bus scaleout proved to be the answer.

推荐答案

我所需要的解决方案的第一部分是部署SignalR集线器客户端可以连接到,接收发送任何通知。我不能使用的基本SignalR解决方案作为MVC5 Web应用程序上可能有多个实例的Web角色托管 - 问题是如何保持所有这些实例同步,因此,无论实例的客户端连接到他们' ð仍然收到通知。 SignalR scaleout天青服务总线被证明是答案的问题的一部分。如何设置这件事的细节可以发现:<一href=\"http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/scaleout-with-windows-azure-service-bus\" rel=\"nofollow\">http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/scaleout-with-windows-azure-service-bus - 这是非常容易设置

The first part of the solution I needed was to deploy a SignalR hub that the clients could connect to, to receive any notifications sent. I couldn't use the basic SignalR solution as the MVC5 web app is hosted on a Web Role that will likely have more than one instance - the problem was how to keep all these instances synced so that whatever instance a client was connected to they'd still receive the notifications. SignalR scaleout with Azure Service Bus proved to be the answer to that part of the problem. Details of how to set this up can be found at: http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/scaleout-with-windows-azure-service-bus - it was VERY easy to setup.

问题的第二部分是如何产生的,从工作者角色(我的队列中的数据处理器)发起的通知。首先,我需要能够举办OWIN在我的辅助角色 - 在的http://www.asp.net/aspnet/overview/owin-and-katana/host-owin-in-an-azure-worker-role是绰绰有余了。一旦这样做是我创建了一个空枢纽实例相同名称的一个部署在我的Web角色(因为我没想到有连接到它直接在客户端里面是空的),并改变了启动类:

The second part of the problem was how to generate the notifications originating from the Worker Roles (my queue data processors). First I needed to be able to host OWIN in my worker roles - the instructions provided at http://www.asp.net/aspnet/overview/owin-and-katana/host-owin-in-an-azure-worker-role were more than sufficient. Once this was done I created an empty Hub instance with the same name as the one deployed on my Web Roles (it was empty because I didn't expect to have an clients connected to it directly), and changed the Startup class to:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        String connectionString = "[Service Bus Connection String]";
        GlobalHost.DependencyResolver.UseServiceBus(connectionString, "[App Name]");
        app.MapSignalR();
    }
}

有了这个地方,如果我想出去发送通知到客户端,从工作者角色,我​​做这样的事情:

With this in place if I want to send a notification out to the clients, from the Worker Roles, I do something like:

var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
context.Clients.All.clientMethod("[Message]");

什么是真正的情况是,该邮件的副本被推到背板(服务总线),并通过Web角色拾起并推送到连接的客户端。在现实中,我将检查谁在线(在Web角色枢纽比如我重写OnConnected方法来保存用户的连接ID,其中存储在表存储他们的个人资料),只有创建与这些用户相关联的通知,以减少SignalR流量。

What really happens is that a copy of the message gets pushed to the backplane (Service Bus) and is picked up by the Web Roles and pushed out to the connected clients. In reality I will check who is online (in the Web Role Hub instance I override the OnConnected method to save the user's connection id in their profile which is stored in Table Storage), and only create notifications that are associated with those users to reduce SignalR traffic.

这篇关于使用SignalR天青与表的存储 - 什么架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆