@viametamap/moleculer-amqp

1.0.2 • Public • Published

@viametamap/moleculer-amqp NPM version

Task queue mixin for AMQP

Description

In order to divide RabbitMQ working queues and transport queues, this mixin was created. Also, it can be used with any moleculer transport you want.

Installation

$ npm install @viametamap/moleculer-amqp --save

Usage

Simple queue handler with validation

const amqpMixin = require('@viametamap/moleculer-amqp');

broker.createService({
  name: 'greeting',
  mixins: [amqpMixin('amqp://localhost')],
  actions: {
    sendGreeting: {
      params: {
        text: { type: 'string', min: 2 },
      },
      handler(ctx) {
        const { params: text } = ctx;
        return this.sendToQueue('greetings', text, { persistent: true });
      },
    },
  },
  queues: {
    // Assign to greeting queue
    greetings: {
      // Params validation with moleculer validator
      params: {
        text: { type: 'string' },
      },
      // Error strategy defines how to nack message on error
      errorStrategy: {
        requeue: false,
      },
      // Handler will receive decoded message on consume
      handler({ text }) {
        console.log('Hello from amqp with new message:', text);
      },
    },
  },
});

Test

$ npm test

In development with watching

$ npm run ci

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Package Sidebar

Install

npm i @viametamap/moleculer-amqp

Weekly Downloads

197

Version

1.0.2

License

MIT

Unpacked Size

34.6 kB

Total Files

9

Last publish

Collaborators

  • xrashad