0.1.10 • Published 4 years ago

moleculer-amqp v0.1.10

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

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 moleculer-amqp --save

Usage

Simple queue handler with validation

const amqpMixin = require('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

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago