How to use the cote.Responder function in cote

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 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 / cote-workshop / services / purchase-service.js View on Github external
var cote = require('cote'),
    models = require('../models');

var purchaseResponder = new cote.Responder({
    name: 'purchase responder',
    namespace: 'purchase',
    respondsTo: ['buy']
});

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

var paymentRequester = new cote.Requester({
    name: 'payment requester',
    key: 'payment'
});
github icebob / microservices-benchmark / suites / remote.js View on Github external
(function () {
	const cote = require('cote');

	cote_resp = new cote.Responder({ name: 'bench-remote' });
	cote_req = new cote.Requester({ name: 'bench-remote' });
	
	cote_resp.on('add', (req, cb) => {
		cb(req.a + req.b);
	});	

	bench.add("Cote", done => {
		cote_req.send({ type: 'add', a: 5, b: 3 }, res => done());
	});

})();

cote

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

MIT
Latest version published 5 months ago

Package Health Score

61 / 100
Full package analysis