简体   繁体   English

将SignalR与CQRS和事件来源配合使用

[英]Using SignalR with CQRS and Event Sourcing

I am using CQRS with EventSourcing. 我正在将CQRS与EventSourcing一起使用。 I have to use SignalR for updating grid when particular event raised in all opened browsers. 在所有打开的浏览器中引发特定事件时,我必须使用SignalR更新网格。 So, I have to push data to all clients once Particular event raised. 因此,一旦发生特殊事件,我就必须将数据推送给所有客户端。

Currently when user manually refresh page the query is fired which is pulling the data, but I have to pull data without manual refresh using SignalR. 当前,当用户手动刷新页面时,将触发查询以提取数据,但是我必须使用SignalR来提取数据而无需手动刷新。 I am new to SignalR, Can I get any sample code/reference for implementing the same? 我是SignalR的新手,我可以获取实现该示例的示例代码/参考吗?

You could read this article about this topic. 您可以阅读有关此主题的本文

There is also a public repository with some "basic experimentations" with CQRS+ES and SignalR. 还有一个公共存储库 ,其中包含对CQRS + ES和SignalR的一些“基本实验”。

Hope this helps 希望这可以帮助

First, you must create a Hub class so clients can connect to. 首先,必须创建一个Hub类,以便客户端可以连接。

Then, in your event handler you do: 然后,在事件处理程序中执行以下操作:

var hubContext = GlobalHost.ConnectionManager.GetHubContext<YourHub>(); hubContext.Clients.All.callJavaScriptFunction(parameters);

This way, when the event handler gets executed, SignalR will call the client methods you want with the data you provide. 这样,执行事件处理程序时,SignalR将使用您提供的数据调用所需的客户端方法。

You must also create the proper connection from the client and define callJavaScriptFunction . 您还必须从客户端创建正确的连接并定义callJavaScriptFunction

Note: If you are using dependency injection, you might see very unstable behavior from GlobalHost . 注意:如果使用依赖项注入,则可能会从GlobalHost看到非常不稳定的行为。 Let me know if it is the case. 让我知道是否是这种情况。

Hope this helps! 希望这可以帮助!

Best of luck! 祝你好运!

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

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