feathers-rabbit-queue

1.5.0 • Public • Published

feathers-rabbit-queue

A Feathers amqp service adapter for Rabbit Queue.

$ npm install --save feathers-rabbit-queue

API

configure(options)

Configure RabbitMQ with Feathers application as new provider.

Options:

  • uri (required) - Connection uri to RabbitMQ
  • prefetch (optional, default: 1) - Prefetch from queue
  • prefix (optional) - Prefix all queues with an application name
  • socketOptions (optional, default: {}) - Socket Options will be passed as a second param to amqp.connect and from there to the socket library (net or tls)
  • queue (optional, default: {retries: 3, retryDelay: 1000, logEnabled: true}) - Queue options
  • reconnectDelay (optional, default: 1000) - Delay before next reconnect attempt
  • logger (optional, default: console) - Output logger

Example

Here's a example of configuration.

const compress = require('compression');
const helmet = require('helmet');
const cors = require('cors');
 
const feathers = require('@feathersjs/feathers');
const configuration = require('@feathersjs/configuration');
const express = require('@feathersjs/express');
const rabbitConfigure = require('feathers-rabbit-queue').configure;
 
const app = express(feathers());
 
// Load app configuration
app.configure(configuration());
// Enable security, CORS, compression, favicon and body parsing
app.use(helmet());
app.use(cors());
app.use(compress());
app.use(express.json());
app.use(express.urlencoded({extended: true}));
 
// Set up Plugins and providers
app.configure(express.rest());
app.configure(
  rabbitConfigure({
    uri: 'amqp://user:pass@host:5672',
    queueName: 'custom-queue-name',
    logger: console
  })
);
 
// Configure a middleware for 404s and the error handler
app.use(express.notFound());
app.use(express.errorHandler({logger}));

Send custom message through RabbitMQ.

Create

async function customFunctionWithAppReference(app) {
  try {
    const result = await app.rabbit.createMessage({path: 'path/to/somewhere', method: 'create', body: {}});
    console.log('Got result:', result);
  } catch (error) {
    console.log('Got error:', error);
  }
}

Patch

async function customFunctionWithAppReference(app) {
  try {
    const result = await app.rabbit.createMessage({
      path: 'path/to/somewhere/id-to-patch',
      method: 'patch',
      body: 'id-to-patch',
      data: {
        attribute: 'value'
      }
    });
    console.log('Got result:', result);
  } catch (error) {
    console.log('Got error:', error);
  }
}

Remove

async function customFunctionWithAppReference(app) {
  try {
    const result = await app.rabbit.createMessage({
      path: 'path/to/somewhere/id-to-remove',
      method: 'remove',
      body: 'id-to-remove',
      query: {
        attribute: 'value'
      }
    });
    console.log('Got result:', result);
  } catch (error) {
    console.log('Got error:', error);
  }
}

Message can be send to another Queue.

async function customFunctionWithAppReference(app) {
  try {
    const result = await app.rabbit.createMessage({queueName: 'another-custom-queue', path: 'example/id-of-this-example', method: 'update', body: {}});
    console.log('Got result:', result);
  } catch (error) {
    console.log('Got error:', error);
  }
}

License

MIT

Authors

Package Sidebar

Install

npm i feathers-rabbit-queue

Weekly Downloads

0

Version

1.5.0

License

MIT

Unpacked Size

12.6 kB

Total Files

5

Last publish

Collaborators

  • dusandrabik
  • w0k3
  • dusan.matejka
  • vittore