I have a service application that works pretty much like a SignalR backplane, so I thought it would be good idea to create my own IMessageBus
implementation to talk with the backend, rather than roll out my own thing. The problem is that I cannot find much information about this contract. Although I have been taking a look at the code (that looks very good), I'm struggling to understand some concepts.
public interface IMessageBus
{
Task Publish(Message message);
IDisposable Subscribe(ISubscriber subscriber, string cursor, Func<MessageResult, object, Task<bool>> callback, int maxMessages, object state);
}
Task Publish(Message message);
This one is easy, basically it must send a message to the backend. I am not worried about this one, because my app is unidirectional from server to client.
IDisposable Subscribe(ISubscriber subscriber, string cursor, Func<MessageResult, object, Task<bool>> callback, int maxMessages, object state);
return
: Despite of sayingIDisposable
, I have seen it always return a Subscription object, but whyIDisposable
?subscriber
identifies a connection. That connection can subscribe or unsubscribe to groups.cursor
: is the last received message id.callback
: when is this callback executed?state
: what is this exactly?
Can somebody explain me how this method work?