Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

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)

Keywords

install

npm i uva-amqp

Downloadsweekly downloads

15

version

0.7.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability