uva-amqp

0.7.1 • Public • Published

uva-amqp

The uva RPC interface implementation for AMQP.

Dependency Status Build Status npm version Coverage Status

Installation

npm install --save uva-amqp

Usage

Create a microservice for mathematical calculations and implement some remote methods.

const uva = require('uva-amqp')
 
uva.server({
  channel: 'mathOperations',
  amqpURL: 'amqp://guest:guest@localhost:5672',
})
.then(server => {
  server.addMethods({
    sum(a, b, cb) {
      cb(null, a + b)
    },
    factorial(n, cb) {
      let f = 1
      for (let i = 2; i <= n; i++) {
        f *= i
      }
      cb(null, f)
    },
  })
  server.start()
})

Create a client for the math microservice and call some of its remote methods.

const uva = require('uva-amqp')
 
uva.client({
  channel: 'mathOperations',
  amqpURL: 'amqp://guest:guest@localhost:5672',
})
.then(math => {
  math.sum(12, 2, function(err, sum) {
    console.log(sum)
  })
 
  /* if the last argument is not a callback, the function will return a promise */
  math.factorial(10).then(function(result) {
    console.log(result)
  }, function(err) {
    console.error(err)
  })
})

License

The MIT License (MIT)

Readme

Keywords

Package Sidebar

Install

npm i uva-amqp

Weekly Downloads

1

Version

0.7.1

License

MIT

Last publish

Collaborators

  • zkochan