如何在 azure table 存储中插入新数据后立即收到通知

How to get notified as soon as new data gets inserted in azure table storage

我有一个 Azure Table 存储,希望从 Web 服务插入数据。

我的应用程序(ASP.Net MVC,VS 2017)实施了 SignalR 以接收来自 Azure Table 存储的任何更改数据。

我的问题

新数据到达 Table 存储后,只有当我刷新浏览器时,最新数据才会自动反映在任何其他打开的浏览器中 - 无论是在同一台计算机还是不同的计算机上 systems.It 都不会一旦新数据进入 Table 存储,它就会自动在任何打开的浏览器中显示更改的值。 我想这可能是因为当我刷新浏览器时,根据我的代码,它从 Table 获取数据并且 SignalR 触发将数据发送给其他客户端。

因此,每当有新数据到达时,从 Table 发送通知就存在差距。

我的查询

  1. 我在这里缺少什么 - 它不会自动在浏览器上显示最新数据?

  2. 还是Table存储没有任何通知机制来通知新数据到达? 如果是这样,当新数据到达 Azure Table 存储时应该做什么接收通知?

我的操作方法

[HttpGet]
    public ActionResult Index()
    {
        var model = SignalRepository.LatestSignalCollection();// Connects with Azure to fetch the latest 5 records
        return View(model);

    }

我的 SignalR Hub 代码

public SignalHub()
    {
        SignalRepository.SignalSubscriber();
        var signalData = SignalRepository.LatestSignalCollection(); //LatestSignalCollection() ===>  Connects with Azure to fetch the latest 5 records
        GetAllClients().All.SendSignalData(signalData);

    }

我的 js 文件 - SignalR 连接代码

var signalHub = $.connection.signalHub; //alert("ACCC");
$.connection.hub.logging = true;
// Start the hub
$.connection.hub.start();
signalHub.client.SendSignalData = function (signalData) {
     updateSignalData(signalData);// updates the elements in Index.cshtml
}

您似乎希望在从 Web 服务插入的新数据到达您的 Azure Table 存储时向所有连接的客户端推送通知。我建议您在执行将数据插入 Azure Table 存储的代码后调用集线器方法向所有连接的客户端广播新数据。

var hub = new HubConnection("http://xxx/signalr/hubs");

var proxy = hub.CreateHubProxy("{HubName}");
hub.Start().Wait();

//invoke hub method
proxy.Invoke("{HubMethod}", "{partitionkey&rowkey}");

在你的hub方法中,你会得到最新数据的partition keyrow key,然后你可以检索基于分区键和行键的实体,并调用 JavaScript 辅助函数 SendSignalData 更新网页元素。