# fastify-async-mqtt

> fastify async mqtt plugin with ts support

Latest version **1.0.1** (published 2023-03-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install fastify-async-mqtt
pnpm add fastify-async-mqtt
yarn add fastify-async-mqtt
bun add fastify-async-mqtt
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-03-25 |
| First published | 2023-03-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 19.5 KB |
| Known vulnerabilities | 0 (+4 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | dmprkp |
| Keywords | fastify, mqtt, async |

## Links

- npm: https://www.npmjs.com/package/fastify-async-mqtt
- Repository: https://github.com/DmPrkp/fastify-async-mqtt
- Homepage: https://github.com/DmPrkp/fastify-async-mqtt#readme
- Issues: https://github.com/DmPrkp/fastify-async-mqtt/issues
- npm.io page: https://npm.io/package/fastify-async-mqtt

## Dependencies (3)

- [fastify](https://npm.io/package/fastify.md) ^4.15.0
- [async-mqtt](https://npm.io/package/async-mqtt.md) ^2.6.3
- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^4.5.0

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2023-03-25
- 1.0.0 — 2023-03-25

## README

# fastify-async-mqtt

<!-- ![CI](https://github.com/fastify/fastify-mongodb/workflows/CI/badge.svg) -->
<!-- [![NPM version](https://img.shields.io/npm/v/@fastify/mongodb.svg?style=flat)](https://www.npmjs.com/package/@fastify/mongodb) -->
<!-- [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) -->

Fastify Async Mqtt is wrapper over [async-mqtt](https://www.npmjs.com/package/async-mqtt) with TypeScript support.

## Install

```
npm i fastify-async-mqtt
```

## Usage
Add it to your project with `register` and you are done!  

```ts
import fastify from 'fastify'
import { fastifyMQTT } from './mqtt-module'

const server = fastify()

// register plugin 
server.register(fastifyMQTT, { url: 'mqtt://localhost:1883' })

server.register(async function (instance) { 
    if (!instance.mqttClient) return
    await instance.mqttClient.publish("hello/world", "Hi Mosquitto");
  })

server.listen({ port: 3000, host: '0.0.0.0' }, err => {
  if (err) throw err
})
```
or usage on request

```ts
// another type of register
server.register(fastifyMQTT, { 
        opts: {host: 'mosquitto', port: 1883, protocol: 'mqtt'}, 
        allowRetries: false 
    })

server.get('/ping/mqtt', async function (req, reply) {
    await this.mqttClient.publish("hello/world", "Hi Mosquitto");
    reply.send({mqtt: 'pinged'})
})

```

## License

Licensed under [MIT](./LICENSE).

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