@avro/services

1.0.1 • Public • Published

Avro services

Avro-powered RPC services.

Features

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

Examples

In-process client and server

const {Deadline, Server, Service} = 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 = stringServer.client(); // In-process client.

stringClient.emitMessage(Deadline.forMillis(100))
  .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...'); });

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.10latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.10
1.0.00
0.10.20
0.10.10
0.10.01
0.9.100
0.9.90
0.9.80
0.9.70
0.9.60
0.9.50
0.9.41
0.9.30
0.9.20
0.9.10
0.9.00
0.8.80
0.8.70
0.8.60
0.8.50
0.8.40
0.8.30
0.8.20
0.8.10
0.8.00
0.7.90
0.7.80
0.7.70
0.7.60
0.7.50
0.7.40
0.7.30
0.7.10
0.7.00
0.6.60
0.6.50
0.6.40
0.6.30
0.6.20
0.6.10
0.6.01
0.5.110
0.5.100
0.5.90
0.5.80
0.5.70
0.5.60
0.5.50
0.5.40
0.5.30
0.5.20
0.5.10
0.5.00
0.4.50
0.4.40
0.4.30
0.4.20
0.4.10
0.4.00
0.3.20
0.3.10
0.3.00
0.2.10
0.2.00
0.1.01

Package Sidebar

Install

npm i @avro/services

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

66.3 kB

Total Files

10

Last publish

Collaborators

  • mtth