# amqp-producer

> AMQP Producer wrapper for emails

Latest version **1.0.5** (published 2018-11-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install amqp-producer
pnpm add amqp-producer
yarn add amqp-producer
bun add amqp-producer
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2018-11-24 |
| First published | 2018-11-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 42.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | yegor_heiz |
| Maintainers | yegor_heiz |

## Links

- npm: https://www.npmjs.com/package/amqp-producer
- Repository: https://github.com/yegorHeiz/amqp-producer
- Homepage: https://github.com/yegorHeiz/amqp-producer#readme
- Issues: https://github.com/yegorHeiz/amqp-producer/issues
- npm.io page: https://npm.io/package/amqp-producer

## Dependencies (2)

- [amqplib](https://npm.io/package/amqplib.md) ^0.5.2
- [fast-json-stringify](https://npm.io/package/fast-json-stringify.md) ^1.9.2

## Recent versions

- 1.0.5 (latest) — 2018-11-24
- 1.0.4 — 2018-11-22
- 1.0.3 — 2018-11-22
- 1.0.2 — 2018-11-22
- 1.0.1 — 2018-11-21
- 1.0.0 — 2018-11-21

## README

# AMQP Producer wrapper for emails
Package is able to connect to AMQP server and send messages to queue. Messages will be send as encoded JSON. The main approach is to send encoded JSON as message to queue in which it should be decoded and send an email based on given JSON
## Usage 
```javascript
const {MailerProducerService} = require('amqp-producer');

// Create mailerProducer instance
const mailerProducerConfig = [
    'amqp',
    'localhost',
    5672,
    'guest',
    'guest',
    '/',
    'email_queue'
];
const mailerProducer = new MailerProducerService(...mailerProducerConfig);


const start = async () => {
    // Start mailProducer
    await mailerProducer.start();
    
    // Send message to queue 
    const emailConfig = [
        'user@example.com',
        ['admin1@example.com', 'admin2@example.com'],
        'My Subject',
        'My Text'
    ];
    mailerProducer.sendEmailMsg(...emailConfig);
    
    // Stop mailProducer 
    mailerProducer.stop();
};

start();
```

## API
<a name="MailerProducerService"></a>
### MailerProducerService
An implementation of AMQP Producer

**Kind**: global class  

* [MailerProducerService](#MailerProducerService)
    * [new MailerProducerService(protocol, hostname, port, username, password, vhost, queue)](#new_MailerProducerService_new)
    * [.start()](#MailerProducerService+start) ⇒ <code>Promise.&lt;void&gt;</code>
    * [.stop()](#MailerProducerService+stop)
    * [.sendEmailMsg(to, cc, subject, text)](#MailerProducerService+sendEmailMsg)

<a name="new_MailerProducerService_new"></a>

### new MailerProducerService(protocol, hostname, port, username, password, vhost, queue)

| Param | Type |
| --- | --- |
| protocol | <code>string</code> | 
| hostname | <code>string</code> | 
| port | <code>number</code> | 
| username | <code>string</code> | 
| password | <code>string</code> | 
| vhost | <code>string</code> | 
| queue | <code>string</code> | 

<a name="MailerProducerService+start"></a>

### mailerProducerService.start() ⇒ <code>Promise.&lt;void&gt;</code>
Setup connection, channel and queue

**Kind**: instance method of [<code>MailerProducerService</code>](#MailerProducerService)  
<a name="MailerProducerService+stop"></a>

### mailerProducerService.stop()
Close connection

**Kind**: instance method of [<code>MailerProducerService</code>](#MailerProducerService)  
<a name="MailerProducerService+sendEmailMsg"></a>

### mailerProducerService.sendEmailMsg(to, cc, subject, text)
Send email msg to queue

**Kind**: instance method of [<code>MailerProducerService</code>](#MailerProducerService)  

| Param | Type |
| --- | --- |
| to | <code>string</code> | 
| cc | <code>Array.&lt;string&gt;</code> | 
| subject | <code>string</code> | 
| text | <code>string</code> |

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