npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

@avro/services

0.9.10 • Public • Published

Avro services

Avro-powered RPC services.

Features

  • Schema evolution
  • "Type safe" APIs
  • Efficient wire encoding

Examples

In-process client and server

const {Client, Server, Service, Trace} = require('@avro/services');
 
const stringService = new Service({
  protocol: 'StringService',
  messages: {
    upperCase: {
      request: [{name: 'message', type: 'string'}],
      response: 'string',
    },
  },
});
 
const stringServer = new Server(stringService)
  .onMessage().upperCase((str, cb) => { cb(null, str.toUpperCase()); });
 
const stringClient = stringService.client(); // In-process client.
 
stringClient.emitMessage(new Trace()).upperCase('hello!', (err, str) => {
  if (err) {
    throw err;
  }
  console.log(str); // HELLO!
});

TCP server hosting two services

const {NettyGateway, RoutingChannel, Server, Service} = require('@avro/services');
const net = require('net');
 
const echoService = new Service({
  protocol: 'Echo',
  messages: {
    echo: {
      request: [{name: 'message', type: 'string'}],
      response: 'string',
    },
  },
});
 
const upperService = new Service({
  protocol: 'Upper',
  messages: {
    upper: {
      request: [{name: 'message', type: 'string'}],
      response: 'string',
    },
  },
});
 
const echoServer = new Server(echoService)
  .onMessage().echo((str, cb) => { cb(null, str); });
 
const upperServer = new Server(upperService)
  .onMessage().upper((str, cb) => { cb(null, str.toUpperCase()); });
 
const channel = RoutingChannel.forServers([echoServer, upperServer]);
const gateway = new NettyGateway(channel);
 
net.createServer()
  .on('connection', (conn) => {
    gateway.accept(conn.on('error', (err) => { console.error(err); }));
  })
  .listen(8080, () => { console.log('Listening...'); });

Keywords

none

install

npm i @avro/services

Downloadsweekly downloads

300

version

0.9.10

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability