title: Implementing backplane and message bus for SignalR
body: <p>My team is running an environment with load balanced IIS web servers and MongoDB. We want to use SignalR to push notifications to our users (and possibly more in the future). I'm trying to implement a new SignalR ScaleoutMessageBus so that we can use our existing MongoDB as a backplane for SignalR. I found an implementation on GitHub that looks like it is the type of thing I want. Unfortunately, it was implemented for SignalR 0.5.3 and is quite incompatible with SignalR 2.0.2.</p>
  
  <p>I'm trying to update it to get it working and have the following parts working:</p>
  
  <ul>
  <li>Dependency injection properly loads the new message bus</li>
  <li>Correctly connect to the database and follow the trailing cursor for new messages (not SignalR related)</li>
  <li>Topics and subscriptions appear to work using existing functionality</li>
  </ul>
  
  <p>I am having trouble understanding how some parts of the ScaleOutMessageBus work, particularly the function of message streams and how they relate to the overall functionality. Looking at the SQL backplane, it looks like I want to replace reading and writing to and from the streams with reading and writing to and from my database? Is that correct?</p>
  
  <p>Here is my Send implementation (which seems to be working)</p>
  
  <pre><code>protected override Task Send(IList&lt;Message&gt; messages)
  {
      MongoMessageWrapper mw = new MongoMessageWrapper(messages);
  
      if (ConnectionReady)
      {
          return Task.Factory.StartNew(() =&gt; _mongoCollection.Insert(mw)).Catch();
      }
      return OpenConnection().Then(() =&gt; Task.Factory.StartNew(() =&gt; _mongoCollection.Insert(mw)));
  }
  </code></pre>
  
  <p>My MongoMessageWrapperClass extends ScaleoutMessage but ads an _id property that the trailing cursor references.</p>
  
  <p>This appears to be correctly writing the messages to the database. I think that my next step is to create a new OnReceived that is called when my trailing cursor finds a new message and unwraps the data from Mongo to get the original message(s) and pass them on to the existing ScaleoutMessageBus base class. </p>
  
  <p>If I do this, what should I pass in as the streamIndex and id values for OnReceived? Also the messages that I am receiving in my Send function are of type Message rather than ScaleoutMessage that OnReceived takes as a parameter. Should I just convert the IList to a ScaleoutMessage?</p>
  
  <p>I haven't been able to find any documentation on building custom scaleout solutions and backplanes. Is there any available (other than wading through the source code to figure it out?</p>