<commit_before># mq-pubsub

![Build Status](https://travis-ci.org/philcockfield/mq-pubsub.svg)](https://travis-ci.org/philcockfield/mq-pubsub)

Pub/sub pattern for microservices using RabbitMQ.


## Installation

    npm install --save mq-pubsub


## Usage
Initialize a connection to a RabbitMQ server:

```js
import factory from "mq-pubsub";
const pubsub = factory("amqp://rabbitmq");
```

Create individual event-managers by passing the event's name to the `event` method:

```js
const myEvent = pubsub.event("my-event");
```

To listen to events pass the `subscribe` method a handler:

```js
myEvent.subscribe(data => {
    // ...
});

```

and to publish events, use the `publish` method:

```js
myEvent.publish({ foo: 123 });
```

These methods can be used immediately without waiting for the connection to complete.  The module manages the connection state internally, and pushes publishes events when the connection is established.


## Example
Look in the `/example` folder, you will need to change the `amqp://` URL to your RabbitMQ server.

Start one or more consoles as subscribed listeners:

```bash
npm run sub
```

Then run the the publish script, optionally passing the number of events to fire:

```bash
npm run pub     # Fires one event.
npm run pub 15  # Fires 15 events.
```


## Tests

    npm test


## Docker Commands

    docker run -it -p 5672:5672 rabbitmq:latest


---
### License: MIT
<commit_msg>CI Badge<commit_after># mq-pubsub

[![Build Status](https://travis-ci.org/philcockfield/mq-connection.svg?branch=master)](https://travis-ci.org/philcockfield/mq-connection)

Pub/sub pattern for microservices using RabbitMQ.


## Installation

    npm install --save mq-pubsub


## Usage
Initialize a connection to a RabbitMQ server:

```js
import factory from "mq-pubsub";
const pubsub = factory("amqp://rabbitmq");
```

Create individual event-managers by passing the event's name to the `event` method:

```js
const myEvent = pubsub.event("my-event");
```

To listen to events pass the `subscribe` method a handler:

```js
myEvent.subscribe(data => {
    // ...
});

```

and to publish events, use the `publish` method:

```js
myEvent.publish({ foo: 123 });
```

These methods can be used immediately without waiting for the connection to complete.  The module manages the connection state internally, and pushes publishes events when the connection is established.


## Example
Look in the `/example` folder, you will need to change the `amqp://` URL to your RabbitMQ server.

Start one or more consoles as subscribed listeners:

```bash
npm run sub
```

Then run the the publish script, optionally passing the number of events to fire:

```bash
npm run pub     # Fires one event.
npm run pub 15  # Fires 15 events.
```


## Tests

    npm test


## Docker Commands

    docker run -it -p 5672:5672 rabbitmq:latest


---
### License: MIT

{'fraction_non_alphanumeric': 0.11688764829030007, 'fraction_numerical': 0.0104675505931612, 'mean_word_length': 3.8758503401360542, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6552856', 'n_tokens_mistral': 958, 'n_tokens_neox': 845, 'n_words': 343}