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 saying IDisposable
, I have seen it always return a Subscription object, but why IDisposable
?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?
I would recommend to inherit from ScaleoutMessageBus (https://msdn.microsoft.com/en-us/library/microsoft.aspnet.signalr.messaging.scaleoutmessagebus(v=vs.111).aspx)
It provides an abstraction and encapsulates all subscription management, so it is possible to focus on a back plane implementation.
You can also take a look on Redis base implementation (https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Redis/RedisMessageBus.cs) just as example.
If it is interesting SignalR is open source, so you can look at ScaleoutMessageBus implementation as well (https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Core/Messaging/ScaleoutMessageBus.cs)
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With