CQRS NServiceBus UI Feedback

I have a CQRS solution using NServiceBus with web workers in an HTML / JavaScript application.

I have a script

  • WebAPI sends command
  • CommandHandler update domain root aggregated roots
  • CommandHanlder publishes events for EventHandlers that update Read Models
  • EventHandler Read Model Updates

I want to provide feedback to the user in the UI when everything is complete (but will not block the UI).

I know I can use Bus.Return to return from my Bus.Send to the CommandHandler when I use it, showing that it has finished working. But how can I give feedback after the EventHandlers initiated by Bus.Publish have finished their work?

I can use Bus.Reply from EventHandler ... but how do I get back to the original sender? Do I need to use the saga for this? And if I do this and ReplyToOriginator, once the response has been received by the sender, how do I match the response to the correct UI / UI to notify? Should I track all requests pending notification somewhere? It seems too complicated.

+3


source to share


3 answers


It looks like the WebAPI service is interested in knowing when XXX work ends with the Domain endpoint. In this case, it makes sense to just post the event from the domain endpoint and then anyone who cares about completing this type of work can subscribe to that type of event. An event is essentially an interesting state change, so if the work being completed is an interesting state change, publishing the events makes sense.

As you noted, Bus.Reply () will also work. I prefer to use an event to avoid an explicit request / response paradigm.



An event / response was received, assuming the information facing the user / browser is a WebAPI service issue, so some form of state tracking would be required. Saga, database, or onboard memory can work, but can also be possible by passing a correlation id with the message in both directions depending on how you return the information to the user (like SignalR).

+1


source


This question has been asked on SO many times.

If you look at Udi's "The Longest Post", you will see that the general assumption that a command handler is not expected will never work. As Greg Young says, the probability of its failure is marginal, so in this case, automation is not required to handle this small number of cases where it can be easily handled by human intervention. In terms of UI updates, Udi suggests (in the same post) that the UI is updated with the data that was posted internally. It is understood that the user interface displays data on the assumption that the command has been processed correctly and the updated model has been updated. Of course, nothing prevents you from using Bus.Return or Bus.Reply, and sometimes you have to use it because you are expecting not only a status, but some actual data,which need to be returned, but this is completely different. In many cases, the user interface of high load systems works as follows. The UI is showing data as it has been updated on the server. Later in time, the UI may receive a crash event stating that an error has occurred and the data has been updated from the read model, the command must be repeated. I believe that the most pragmatic approach is to expect success rather than failure, since the system is working fine, and then create a mechanist to publish error notifications. If no error is received, the assumption must be made that everything went well.since it was updated on the server. Later in time, the UI may receive a crash event stating that an error has occurred and the data has been updated from the read model, the command must be repeated. I believe that the most pragmatic approach is to expect success rather than failure, since the system is working fine, and then create a mechanist to publish error notifications. If no error is received, the assumption must be made that everything went well.since it was updated on the server. Later in time, the UI may receive a crash event stating that an error has occurred and the data has been updated from the read model, the command must be repeated. I believe the most pragmatic approach is to expect success rather than failure, since the system is working fine, and then create a mechanist to post error notifications. If no error is received, the assumption must be made that everything went well.and then create a mechanism to publish error notifications. If no error is received, the assumption must be made that everything went well.and then create a mechanism to publish error notifications. If no error is received, the assumption must be made that everything went well.



In his book Implementing DDD, Vaughn Vernon mentions this approach, but argues that while many find it effective, others criticize it as a "hack." So, I would guess that there is still no "right way" and everything is decided according to the requirements and the speed of adoption by users.

From what Greg Young says about the service bus used to propagate events, I've come to the conclusion that ES with catch-up subscription is an easier and more reliable way of reading model updates than using pub-sub.

+1


source


I don't think updating the UI without confirming the team's success is the best approach.

For this purpose, I am using a real time framework called SignalR

where you can have real time calls between server and client.

http://www.asp.net/signalr

The command is executed CommandHandler

, after which the event is fired, and I use most of the events mainly to update the read data and the UI.

In your event handler you can call server methods from the hubs SignalR

(and for a specific answer to your question, you can go back to the original sender by getting it SignalR ConnectionId

) (googling "signalr get client connection id" can help you go back to the original sender)

0


source







All Articles