# menashmq

> Easy to use RabbitMQ abstraction with auto-reconnect for JavaScript and TypeScript

Latest version **0.1.6** (published 2021-08-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install menashmq
pnpm add menashmq
yarn add menashmq
bun add menashmq
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2021-08-30 |
| First published | 2020-05-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 223.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Alexander Gurevich |
| Maintainers | rand0m1ze |
| Keywords | rabbitmq, rabbit, mq, amqplib, amqp, typescript, reconnect, rpc, menash |

## Links

- npm: https://www.npmjs.com/package/menashmq
- Repository: https://github.com/Randomize163/MenashMQ
- Homepage: https://github.com/Randomize163/MenashMQ#readme
- Issues: https://github.com/Randomize163/MenashMQ/issues
- npm.io page: https://npm.io/package/menashmq

## Dependencies (4)

- [amqplib](https://npm.io/package/amqplib.md) ^0.8.0
- [p-retry](https://npm.io/package/p-retry.md) ^4.2.0
- [@types/amqplib](https://npm.io/package/@types/amqplib.md) ^0.8.2
- [@types/p-retry](https://npm.io/package/@types/p-retry.md) ^3.0.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.6 (latest) — 2021-08-30
- 0.1.5 — 2021-02-09
- 0.1.4 — 2020-11-04
- 0.1.3 — 2020-08-16
- 0.1.2 — 2020-08-09
- 0.1.1 — 2020-07-31
- 0.1.0 — 2020-07-18
- 0.0.5 — 2020-06-12
- 0.0.4 — 2020-06-11
- 0.0.3 — 2020-06-11
- 0.0.2 — 2020-06-01
- 0.0.1 — 2020-05-30

## README

# Welcome to MenashMQ!

![npm](https://img.shields.io/npm/v/menashmq?color=green)
![NPM](https://img.shields.io/npm/l/menashmq)
![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/menashmq)
![npm](https://img.shields.io/npm/dt/menashmq)

Easy to use RabbitMQ abstraction with auto-reconnect for JavaScript and TypeScript

![MenashMQ Logo](https://raw.githubusercontent.com/Randomize163/MenashMQ/master/other/menashmq-logo.png 'MenashMQ logo')

# Examples

## Initialize once - use everywhere:

**index.js**

    const { menash } = require('menashmq');

    await menash.connect('amqp://localhost');
    await menash.declareQueue('my-queue', { durable: true });

**manager.js**

    const { menash } = require('menashmq');

    await menash.send('my-queue', "I'm using MenashMQ");

## Declare your topology easily in one place:

    const { menash } = require('menashmq');

    // Simple consume function
    const consume = (msg) => {
    	console.log(msg.getContent());
    };

    await menash.declareTopology({
    	exchanges: [
    		{ name: 'first-exchange', type: 'fanout', options: { durable: false } },
    		{ name: 'second-exchange', type: 'direct' },
    		{ name: 'third-exchange', type: 'topic' },
    	],
    	queues: [
    		{ name: 'queue1', options: { durable: false } },
    		{ name: 'queue2' },
    		{ name: 'queue3' },
    		{ name: 'queue4' },
    	],
    	bindings: [
    		{ source: 'first-exchange', destination: 'queue1' },
    		{ source: 'second-exchange', destination: 'queue2' },
    		{ source: 'third-exchange', destination: 'queue3', pattern: "*.menash" },
    		{ source: 'third-exchange', destination: 'queue4', pattern: "monkey.#" },
    	],
    	consumers: [
    		{ queueName: 'queue1', onMessage: consume },
    		{ queueName: 'queue2', onMessage: consume, options: { noAck: true } },
    	]
    });

## TypeScript support

MenashMQ is written in Typescript and supports it perfectly!

**index.ts**

    import menash from 'menashmq';

    await menash.connect('amqp://localhost');
    await menash.declareQueue('menash-queue');

**produce.ts**

    import menash from 'menashmq';

    await menash.send('menash-queue', { name: 'menash', type: 'monkey' });

**consume.ts**

    import menash, { ConsumerMessage } from 'menashmq';

    await menash.queue('menash-queue').activateConsumer((msg: ConsumerMessage) => {
    	const animal = msg.getContent() as IAnimal;
    	console.log('Name:', animal.name);
    	console.log('Type:', animal.type);

    	msg.ack();
    }, { noAck: false });

## Upcoming features:

-   add support for JSON RPC over RabbitMQ

# API

## Client

**Methods:**

-   connect()

-   close()

-   bind()

-   declareQueue()

-   deleteQueue()

-   declareExchange()

-   deleteExchange()

-   declareTopology()

-   send()

-   queue()

-   exchange()

**Events:**

-   close

-   error

-   ready

## Exchange

**Methods:**

-   bind()

-   delete()

-   send()

## Queue

**Methods:**

-   activateConsumer()

-   stopConsumer()

-   bind()

-   delete()

-   prefetch()

-   send()

## ConsumerMessage

**Methods:**

-   setContent()

-   getContent()

-   getRawContent()

-   ack()

-   nack()

-   reject()

---
_Source: https://npm.io/package/menashmq · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
