0
votes

I'm using NServiceBus in a pub/sub application for event notifications on a web application. Right now, when something happens (like a note is created), a message is created and sent on the bus, and the subscriber picks it up and determines who needs to get an email or SMS notification of the event.

What I want to do is put a delay in the processing stream for some of the events. The purpose of this delay is similar to the old 7-second delay on live TV -- it gives the user that fired the event time to undo what they did.

Consider our event of CommentCreated. This event is sent when a new comment is persisted by my service layer. This comment can be marked as private or internal, and it's not uncommon for a user to create a comment then realize they should have marked it private.

I'd like to accomplish this delay without Sagas because, for one, I'm not savvy on them, for two, they seem to be a bit of an overkill for this simple of a requirement, and for three I don't want to have to deal with another database server to persist their data. The ghetto option would be to set a timer in my subscriber's handler and wait a few minutes before processing, but that just feels wrong.

Is it possible to do this within NServiceBus? I know some people will say to create a polling service, but that sort of defeats the purpose of a service bus...

1
Is there any reason you couldn't let the user see the notes on the UI and not push them back to the back end until a later time?Adam Fyles
Well, since I already have the NSB pub/sub in place, I'd like to handle it there. It would add complexity to persist notes but delay the event firing since the app is a web app (MVC, so no state). And I'm only talking about a short delay -- no more than 5 minutes.Josh Anderson
I was thinking you would persist the notes in the DOM(jQuery or otherwise) and not Bus.Send() to the server until they took some action(button, leaving the page). This would be a sandbox until they truly wanted to save.Adam Fyles
Also, depending on how you are doing your Publish, you may want to look at this: make-awesome.com/2010/10/…Adam Fyles
Yeah, I'm already using Bus.Send(), and the events come through a service layer anyway. Persisting in the DOM like that won't work, as I would like to be able to stop the event even after they leave the page.Josh Anderson

1 Answers

2
votes

There is no pretty way that I know of, besides sagas - either by using NServiceBus' own Saga<...>, or by effectively implementing the saga yourself - and using some kind of timeout mechanism, like e.g. NServiceBus' timeout service.

I agree with you that fulfilling this requirement can be simple - given that the required infrastructure is in place! If you insist on building this the ghetto way, however, I don't think satisfying the requirement is simple.

I.e. when you have NServiceBus set up with a proper timeout service and a way to persist sagas, implementing this will be simple.

But hacking this up, with timers and whatnot, will just invite all kinds of trouble over, like e.g. timers not firing when IIS recycles your web app, etc.