# lowmq-client

> HTTPS client for LowMQ

Latest version **3.1.0** (published 2024-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install lowmq-client
pnpm add lowmq-client
yarn add lowmq-client
bun add lowmq-client
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2024-09-12 |
| First published | 2022-10-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 352.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | https://github.com/AndreyHa |
| Maintainers | andreyha |
| Keywords | lowmq, lowmq-client |

## Links

- npm: https://www.npmjs.com/package/lowmq-client
- npm.io page: https://npm.io/package/lowmq-client

## Recent versions

- 3.1.0 (latest) — 2024-09-12
- 3.0.1 — 2024-09-12
- 3.0.0 — 2024-09-12
- 2.1.0 — 2024-09-01
- 2.0.0 — 2024-07-28
- 0.2.0 — 2024-07-28
- 1.1.5 — 2024-01-07
- 1.1.4 — 2024-01-06
- 1.1.3 — 2024-01-06
- 1.1.2 — 2024-01-06
- 1.1.1 — 2024-01-04
- 1.1.0 — 2024-01-04
- 1.0.3 — 2022-10-16
- 1.0.2 — 2022-10-16
- 1.0.1 — 2022-10-14
- … 1 more at https://npm.io/package/lowmq-client/versions

## README

# LowMQ Client for Node.js

A Node.js client library for interacting with the LowMQ message broker. LowMQ is a simple, HTTP-based message broker for easily managing message queues with both synchronous and asynchronous patterns.

## Installation

To install the `lowmq-client` package, use npm or yarn:

```bash
npm install lowmq-client
```

or

```bash
yarn add lowmq-client
```

## Setup and Usage

### Import and Initialize the Client

You can import the client, set the server URL and authentication key, and start interacting with LowMQ:

```js
import LowmqClient from 'lowmq-client'

const lowmq = new LowmqClient({
  host: 'localhost', // Default: 0.0.0.0
  port: 8788,        // Default: 8788
  authKey: 'your-auth-key', // Default: 'woof'
  tls: false,        // Enable TLS (HTTPS) if needed
})
```

### Add a Packet

To add a new packet (message) to a queue:

```js
const packet = await lowmq.add('test-queue', { message: 'Hello, world!' }, { freezeTimeMin: 10 })
console.log(packet)  // Packet is frozen for 10 minutes
```

### Get a Packet

To retrieve a packet from a queue:

```js
const packet = await lowmq.get('test-queue')
console.log(packet)  // Packet will be frozen for 5 minutes by default
```

### Delete a Packet

To delete a packet from a queue:

```js
await lowmq.delete('test-queue', packet._id)
```

### Get and Delete a Packet

To get a packet and delete it in one operation:

```js
const packet = await lowmq.get('test-queue', { delete: true })
console.log(packet)  // This packet has been deleted
```

### Freeze a Packet

To freeze a specific packet:

```js
await lowmq.freeze('test-queue', packet._id)
```

### Unfreeze a Packet

To unfreeze a specific packet:

```js
await lowmq.unfreezeOne('test-queue', packet._id)
```

### Update a Packet

To update a packet's contents:

```js
const updatedPacket = await lowmq.update('test-queue', packet._id, { message: 'Updated message' })
console.log(updatedPacket)
```

## Error Handling

LowMQ client throws detailed errors based on RFC 7807 (Problem Details). The errors include types such as:

- `LowmqGetError`
- `LowmqAddError`
- `LowmqDeleteError`
- `LowmqUpdateError`
- `LowmqFreezeError`

Each error contains the following properties:
- `type`: The type of error (e.g., `invalid-token`, `no-messages-found`)
- `title`: A short description of the error
- `status`: The HTTP status code
- `detail`: Detailed information about the error

Example:

```js
try {
  const packet = await lowmq.get('non-existent-queue')
} catch (err) {
  if (err instanceof LowmqError) {
    console.error(`Error Type: ${err.type}, Message: ${err.problemDetails.detail}`)
  }
}
```

## TLS Support

LowMQ supports TLS for secure communication. To enable TLS, pass in the necessary certificates when initializing the client:

```js
const lowmq = new LowmqClient({
  host: 'your-host',
  port: 8788,
  authKey: 'your-auth-key',
  tls: true,
  tlsCert: '/path/to/cert.pem',
  tlsKey: '/path/to/key.pem',
  tlsCA: '/path/to/ca.pem'
})
```

## Server Initialization Check

By default, the client performs an initial connection check to verify if the server is reachable. If you'd like to disable this behavior:

```js
const lowmq = new LowmqClient({
  host: 'localhost',
  port: 8788,
  disableInitConnection: true
})
```

## API Reference

### LowmqClient

#### `new LowmqClient(config: object)`

- `host` (optional): The LowMQ server host (default: `0.0.0.0`)
- `port` (optional): The LowMQ server port (default: `8788`)
- `authKey` (optional): The authorization key to access the LowMQ server (default: `'woof'`)
- `tls` (optional): Enable TLS for secure communication (default: `false`)
- `tlsCert`, `tlsKey`, `tlsCA` (optional): Paths to TLS certificate, key, and CA
- `retryTimeoutMs` (optional): Time in milliseconds to retry a failed network request (default: `10000`)

#### Methods

- `add<TPayload>(key: string, payload: TPayload, options?: { freezeTimeMin?: number }): Promise<LowmqMessage<TPayload>>`
- `get<TPayload>(key: string, options?: { delete?: boolean }): Promise<LowmqMessage<TPayload>>`
- `freeze(key: string, packetId: string): Promise<LowmqMessage>`
- `unfreezeOne(key: string, packetId: string): Promise<LowmqMessage>`
- `unfreezeAll(key: string): Promise<LowmqMessage[]>`
- `update<TPayload>(key: string, packetId: string, payload: TPayload): Promise<LowmqMessage<TPayload>>`
- `delete(key: string, packetId: string): Promise<LowmqMessage>`

## Links

- [LowMQ: REST API based message broker](https://github.com/farawayCC/lowmq)
- [Installation Guide](https://github.com/farawayCC/lowmq#production)
- [NPM Package](https://www.npmjs.com/package/lowmq-client)

## License

This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.

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