0.3.10 • Published 4 years ago

rxamqp v0.3.10

Weekly downloads
10
License
MIT
Repository
github
Last release
4 years ago

Reactive AMQP Build Status rxamqp codecov

This library is aimed to ease amqplib usage.

Installation:

npm i rxamqp -S

Following features are implemented:

  • Client reconnection
  • Failed channel reopening
  • Express like middleware pipelines for subscriptions
  • Promise based querying interface

Usage example

const createClient = require('rxamqp')

const client = createClient()

// prepare reply queues beforehand to save request time later
client.assertReplyQueue('foo.bar')
client.assertReplyQueue('foo.bar.error.sync')
client.assertReplyQueue('foo.bar.error.async')

client
  // middlewares bound to specific routing keys and exchange
  .use(
    { exchange: 'amq.topic', routingKey: 'foo.bar' }, (msg, ctx, next) => {
      ctx.value = 1
      return next()
    }, (msg, ctx, next) => {
      ctx.value++
      return next()
    }
  )
  .use(
    { exchange: 'amq.topic', routingKey: 'foo.bar.error.sync' }, (msg, ctx, next) => {
      ctx.value = 1
      throw new Error('Some sync Error')
      return next()
    }, (msg, ctx, next) => {
      ctx.value++
      return next()
    }
  )
  .use(
    { exchange: 'amq.topic', routingKey: 'foo.bar.error.async' }, (msg, ctx, next) => {
      ctx.value = 1
      setTimeout(() => {
        next(new Error('Some async Error'))
      }, 0)
    }, (msg, ctx, next) => {
      ctx.value++
      return next()
    }
  )
  // global middleware
  .use((msg, ctx, next) => {
    return ctx.respond({ foo: `${msg.bar} - ${ctx.value}`  })
  })
  // global error handler
  .use((error, msg, ctx, next) => {
    ctx.rejectAndRespond({ foo: `${msg.bar} - ${ctx.value}`, error: error.message })
    next()
  })

client.listen()

client.request('amq.topic', 'foo.bar', { bar: 'bar' })
  .then(result => console.log(result))
/*
  {
    "data": {
      "foo": "bar - 2"
    }
  }
*/
client.request('amq.topic', 'foo.bar.error.sync', { bar: 'bar' })
  .catch(result => console.log(result))
/*
{
  "data": {
    "foo": "bar - 1",
    "error": "Some sync Error"
  }
}
*/
client.request('amq.topic', 'foo.bar.error.async', { bar: 'bar' })
  .catch(result => console.log(result))
/*
{
  "data": {
    "foo": "bar - 1",
    "error": "Some async Error"
  }
}
*/

Roadmap

  • Add primary global middlwares that are executed before all subscribers' local ones
  • Improve documentation
0.3.8

4 years ago

0.3.7

4 years ago

0.3.9

4 years ago

0.3.10

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.0.22-queue

5 years ago

0.0.21-queue

5 years ago

0.0.20-queue

5 years ago

0.1.7

6 years ago

0.0.21

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.1

6 years ago