Implementing Basic SignalR IMessageBus

I have a service application that works very similar to the SignalR backplane, so I thought it would be nice to create my own implementation of IMessageBus to talk to the backend rather than deploying my own thing. The problem is that I can not find much information about this contract. Although I look at the code (which 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);

It is easy, basically it should send a message to the server. I am not worried about this because my application is unidirectional from server to client.

  1. IDisposable Subscribe(ISubscriber subscriber, string cursor, Func<MessageResult, object, Task<bool>> callback, int maxMessages, object state);

    • return : Despite saying IDisposable , I saw that it always returns a Subscription object, but why is IDisposable ?
    • subscriber identifies the compound. This connection may subscribe or unsubscribe to groups.
    • cursor : this is the last message id received.
    • callback : when is this callback executed?
    • state : what exactly is it?

Can someone explain to me how this method works?

+7
signalr signalr-backplane
source share
1 answer

I would recommend inheriting from ScaleoutMessageBus ( https://msdn.microsoft.com/en-us/library/microsoft.aspnet.signalr.messaging.scaleoutmessagebus(v=vs.111).aspx )

It provides abstraction and encapsulates all subscription management, so you can focus on implementing the inverse plane.

You can also take a look at the basic Redis implementation ( https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Redis/RedisMessageBus.cs ) as an example.

If you're interested, SignalR is open source, so you can also take a look at the ScaleoutMessageBus implementation ( https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Core/Messaging/ScaleoutMessageBus.cs )

Hope this helps.

+1
source share

All Articles