Message-based architecture

Events

WIP Notes:
Topics:

  • UI coordinated by events via the event bus
  • Decoupling application concerns using event subscribers rather than direct subscribing (use routing and template management as an example)

Commands

WIP Notes:
'Tell don't ask', Apis, Validated commands routed to Aggreates

Validate client commands using Apis

Defining an Application API is as easy as extending the Space.messaging.Api object, and adding it to the Apis array in your Application definition.

MyApi = Space.messaging.Api.extend('MyApi',{

  methods: function(){
    return [
      'MyCommand': function (context, command) {
         if(!context.userId)
           throw new Meteor.Error('Denied');
         console.log('Success');
         this.commandBus.send(command);
      }
    ]
  }
  
});
var MyApp = Space.Application.define('MyApp', {
  
  // Apis: ['MyApi']

});

Now just send a command on the CommandBus on the client (assuming user is logged in)

app.sendCommand(new MyCommand({…}));
// -> 'Success'

Distributed messaging via Mongo

It is also the messaging queue, so you can make event subscriptions in other connected services with support for multiple instances to be running. A collection observer triggers a findAndModify on the queue to mark it as received by the service, publishes the event in the current process's, then marks it as published for that service. The last step here is to allow for automatic failure handling

📘

Dependent on Event Sourcing and domain events as the integration strategy

The Commit Store is a natural message queue for Eventually Consistent systems as it's an append-only record of the complete state. This allows for integration via domain events, a core DDD principle.