# newsource-rabbitmq-module

> Newsource module for consuming and publishing rabbitmq messages

Latest version **1.2.0** (published 2024-07-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install newsource-rabbitmq-module
pnpm add newsource-rabbitmq-module
yarn add newsource-rabbitmq-module
bun add newsource-rabbitmq-module
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2024-07-17 |
| First published | 2024-04-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10.0.0 |
| Dependencies | 1 |
| Unpacked size | 68.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | mss-npm-user |
| Keywords | newsource, rabbit, rabbitmq, ampqlib |

## Links

- npm: https://www.npmjs.com/package/newsource-rabbitmq-module
- Repository: https://github.com/turnercode/newsource-rabbitmq-module
- Homepage: https://github.com/turnercode/newsource-rabbitmq-module#readme
- Issues: https://github.com/turnercode/newsource-rabbitmq-module/issues
- npm.io page: https://npm.io/package/newsource-rabbitmq-module

## Dependencies (1)

- [amqp-connection-manager](https://npm.io/package/amqp-connection-manager.md) ^4.1.14

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2024-07-17
- 1.1.1 — 2024-06-03
- 1.1.0 — 2024-06-03
- 1.0.2 — 2024-05-01
- 1.0.1 — 2024-04-30
- 1.0.0 — 2024-04-29

## README

# newsource-rabbitmq-module

## Base Requirements

- newsource-winston-splunk-logger-instance
- rabbitmq configuration

```bash
# Requires Node >= 10
# Requires newsource-winston-splunk-logger >= 3.x
npm install "newsource-rabbitmq-module"
```

## Code Examples

### Instantiation and Cleanup

```typescript
// Supports named and default exports

import { nsRabbit } from "newsource-rabbitmq-module";
// import default from "newsource-rabbitmq-module"

// Must always start the module before calling any other methods
nsRabbit.start({
  config: {
    hostname: "example.cloudamqp.com",
    password: "password1234",
    port: 1234,
    username: "example_user",
    vhost: "example",
  },

  // newsource-winston-splunk-logger instance
  logger,

  // Optional array of queues to subscribe to on start
  queues: [
    {
      name: "example-env.queue",
      limit: 20,
    },
  ],
});

// Closes all connections and resets all configuration
await nsRabbit.stop();
```

### Publish Messages

```typescript
await nsRabbit.publishMessage({
  exchange: "example.task",
  routingKey: "example.routing.key",
  content: {
    // some object
  },
});
```

### Register Routing Key and Queue Handlers

```typescript
nsRabbit.handleRoutingKey<ExpectedMessage>(
  "example.routing.key",
  (msg: Message<ExpectedMessage>) => {
    /*
        Logic to run when message with routing key received

        msg.body will contain parsed JSON of msg.content

        Must ack / nack message
        * msg.ack();
        * msg.nack();
    */
  },
);

nsRabbit.consumeQueue({
  name: "example-env.queue",
  limit: 20, // optional and defaults to 10
});
```

### Unregister Handlers

```typescript
nsRabbit.stopHandlingRoutingKey("example.routing.key");

nsRabbit.stopConsumingQueue("example-env.queue");
```

### Setup Multiple Server Connections

```typescript
// Import static class instead of singleton to support setting up multiple connections
import { RabbitMQManager } from "newsource-rabbitmq-module";

const nsRabbit1 = new RabbitMQManager(config1);
const nsRabbit2 = new RabbitMQManager(config2);
```

## TODO

- Setup tests with jest
- Auto publish to npm on release?

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