How to use cote - 10 common examples

To help you get started, we’ve selected a few cote examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kalisio / feathers-distributed / src / service.js View on Github external
}

  async remove (id, params) {
    debug('Requesting remove() remote service on path ' + this.path, id, params)
    try {
      const result = await this.requester.send({ type: 'remove', id, params })
      debug('Successfully remove() remote service on path ' + this.path)
      return result
    } catch (error) {
      throw convert(error)
    }
  }
}

// This is the cote responder abstraction for a local Feathers service
class LocalService extends cote.Responder {
  constructor (options) {
    const app = options.app
    const path = options.path
    super({
      name: path + ' responder',
      namespace: path,
      key: path,
      respondsTo: ['find', 'get', 'create', 'update', 'patch', 'remove']
    }, app.coteOptions)
    debug('Responder created for local service on path ' + path)
    const service = app.service(path)

    // Answer requests from other nodes
    this.on('find', async (req) => {
      debug('Responding find() local service on path ' + path, req)
      const result = await service.find(Object.assign({ fromRemote: true }, req.params))
github kalisio / feathers-distributed / src / index.js View on Github external
function initializeCote (app) {
  debug('Initializing cote with options', app.coteOptions)
  // Setup cote with options
  app.cote = makeCote(app.coteOptions)

  // This subscriber listen to an event each time a remote app service has been registered
  app.serviceSubscriber = new app.cote.Subscriber({
    name: 'feathers services subscriber',
    namespace: 'services',
    key: 'services',
    subscribesTo: ['application', 'service']
  }, app.coteOptions)
  debug('Services subscriber ready for app with uuid ' + app.uuid)
  // When a remote service is declared create the local proxy interface to it
  app.serviceSubscriber.on('service', serviceDescriptor => {
    registerService(app, serviceDescriptor)
  })
  // This publisher publishes an event each time a local app or service is registered
  app.servicePublisher = new app.cote.Publisher({
    name: 'feathers services publisher',
github dashersw / cote-workshop / services / user-service.js View on Github external
var cote = require('cote'),
    models = require('../models');

var userResponder = new cote.Responder({
    name: 'user responder',
    namespace: 'user',
    respondsTo: ['create']
});

var userPublisher = new cote.Publisher({
    name: 'user publisher',
    namespace: 'user',
    broadcasts: ['update']
});

userResponder.on('*', console.log);

userResponder.on('create', function(req, cb) {
    models.User.create({}, cb);
github dashersw / microservices-workshop / restaurants-service / index.js View on Github external
const cote = require('cote')

const restaurantsResponder = new cote.Responder({ name: 'restaurants responder', key: 'restaurants' })
restaurantsResponder.on('*', req => req.type && console.log(req))

const restaurants = [{
    id: 0,
    name: 'Italian Restaurant',
    menu: [{
        id: 0,
        name: 'Pizza',
        price: 14
    }, {
        id: 1,
        name: 'Pasta',
        price: 12
    }]
}, {
    id: 1,
github dashersw / microservices-workshop / delivery-service / index.js View on Github external
const cote = require('cote')

const deliveryResponder = new cote.Responder({ name: 'delivery responder', key: 'deliveries' })
deliveryResponder.on('*', req => req.type && console.log(req))

const deliveries = []
let idCounter = 0

deliveryResponder.on('create delivery', req => {
    const delivery = { id: idCounter++, orderId: req.order.id, eta: 30, status: 'pending' }

    deliveries.push(delivery)
    return Promise.resolve(delivery)
})
github dashersw / dockercloud-microservices / time-service / index.js View on Github external
var cote = require('cote');

var hostname = require('os').hostname();
var source = `time-service@${hostname}`;

var timeResponder = new cote.Responder({
    name: 'Time Responder'
});

timeResponder.on('time', function(req, cb) {
    var time = new Date();
    var reply = {source, time, rand: Math.random()};

    console.log(reply);
    cb(reply);
});
github dashersw / cote-workshop / services / payment-service.js View on Github external
var cote = require('cote'),
    models = require('../models');

var paymentResponder = new cote.Responder({
    name: 'payment responder',
    key: 'payment'
});

paymentResponder.on('*', console.log);

paymentResponder.on('process', function(req, cb) {
    models.User.get(req.userId, function(err, user) {
        if (user.balance < req.price) return cb(true);

        user.balance -= req.price;

        user.save(cb);
    });
});
github dashersw / microservices-workshop / order-service / index.js View on Github external
const cote = require('cote')

const orderResponder = new cote.Responder({ name: 'order responder', key: 'orders' })
orderResponder.on('*', req => req.type && console.log(req))

const orders = []
let idCounter = 0

orderResponder.on('create order', req => {
    const order = { id: idCounter++, ...req.order, status: 'preparing' }

    orders.push(order)
    return Promise.resolve(order)
})
github dashersw / cote-workshop / services / product-service.js View on Github external
var cote = require('cote'),
    models = require('../models');

var productResponder = new cote.Responder({
    name: 'product responder',
    namespace: 'product',
    respondsTo: ['list']
});

var productPublisher = new cote.Publisher({
    name: 'product publisher',
    namespace: 'product',
    broadcasts: ['update']
});

productResponder.on('*', console.log);

productResponder.on('list', function(req, cb) {
    var query = req.query || {};
    models.Product.find(query, cb);
github dashersw / microservices-workshop / api-gateway / index.js View on Github external
const express = require('express')
const bodyParser = require('body-parser')
const cote = require('cote')
const axios = require('axios')

const app = express()

app.use(bodyParser.json())

const restaurantsRequester = new cote.Requester({ name: 'restaurants requester', key: 'restaurants' })

const orderRequester = new cote.Requester({ name: 'order requester', key: 'orders' })

const deliveryRequester = new cote.Requester({ name: 'delivery requester', key: 'deliveries' })

app.get('/restaurants', async (req, res) => {
    const restaurants = await restaurantsRequester.send({ type: 'list' })
    res.send(restaurants);
})

app.post('/order', async (req, res) => {
    const order = await orderRequester.send({ type: 'create order', order: req.body })
    const delivery = await deliveryRequester.send({ type: 'create delivery', order })

    res.send({ order, delivery })
})

app.listen(3000, () => console.log('listening'))

cote

A Node.js library for building zero-configuration microservices.

MIT
Latest version published 1 month ago

Package Health Score

73 / 100
Full package analysis