{"_id":"570828a0447c410e00221b17","project":"5564f26a1fd04c0d00dc9aaa","user":"5564f227f0f70f0d00a9ab20","parentDoc":null,"category":{"_id":"56731b714b2a680d00524daf","project":"5564f26a1fd04c0d00dc9aaa","version":"5564f26a1fd04c0d00dc9aad","__v":1,"pages":["56731edc58c4890d00bb5439"],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-17T20:30:41.290Z","from_sync":false,"order":3,"slug":"subscriptions","title":"Subscriptions"},"__v":7,"version":{"_id":"5564f26a1fd04c0d00dc9aad","project":"5564f26a1fd04c0d00dc9aaa","__v":15,"createdAt":"2015-05-26T22:23:38.671Z","releaseDate":"2015-05-26T22:23:38.671Z","categories":["5564f26b1fd04c0d00dc9aae","556741d17acd550d0075eaca","556741d87acd550d0075eacb","556742f87acd550d0075ead1","556781cd6976ef0d0099c545","5568d666d33aad0d00ec8d2e","557f6b2d38249b0d00d0d12b","55b67be9c2e909190073ed38","564e56c601e80e0d00396684","56731b714b2a680d00524daf","573612ac652bd80e00a90027","57365e2cf8ebd31700769f50","57366131f8ebd31700769f58","573b93514e029d19000b8669","573bbfdb7ac6f6170033bd35"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-04-08T21:54:40.834Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"A device can subscribe to the messages from another device. This allows for messages to be forwarded from one device to another.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Security Configuration\",\n  \"body\": \"The device must have the appropriate whitelists configured in order to allow message forwarding.\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Subscriptions\",\n  \"body\": \"The device must have the appropriate subscriptions configured in order to allow message forwarding. For example, if you want a webhook to fire on message received, you will create a `message.recevied` subscription to yourself.\"\n}\n[/block]\n## Version 2.0 Subscription Types:\n * `broadcast.received`: subscribe to broadcast messages received from other devices\n * `broadcast.sent`: subscribe to broadcast messages sent from the current device\n * `configure.received`: subscribe to `config` messages received from other devices\n * `configure.sent`: subscribe to configure messages sent from the current device\n * `message.received`: subscribe to messages received from other devices \n * `message.sent`: subscribe to messages sent by the current device\n * `unregister.received`: subscribe to unregister events received from other devices \n * `unregister.sent`: subscribe to unregister events sent by the current device\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"uuid\\\": \\\"device-b\\\",\\n  \\\"meshblu\\\": {\\n    \\\"version\\\": \\\"2.0.0\\\",\\n    \\\"whitelists\\\": {\\n      \\\"message\\\": {\\n        \\\"received\\\": [\\n          {\\n            \\\"uuid\\\": \\\"device-a\\\"\\n          }\\n        ]\\n      }\\n    }\\n  }\\n}\",\n      \"language\": \"json\",\n      \"name\": \"Device B\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"emitterUuid\\\": \\\"device-b\\\",\\n  \\\"subscriberUuid\\\": \\\"device-a\\\",\\n  \\\"type\\\": \\\"message.received\\\"\\n}\",\n      \"language\": \"json\",\n      \"name\": \"Subscription\"\n    }\n  ]\n}\n[/block]\nWhen `Device A` subscribes to `Device B` received messages, the message will be automatically forwarded and emitted from `Device A`.\n\nUse the [Subscription API](https://meshblu-http.readme.io/docs/subscriptions) to manage your subscriptions.\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Circular Subscriptions\",\n  \"body\": \"Meshblu will detect circular subscriptions to prevent infinite loops by checking the `route` property for repeated subscriptions.\"\n}\n[/block]","excerpt":"Server-Side Subscriptions","slug":"subscriptions-2-0","type":"basic","title":"Subscriptions 2.0"}

Subscriptions 2.0

Server-Side Subscriptions

A device can subscribe to the messages from another device. This allows for messages to be forwarded from one device to another. [block:callout] { "type": "warning", "title": "Security Configuration", "body": "The device must have the appropriate whitelists configured in order to allow message forwarding." } [/block] [block:callout] { "type": "warning", "title": "Subscriptions", "body": "The device must have the appropriate subscriptions configured in order to allow message forwarding. For example, if you want a webhook to fire on message received, you will create a `message.recevied` subscription to yourself." } [/block] ## Version 2.0 Subscription Types: * `broadcast.received`: subscribe to broadcast messages received from other devices * `broadcast.sent`: subscribe to broadcast messages sent from the current device * `configure.received`: subscribe to `config` messages received from other devices * `configure.sent`: subscribe to configure messages sent from the current device * `message.received`: subscribe to messages received from other devices * `message.sent`: subscribe to messages sent by the current device * `unregister.received`: subscribe to unregister events received from other devices * `unregister.sent`: subscribe to unregister events sent by the current device [block:code] { "codes": [ { "code": "{\n \"uuid\": \"device-b\",\n \"meshblu\": {\n \"version\": \"2.0.0\",\n \"whitelists\": {\n \"message\": {\n \"received\": [\n {\n \"uuid\": \"device-a\"\n }\n ]\n }\n }\n }\n}", "language": "json", "name": "Device B" } ] } [/block] [block:code] { "codes": [ { "code": "{\n \"emitterUuid\": \"device-b\",\n \"subscriberUuid\": \"device-a\",\n \"type\": \"message.received\"\n}", "language": "json", "name": "Subscription" } ] } [/block] When `Device A` subscribes to `Device B` received messages, the message will be automatically forwarded and emitted from `Device A`. Use the [Subscription API](https://meshblu-http.readme.io/docs/subscriptions) to manage your subscriptions. [block:callout] { "type": "success", "title": "Circular Subscriptions", "body": "Meshblu will detect circular subscriptions to prevent infinite loops by checking the `route` property for repeated subscriptions." } [/block]