System used to synchronize MQTT Protobuff Messages to Couchdb.
npm install -s Telluric/protobuf-mqtt-couchdb
const pmc = require('@telluric/protobuf-mqtt-couchdb');
const PouchDB = require('pouchdb');
const mqtt = require('mqtt')
// Setup MQTT Client and Subscribe
const client = mqtt.connect(process.env.MQTT_BROKER)
const feed = process.env.MQTT_FEED;
client.on('connect', () => {
client.subscribe(feed)
})
// Load PB and Sync Mutated Messages to Couchdb
pmc({
file: process.env.PROTOBUF_FILE,
type: process.env.PROTOBUF_TYPE,
db: new PouchDB(process.env.COUCHDB_DATABASE),
client: client,
mutation: process.env.PMC_MUTATION_FILE ? require(process.env.PMC_MUTATION_FILE) : (d)=>d
}, (res)=>{
console.log(res);
})
Setting these will configure the middleware services. They are all required to run the server.js example. You can configure them in an .env file in the root of your project
ENV Variable | Example Value |
---|---|
COUCHDB_DATABASE | http://localhost:5984/messages |
MQTT_BROKER | mqtt://localhost |
MQTT_FEED | /feed/messages |
PROTOBUF_FILE | example.proto |
PROTOBUF_TYPE | example.Message |
PMC_MUTATION_FILE | mutate.js |
MIT License - See ./LICENSE