@healthzkit/rabbitmq 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -0
- package/dist/amqp-connection-manager.d.mts +18 -0
- package/dist/amqp-connection-manager.mjs +1 -0
- package/dist/amqplib.d.mts +19 -0
- package/dist/amqplib.mjs +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +1 -0
- package/dist/shared-B-1hAtzF.mjs +1 -0
- package/dist/shared-CBgGC1WB.d.mts +13 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# @healthzkit/rabbitmq
|
|
2
|
+
|
|
3
|
+
RabbitMQ **healthzkit** `HealthAdapter` helpers for **[`amqplib`](https://github.com/amqp-node/amqplib)** and **[`amqp-connection-manager`](https://github.com/jwalton/node-amqp-connection-manager)**. Successful checks return `ok` with `metadata.latencyMs` plus any fields from an optional `metadata` hook; failures return `fail` with the caught error.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @healthzkit/rabbitmq healthzkit
|
|
9
|
+
# plus one of:
|
|
10
|
+
npm install amqplib
|
|
11
|
+
npm install amqp-connection-manager
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Both clients are optional peers—install the library you use.
|
|
15
|
+
|
|
16
|
+
## Package entrypoints
|
|
17
|
+
|
|
18
|
+
| Import | Exports |
|
|
19
|
+
| ---------------------------------------------- | ----------------------------------------------------------- |
|
|
20
|
+
| `@healthzkit/rabbitmq` | `amqplibAdapter`, `amqpConnectionManagerAdapter`, and types |
|
|
21
|
+
| `@healthzkit/rabbitmq/amqplib` | `amqplibAdapter` only |
|
|
22
|
+
| `@healthzkit/rabbitmq/amqp-connection-manager` | `amqpConnectionManagerAdapter` only |
|
|
23
|
+
|
|
24
|
+
Use subpath imports when you want to avoid pulling both clients into your bundle analysis path.
|
|
25
|
+
|
|
26
|
+
## Shared options
|
|
27
|
+
|
|
28
|
+
Both factories accept `BaseRabbitOptions`:
|
|
29
|
+
|
|
30
|
+
| Option | Description |
|
|
31
|
+
| ---------- | ----------------------------------------------------------------------------------------------------- |
|
|
32
|
+
| `metadata` | Optional `(client) => Record<string, unknown>` (sync or async) merged into metadata with `latencyMs`. |
|
|
33
|
+
|
|
34
|
+
Pass either a connection URL (or URLs) or an existing client/connection manager (not both). The shape depends on the adapter (see below).
|
|
35
|
+
|
|
36
|
+
## `amqplibAdapter` (`amqplib`)
|
|
37
|
+
|
|
38
|
+
**Peer:** `amqplib` ≥ 1 or ≥ 2.
|
|
39
|
+
|
|
40
|
+
Each check opens a channel on the connection and closes it immediately. That exercises the broker path without leaving channels open.
|
|
41
|
+
|
|
42
|
+
### URL
|
|
43
|
+
|
|
44
|
+
The adapter lazily imports `amqplib`, calls `connect(url, socketOptions)` once, and reuses the same `ChannelModel` across checks.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { createHealthKit } from "healthzkit";
|
|
48
|
+
import { amqplibAdapter } from "@healthzkit/rabbitmq";
|
|
49
|
+
|
|
50
|
+
const kit = createHealthKit({
|
|
51
|
+
checks: [
|
|
52
|
+
{
|
|
53
|
+
name: "rabbitmq",
|
|
54
|
+
type: ["readiness"],
|
|
55
|
+
adapter: amqplibAdapter({
|
|
56
|
+
url: process.env.AMQP_URL!,
|
|
57
|
+
socketOptions: { timeout: 2000 },
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`url` may be a connection string or an `Options.Connect` object accepted by `amqplib.connect`.
|
|
65
|
+
|
|
66
|
+
### Existing connection
|
|
67
|
+
|
|
68
|
+
Pass **`connection`** as an existing `ChannelModel` or `RecoveringChannelModel` from your app. The adapter reuses that connection across checks.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import amqplib from "amqplib";
|
|
72
|
+
import { amqplibAdapter } from "@healthzkit/rabbitmq/amqplib";
|
|
73
|
+
|
|
74
|
+
const connection = await amqplib.connect(process.env.AMQP_URL!);
|
|
75
|
+
|
|
76
|
+
const adapter = amqplibAdapter({
|
|
77
|
+
connection,
|
|
78
|
+
metadata: () => ({ driver: "amqplib" }),
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## `amqpConnectionManagerAdapter` (`amqp-connection-manager`)
|
|
83
|
+
|
|
84
|
+
**Peer:** `amqp-connection-manager` ≥ 4 or ≥ 5.
|
|
85
|
+
|
|
86
|
+
Each check verifies that the connection manager reports at least one active connection via `isConnected()`. Use this when your app already relies on automatic reconnects and you want readiness to reflect the manager’s view of connectivity rather than opening a new channel.
|
|
87
|
+
|
|
88
|
+
### URLs
|
|
89
|
+
|
|
90
|
+
The adapter lazily imports `amqp-connection-manager`, calls `connect(urls, connectionOptions)` once, and reuses the same manager across checks.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { amqpConnectionManagerAdapter } from "@healthzkit/rabbitmq/amqp-connection-manager";
|
|
94
|
+
|
|
95
|
+
const adapter = amqpConnectionManagerAdapter({
|
|
96
|
+
urls: [process.env.AMQP_URL!],
|
|
97
|
+
connectionOptions: {
|
|
98
|
+
heartbeatIntervalInSeconds: 5,
|
|
99
|
+
reconnectTimeInSeconds: 2,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Existing connection manager
|
|
105
|
+
|
|
106
|
+
Pass **`connection`** as your app’s `AmqpConnectionManager` instance.
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { connect } from "amqp-connection-manager";
|
|
110
|
+
import { amqpConnectionManagerAdapter } from "@healthzkit/rabbitmq";
|
|
111
|
+
|
|
112
|
+
const connection = connect([process.env.AMQP_URL!]);
|
|
113
|
+
|
|
114
|
+
const adapter = amqpConnectionManagerAdapter({
|
|
115
|
+
connection,
|
|
116
|
+
metadata: () => ({ driver: "amqp-connection-manager" }),
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
If no connection is active, the check fails with `rabbitmq adapter: connection manager has no active connections.`
|
|
121
|
+
|
|
122
|
+
## Check result
|
|
123
|
+
|
|
124
|
+
On success:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"status": "ok",
|
|
129
|
+
"metadata": { "latencyMs": 12 }
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
On failure, `status` is `"fail"` and `error` is set (see [healthzkit](https://github.com/alasti-company/healthzkit) for how that rolls up into probe responses).
|
|
134
|
+
|
|
135
|
+
## Scheduling
|
|
136
|
+
|
|
137
|
+
For brokers that should not be probed on every request, pair these adapters with a **`schedule`** on the check so readiness reads cached results instead of opening channels on every probe. See the **Scheduling** section in the `healthzkit` README.
|
|
138
|
+
|
|
139
|
+
## Development
|
|
140
|
+
|
|
141
|
+
From the monorepo root:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
vp install
|
|
145
|
+
vp test --filter @healthzkit/rabbitmq
|
|
146
|
+
vp pack --filter @healthzkit/rabbitmq
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
See the repo root `AGENTS.md` for Vite+ / `vp` conventions.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { n as HealthAdapter, t as BaseRabbitOptions } from "./shared-CBgGC1WB.mjs";
|
|
2
|
+
import { AmqpConnectionManager, AmqpConnectionManagerOptions } from "amqp-connection-manager";
|
|
3
|
+
|
|
4
|
+
//#region src/amqp-connection-manager.d.ts
|
|
5
|
+
interface AmqpConnectionManagerAdapterOptionsWithConnection extends BaseRabbitOptions<AmqpConnectionManager> {
|
|
6
|
+
connection: AmqpConnectionManager;
|
|
7
|
+
urls?: never;
|
|
8
|
+
connectionOptions?: never;
|
|
9
|
+
}
|
|
10
|
+
interface AmqpConnectionManagerAdapterOptionsWithUrls extends BaseRabbitOptions<AmqpConnectionManager> {
|
|
11
|
+
urls: string[];
|
|
12
|
+
connectionOptions?: AmqpConnectionManagerOptions;
|
|
13
|
+
connection?: never;
|
|
14
|
+
}
|
|
15
|
+
type AmqpConnectionManagerAdapterOptions = AmqpConnectionManagerAdapterOptionsWithConnection | AmqpConnectionManagerAdapterOptionsWithUrls;
|
|
16
|
+
declare function amqpConnectionManagerAdapter(options: AmqpConnectionManagerAdapterOptions): HealthAdapter;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { AmqpConnectionManagerAdapterOptions, AmqpConnectionManagerAdapterOptionsWithConnection, AmqpConnectionManagerAdapterOptionsWithUrls, amqpConnectionManagerAdapter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./shared-B-1hAtzF.mjs";function n(n){let r=null,i=null;async function a(){return`connection`in n&&n.connection?n.connection:r||i||(i=(async()=>{let{connect:e}=await import(`amqp-connection-manager`),t=e(n.urls,n.connectionOptions);return r=t,i=null,t})(),i)}return{async check(){try{let t=await a(),r=Date.now();if(!t.isConnected())throw Error(`rabbitmq adapter: connection manager has no active connections.`);let i=Date.now()-r,o=n.metadata?n.metadata(t):void 0;return e(i,o instanceof Promise?await o:o)}catch(e){return t(e)}}}}export{n as amqpConnectionManagerAdapter};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { n as HealthAdapter, t as BaseRabbitOptions } from "./shared-CBgGC1WB.mjs";
|
|
2
|
+
import { ChannelModel, Options, RecoveringChannelModel, SocketOptions } from "amqplib";
|
|
3
|
+
|
|
4
|
+
//#region src/amqplib.d.ts
|
|
5
|
+
type AmqplibClient = ChannelModel | RecoveringChannelModel;
|
|
6
|
+
interface AmqplibAdapterOptionsWithConnection extends BaseRabbitOptions<AmqplibClient> {
|
|
7
|
+
connection: AmqplibClient;
|
|
8
|
+
url?: never;
|
|
9
|
+
socketOptions?: never;
|
|
10
|
+
}
|
|
11
|
+
interface AmqplibAdapterOptionsWithUrl extends BaseRabbitOptions<AmqplibClient> {
|
|
12
|
+
url: string | Options.Connect;
|
|
13
|
+
socketOptions?: SocketOptions;
|
|
14
|
+
connection?: never;
|
|
15
|
+
}
|
|
16
|
+
type AmqplibAdapterOptions = AmqplibAdapterOptionsWithConnection | AmqplibAdapterOptionsWithUrl;
|
|
17
|
+
declare function amqplibAdapter(options: AmqplibAdapterOptions): HealthAdapter;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { AmqplibAdapterOptions, AmqplibAdapterOptionsWithConnection, AmqplibAdapterOptionsWithUrl, AmqplibClient, amqplibAdapter };
|
package/dist/amqplib.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./shared-B-1hAtzF.mjs";function n(n){let r=null,i=null;async function a(){return`connection`in n&&n.connection?n.connection:r||i||(i=(async()=>{try{let{default:e}=await import(`amqplib`),t=await e.connect(n.url,n.socketOptions);return r=t,t}finally{i=null}})(),i)}return{async check(){try{let t=await a(),r=Date.now();await(await t.createChannel()).close();let i=Date.now()-r,o=n.metadata?n.metadata(t):void 0;return e(i,o instanceof Promise?await o:o)}catch(e){return t(e)}}}}export{n as amqplibAdapter};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AmqpConnectionManagerAdapterOptions, amqpConnectionManagerAdapter } from "./amqp-connection-manager.mjs";
|
|
2
|
+
import { AmqplibAdapterOptions, amqplibAdapter } from "./amqplib.mjs";
|
|
3
|
+
export { type AmqpConnectionManagerAdapterOptions, type AmqplibAdapterOptions, amqpConnectionManagerAdapter, amqplibAdapter };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{amqplibAdapter as e}from"./amqplib.mjs";import{amqpConnectionManagerAdapter as t}from"./amqp-connection-manager.mjs";export{t as amqpConnectionManagerAdapter,e as amqplibAdapter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){return{status:`ok`,metadata:{...t,latencyMs:e}}}function t(e){return{status:`fail`,error:e instanceof Error?e:Error(String(e))}}export{e as n,t};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HealthAdapter } from "healthzkit";
|
|
2
|
+
|
|
3
|
+
//#region src/shared.d.ts
|
|
4
|
+
type MetadataFn<TClient> = (client: TClient) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
5
|
+
interface BaseRabbitOptions<TClient> {
|
|
6
|
+
/**
|
|
7
|
+
* Optional function to populate metadata in the check result.
|
|
8
|
+
* Receives the resolved client so you can run additional operations.
|
|
9
|
+
*/
|
|
10
|
+
metadata?: MetadataFn<TClient>;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { HealthAdapter as n, BaseRabbitOptions as t };
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@healthzkit/rabbitmq",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"license": "AGPL-3.0-only",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/alasti-company/healthzkit.dev",
|
|
8
|
+
"directory": "packages/rabbitmq"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./dist/index.mjs",
|
|
16
|
+
"./amqp-connection-manager": "./dist/amqp-connection-manager.mjs",
|
|
17
|
+
"./amqplib": "./dist/amqplib.mjs",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "vp pack",
|
|
25
|
+
"dev": "vp pack --watch",
|
|
26
|
+
"test": "vp test",
|
|
27
|
+
"check": "vp check",
|
|
28
|
+
"prepublishOnly": "vp run build"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/amqplib": "^0.10.8",
|
|
32
|
+
"@types/node": "^25.6.2",
|
|
33
|
+
"@typescript/native-preview": "7.0.0-dev.20260509.2",
|
|
34
|
+
"amqp-connection-manager": "^5.0.0",
|
|
35
|
+
"amqplib": "^2.0.1",
|
|
36
|
+
"bumpp": "^11.1.0",
|
|
37
|
+
"healthzkit": "workspace:*",
|
|
38
|
+
"typescript": "^6.0.3",
|
|
39
|
+
"vite-plus": "^0.1.20"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"amqp-connection-manager": ">=4.0.0 || >=5.0.0",
|
|
43
|
+
"amqplib": ">=1.0.0 || >=2.0.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependenciesMeta": {
|
|
46
|
+
"amqp-connection-manager": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"amqplib": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|