octoblu / meshblu

Meshblu is a cross-protocol IoT machine-to-machine messaging system.
https://meshblu.readme.io/
MIT License
815 stars 182 forks source link

About unifying APIs for all protocols #130

Closed anhldbk closed 8 years ago

anhldbk commented 8 years ago

Currently, Meshblu supports various protocols including HTTP, Websocket, MQTT, CoAP... To work with individual protocols, we must use different APIs.

So is it reasonable to unify them into one? For example, here is what I think about the unified APIs:

var meshblu = require('meshblu');

var endpoint = meshblu.createConnection({
  "uuid": "xxxxxxxxxxxx-My-UUID-xxxxxxxxxxxxxx",
  "token": "xxxxxxx-My-Token-xxxxxxxxx",
  "protocol": "mqtt", // protocol to work with
  "mqtt": { // configuration for the protocol
      "qos": 0, // MQTT Quality of Service (0=no confirmation, 1=confirmation, 2=N/A)
      "host": "localhost", // optional - defaults to meshblu.octoblu.com
      "port": 1883  // optional - defaults to 1883
  }
});

// register for event handlers
endpoint.on('<a message>', function(data){
});

// to send data or messages
endpoint.send('data', data, function(err, result){
});
endpoint.send('message', message, function(err, result){
});
endpoint.send('subscription', uuid, function(err, result){
});
iamruinous commented 8 years ago

In Meshblu 2.0 we have a standard set of jobs across all protocols. To preserve backwards compatibility we support the legacy meshblu API, however we will start exposing the "Job Manager" style APIs to all protocols. We should continue to try and support the native paradigms of each protocol, however the client libraries should have some consistency between them. If you look at the XMPP and AMQP protocol adapters, you can see some examples.

https://github.com/octoblu/meshblu-core-protocol-adapter-xmpp https://github.com/octoblu/meshblu/wiki/Job

anhldbk commented 8 years ago

@iamruinous Thank you!