Topics

Topics are a very powerful feature to control the business-logic of your realtime application. A Topic defines a handler on your server. If a client connects (subscribes) to a topic the handler will be executed. A topic can simply return data or start observing events, collections or event raw rx.Observables. It's the task of the client to disconnect (dispose) from a connected topic. If client disconnects, all connected topic subscriptions will be disposed automatically.

The following example shows a simple use case how to implement your realtime-logic:

server.topic('todos', ({ room, collection, user }) => {

  room('active-users').join();

  let query = { groups: user.groups };

  collection('tasks')
    .query(query)
    .queryChanges(query);

});

If a client subscribes to a topic he will receive:

  • all future events of the room active-users
  • all tasks of "his" groups as a direct response to his subscription-request
  • all future changes of task-items (e.g. someone concluded a task or edited the purpose of a task)

It looks like dreamcode, but it's really just that simple. All the heavy parts are abstracted by Durga.

Let's summarize: We have three types of handlers, which can be called from client:

  • Events for _fire-and-forget _cases.
  • Methods to request something from the server.
  • Topics to combine realtime-events into logical blocks.

But does it scale? Until now there is nothing stored on the server. No session, no data, no event-pools, nothing. The basic idea behind Durga is that every type of persistent data should be excluded from your realtime-server. What does it mean?

  • You have events, which should reach multiple clients? - Use an external messaging queue for that.
  • You need to store data and would like to inform connected clients about these changes? Whats about using RethinkDB?

Durga will not implement a "rooming"-pool or an event-queue for delivering events. But it will give you a neat way to use such services.

results matching ""

    No results matching ""