--
You received this message because you are subscribed to the Google Groups "Particular Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftw...@googlegroups.com.
To post to this group, send email to particula...@googlegroups.com.
Visit this group at http://groups.google.com/group/particularsoftware.
To view this discussion on the web visit https://groups.google.com/d/msgid/particularsoftware/f6394707-24ca-49c6-b1a4-c590b96ef092%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftware+unsub...@googlegroups.com.
To post to this group, send email to particul...@googlegroups.com.
We've played around with WebAPI sending something to the bus and registering a callback. We had this working by marking the WebAPI and controller methods async and then used await to wait for the result of the callback. What I wanted to know was how to handle a timeout where for some reason the handler never sent a response.
The only thing that comes to my mind is something like (not tested at all):
public Task<HttpStatusCode> ExecuteSomething()
{
var task = this.Bus.Send( null )
.Register( r =>
{
//callback handling logic here
} );
var completed = task.Wait( 2000 );
if( !completed )
{
//timed out
return Task.FromResult( HttpStatusCode.RequestTimeout );
}
return Task.FromResult( HttpStatusCode.OK );
}
Yes I guess we are trying to make the asynchronous operation synchronous but is this not necessary sometimes for short lived UI operations ?
My guess is that the assumption “short lived” can be problematic, and really depends on so many factors that can be hard to determine that something is timing out after a set, and known upfront, amount of time.
I use to implement this timeout logic in the UI/front end that knows what is going on, handling a timeout at the UI level allows me to ask to the user what we should do next, e.g. wait some more time?, something that at the web server level cannot be done.
After all WebAPI is request/response. In a traditional scenario without a bus the whole thing would be synchronous anyway unless you got funky with SignalR.
I guess I'm struggling to see how NServiceBus should work with WebAPI, perhaps the question should be "How should I build my UI to work with WebAPI and NServiceBus ?".
I fully get that the bus should not be used for querying data and it should in most cases issue commands in a sort of fire and forget fashion. So what's the strategy for building the UI ? Do you just make an assumption that most UI commands should complete in a short time and just assume that you UI will be eventually consistent ? Or do you have to employ polling or SignalR for every type of UI operation both short and long running ?
My assumption is that each command is always backed and followed by at least one event, the front-end is subscribed to all the events and will push these events to the UI via SignalR, what you need now is a way to correlate things back, since when pushing with SignalR what happens is that you are pushing every event to every client regardless that that client is waiting for that event, so a client needs to understand if a specific event is the one it is waiting for.
Given the above assumption the client needs to be able to generate unique Correlation IDs, or Conversation IDs, that will attach to every sent request that will generate a command and expects a reply back via an event.
I've never seen a decent sample application for NServiceBus hooked up to WebAPI, certainly there needs to be better guidance in the documentation.
That is far from easy, unfortunately, we are working in order to understand which is the best way to approach it, the issue is that in order to give a real world sample that handles a lot of the issues and the details that one can face in production the result is not a sample any more :-)