{"_id":"5639e5bad25e8919005f3e6a","project":"56000f0d8c0c9d0d00dcad21","githubsync":"","user":"5600910981a9670d006d144f","__v":11,"version":{"_id":"56000f0e8c0c9d0d00dcad24","project":"56000f0d8c0c9d0d00dcad21","__v":13,"createdAt":"2015-09-21T14:07:10.176Z","releaseDate":"2015-09-21T14:07:10.176Z","categories":["56000f0e8c0c9d0d00dcad25","56008f2497f69f1700f21a36","560091601503430d007cc936","560e0d8054af2b0d005bbe92","560e3ce7ad6b200d00ff471c","560e3cf2c4e4ae0d00b42ed1","561c81d0e822e12b00e1fe00","561c81e9e822e12b00e1fe01","561c823d20b4a92b007d5147","56257f8951bf1c0d001f660a","562d5f165bd25e0d0054dbd4","562d68d5d38b650d0044472a","56421aebb0dc090d00f88438"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"562d68d5d38b650d0044472a","project":"56000f0d8c0c9d0d00dcad21","__v":5,"version":"56000f0e8c0c9d0d00dcad24","pages":["562d904026a0a10d00ad6c30","56398e44a19edf0d009721a7","5639e5bad25e8919005f3e6a","563a30e3a19edf0d009722e6","563bf349d8f2d20d00448b39"],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-10-25T23:42:13.718Z","from_sync":false,"order":1,"slug":"getting-started","title":"Getting Started"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-11-04T11:02:18.264Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Events\"\n}\n[/block]\nWIP Notes: \nTopics:\n- UI coordinated by events via the event bus\n- Decoupling application concerns using event subscribers rather than direct subscribing (use routing and template management as an example)\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Commands\"\n}\n[/block]\nWIP Notes:\n'Tell don't ask', Apis, Validated commands routed to Aggreates\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Validate client commands using Apis\"\n}\n[/block]\nDefining an Application API is as easy as extending the Space.messaging.Api object, and adding it to the `Apis` array in your Application definition.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"MyApi = Space.messaging.Api.extend('MyApi',{\\n\\n  methods: function(){\\n    return [\\n      'MyCommand': function (context, command) {\\n         if(!context.userId)\\n           throw new Meteor.Error('Denied');\\n         console.log('Success');\\n         this.commandBus.send(command);\\n      }\\n    ]\\n  }\\n  \\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var MyApp = Space.Application.define('MyApp', {\\n  \\n  // Apis: ['MyApi']\\n\\n});  \",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nNow just send a command on the CommandBus on the client (assuming user is logged in)\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"app.sendCommand(new MyCommand({…}));\\n// -> 'Success'\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Distributed messaging via Mongo\"\n}\n[/block]\nIt 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\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Dependent on Event Sourcing and domain events as the integration strategy\",\n  \"body\": \"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.\"\n}\n[/block]","excerpt":"","slug":"message-based-architecture","type":"basic","title":"Message-based architecture"}

Message-based architecture


[block:api-header] { "type": "basic", "title": "Events" } [/block] 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) [block:api-header] { "type": "basic", "title": "Commands" } [/block] WIP Notes: 'Tell don't ask', Apis, Validated commands routed to Aggreates [block:api-header] { "type": "basic", "title": "Validate client commands using Apis" } [/block] 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. [block:code] { "codes": [ { "code": "MyApi = Space.messaging.Api.extend('MyApi',{\n\n methods: function(){\n return [\n 'MyCommand': function (context, command) {\n if(!context.userId)\n throw new Meteor.Error('Denied');\n console.log('Success');\n this.commandBus.send(command);\n }\n ]\n }\n \n});", "language": "javascript" } ] } [/block] [block:code] { "codes": [ { "code": "var MyApp = Space.Application.define('MyApp', {\n \n // Apis: ['MyApi']\n\n}); ", "language": "javascript" } ] } [/block] Now just send a command on the CommandBus on the client (assuming user is logged in) [block:code] { "codes": [ { "code": "app.sendCommand(new MyCommand({…}));\n// -> 'Success'", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Distributed messaging via Mongo" } [/block] 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 [block:callout] { "type": "info", "title": "Dependent on Event Sourcing and domain events as the integration strategy", "body": "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." } [/block]