uva-amqp

AMQP RPC driver for Node.js using the uva interface.

Usage no npm install needed!

<script type="module">
  import uvaAmqp from 'https://cdn.skypack.dev/uva-amqp';
</script>

README

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)