@bitspacerlabs/rabbit-relay 0.5.2 → 0.6.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.
Files changed (45) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +101 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  3. package/.github/dependabot.yml +11 -0
  4. package/CODE_OF_CONDUCT.md +128 -0
  5. package/CONTRIBUTING.md +145 -0
  6. package/README.md +89 -33
  7. package/SECURITY.md +8 -0
  8. package/dist/cjs/backpressure.d.ts +4 -0
  9. package/dist/cjs/backpressure.js +31 -0
  10. package/dist/cjs/consumer.d.ts +19 -0
  11. package/dist/cjs/consumer.js +111 -0
  12. package/dist/cjs/index.d.ts +1 -0
  13. package/dist/cjs/index.js +1 -0
  14. package/dist/cjs/publisher.d.ts +13 -0
  15. package/dist/cjs/publisher.js +141 -0
  16. package/dist/cjs/rabbitmqBroker.d.ts +2 -50
  17. package/dist/cjs/rabbitmqBroker.js +31 -345
  18. package/dist/cjs/reconnect.d.ts +17 -0
  19. package/dist/cjs/reconnect.js +64 -0
  20. package/dist/cjs/topology.d.ts +9 -0
  21. package/dist/cjs/topology.js +58 -0
  22. package/dist/cjs/types.d.ts +49 -0
  23. package/dist/cjs/types.js +2 -0
  24. package/dist/cjs/uuid.d.ts +1 -0
  25. package/dist/cjs/uuid.js +6 -0
  26. package/dist/esm/backpressure.d.ts +4 -0
  27. package/dist/esm/backpressure.js +31 -0
  28. package/dist/esm/consumer.d.ts +19 -0
  29. package/dist/esm/consumer.js +111 -0
  30. package/dist/esm/index.d.ts +1 -0
  31. package/dist/esm/index.js +1 -0
  32. package/dist/esm/publisher.d.ts +13 -0
  33. package/dist/esm/publisher.js +141 -0
  34. package/dist/esm/rabbitmqBroker.d.ts +2 -50
  35. package/dist/esm/rabbitmqBroker.js +31 -345
  36. package/dist/esm/reconnect.d.ts +17 -0
  37. package/dist/esm/reconnect.js +64 -0
  38. package/dist/esm/topology.d.ts +9 -0
  39. package/dist/esm/topology.js +58 -0
  40. package/dist/esm/types.d.ts +49 -0
  41. package/dist/esm/types.js +2 -0
  42. package/dist/esm/uuid.d.ts +1 -0
  43. package/dist/esm/uuid.js +6 -0
  44. package/package.json +1 -1
  45. /package/assets/{logo.svg → rabbit-relay.svg} +0 -0
@@ -0,0 +1,101 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: sohaibqasem
7
+
8
+ ---
9
+
10
+ # Bug Report – Rabbit Relay
11
+
12
+ ## Summary
13
+ A clear and concise description of what the bug is.
14
+
15
+ ---
16
+
17
+ ## Rabbit Relay Version
18
+ - **Package:** `@bitspacerlabs/rabbit-relay`
19
+ - **Version:** `x.y.z`
20
+
21
+ ---
22
+
23
+ ## RabbitMQ Environment
24
+ - **RabbitMQ Version:** `x.y.z`
25
+ - **Deployment:** Local / Docker / Cloud
26
+ - **Clustered:** Yes / No
27
+
28
+ ---
29
+
30
+ ## Node.js Environment
31
+ - **Node.js Version:** `vXX`
32
+ - **Package Manager:** npm / pnpm / yarn
33
+ - **OS:** Linux / macOS / Windows
34
+
35
+ ---
36
+
37
+ ## What Happened?
38
+ Describe what actually happened.
39
+
40
+ ---
41
+
42
+ ## Expected Behavior
43
+ Describe what you expected to happen.
44
+
45
+ ---
46
+
47
+ ## Steps to Reproduce
48
+ 1. Configure broker with minimal setup
49
+ 2. Publish an event
50
+ 3. Start a consumer
51
+ 4. Observe the behavior
52
+
53
+ ---
54
+
55
+ ## Actual Output / Logs
56
+ ```text
57
+ Paste logs or error messages here
58
+ ```
59
+
60
+ ---
61
+
62
+ ## Example Code (Minimal Repro)
63
+ ```ts
64
+ // Paste a minimal reproducible example here
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Message / Event Details
70
+ - **Exchange:**
71
+ - **Routing Key:**
72
+ - **Queue:**
73
+ - **Event Name:**
74
+ - **Persistent:** Yes / No
75
+ - **Confirm Channel:** Yes / No
76
+ - **Deduplication Enabled:** Yes / No
77
+
78
+ ---
79
+
80
+ ## Does This Happen Consistently?
81
+ - Always
82
+ - Sometimes
83
+ - Only under load
84
+ - Only after reconnect
85
+
86
+ ---
87
+
88
+ ## Screenshots / Diagrams (Optional)
89
+ Broker topology or RabbitMQ Management UI screenshots if available.
90
+
91
+ ---
92
+
93
+ ## Additional Context
94
+ Add any other context that might help diagnose the problem (retries, reconnects, dead letters, load, etc.).
95
+
96
+ ---
97
+
98
+ ## Checklist
99
+ - [ ] I am using the latest Rabbit Relay version
100
+ - [ ] I checked existing issues
101
+ - [ ] I provided a minimal reproducible example
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "weekly"
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ @sohaibqasem.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
@@ -0,0 +1,145 @@
1
+ # Contributing to Rabbit Relay 🐇⚡
2
+
3
+ First of all, thank you for taking the time to contribute!
4
+ **Rabbit Relay** is an open-source project built with the goal of making RabbitMQ usage in Node.js **reliable, type-safe, and developer-friendly**.
5
+ Contributions of all kinds are welcome 💙
6
+
7
+ ---
8
+
9
+ ## Project Philosophy
10
+
11
+ Rabbit Relay is built around a few core principles:
12
+
13
+ - **Type safety first** (TypeScript-driven APIs)
14
+ - **Reliability over magic**
15
+ - **Explicit, predictable behavior**
16
+ - **Minimal runtime dependencies**
17
+ - **Production-ready by default**
18
+
19
+ Every contribution should aim to support these goals.
20
+
21
+ ---
22
+
23
+ ## Ways to Contribute
24
+
25
+ You can contribute in many ways, including:
26
+
27
+ - Reporting bugs
28
+ - Proposing or implementing new features
29
+ - Adding tests or improving coverage
30
+ - Improving documentation or examples
31
+ - Refactoring or improving internal code quality
32
+ - Suggesting design or API improvements
33
+
34
+ If you’re unsure where to start, check existing issues or open a discussion.
35
+
36
+ ---
37
+
38
+ ## 🐞 Reporting Bugs
39
+
40
+ Before opening a new issue:
41
+
42
+ 1. Search existing issues to avoid duplicates
43
+ 2. Make sure you're using the latest version
44
+ 3. Provide as much detail as possible
45
+
46
+ Please include:
47
+
48
+ - Rabbit Relay version
49
+ - Node.js version
50
+ - RabbitMQ version
51
+ - Minimal reproducible example (if possible)
52
+ - Expected behavior vs actual behavior
53
+ - Error logs or stack traces
54
+
55
+ ---
56
+
57
+ ## ✨ Feature Requests
58
+
59
+ Feature requests are welcome!
60
+
61
+ Please describe:
62
+
63
+ - The problem you're trying to solve
64
+ - Why existing solutions are insufficient
65
+ - How the feature fits Rabbit Relay’s philosophy
66
+ - Proposed API shape (TypeScript examples encouraged)
67
+
68
+ Large changes should be discussed before implementation.
69
+
70
+ ---
71
+
72
+ ## 🛠 Development Setup
73
+
74
+ ### Prerequisites
75
+
76
+ - Node.js (LTS recommended)
77
+ - npm or pnpm
78
+ - A running RabbitMQ instance (Docker is fine)
79
+
80
+ ### Install dependencies
81
+
82
+ ```bash
83
+ npm install
84
+ ```
85
+
86
+ ### Build the package
87
+
88
+ ```bash
89
+ npm run build
90
+ ```
91
+
92
+ ## Code Style & Conventions
93
+
94
+ - TypeScript only
95
+ - Avoid `any` unless absolutely necessary
96
+ - Prefer explicit types for public APIs
97
+ - Avoid breaking changes unless discussed
98
+ - Keep functions small and focused
99
+
100
+ ---
101
+
102
+ ## Pull Request Process
103
+
104
+ 1. Fork the repository
105
+ 2. Create a feature branch
106
+ 3. Commit with clear messages
107
+ 4. Open a Pull Request
108
+ 5. Be ready to iterate based on feedback
109
+
110
+ ---
111
+
112
+ ## 🚦 Breaking Changes
113
+
114
+ Breaking changes require:
115
+
116
+ - Clear justification
117
+ - Migration guidance
118
+ - Explicit mention in PR title and description
119
+
120
+ ---
121
+
122
+ ## 🤝 Code of Conduct
123
+
124
+ Be respectful, inclusive, and constructive.
125
+ Harassment or toxic behavior will not be tolerated.
126
+
127
+ ---
128
+
129
+ ## 💙 Community & Vision
130
+
131
+ Rabbit Relay is part of **Bitspacer Labs**, focused on open-source tooling and developer communities.
132
+
133
+ Everyone is welcome to contribute.
134
+
135
+ ---
136
+
137
+ ## ⭐ Support the Project
138
+
139
+ If you find Rabbit Relay useful:
140
+
141
+ - ⭐ Star the repository
142
+ - 📣 Share it
143
+ - 💬 Provide feedback
144
+
145
+ Thank you for contributing
package/README.md CHANGED
@@ -1,73 +1,101 @@
1
+ <!--
2
+ NOTE:
3
+ - Package: @bitspacerlabs/rabbit-relay
4
+ - Repo: https://github.com/bitspacerlabs/rabbit-relay
5
+ -->
6
+
7
+ <p align="center">
8
+ <img src="assets/rabbit-relay.svg" alt="Rabbit Relay" width="220" />
9
+ </p>
10
+
11
+ <h1 align="center">Rabbit Relay</h1>
12
+
1
13
  <p align="center">
2
- <img src="assets/logo.svg" alt="Rabbit Relay" width="260">
14
+ A <b>type-safe</b> RabbitMQ framework for Node.js (TypeScript), built on top of <b>amqplib</b> to simplify
15
+ event-driven messaging, publishing, and consumption.
3
16
  </p>
4
17
 
5
18
  <p align="center">
6
- <a href="https://www.npmjs.com/package/rabbit-relay">
7
- <img src="https://img.shields.io/npm/v/@bitspacerlabs/rabbit-relay.svg?style=flat-square" alt="NPM Version">
19
+ <a href="https://www.npmjs.com/package/@bitspacerlabs/rabbit-relay">
20
+ <img alt="npm version" src="https://img.shields.io/npm/v/@bitspacerlabs/rabbit-relay">
8
21
  </a>
9
- <a href="https://github.com/bitspacerlabs/rabbit-relay">
10
- <img src="https://img.shields.io/github/stars/@bitspacerlabs/rabbit-relay.svg?style=flat-square" alt="GitHub Stars">
22
+ <a href="https://www.npmjs.com/package/@bitspacerlabs/rabbit-relay">
23
+ <img alt="npm downloads" src="https://img.shields.io/npm/dm/@bitspacerlabs/rabbit-relay">
11
24
  </a>
12
- <a href="https://github.com/bitspacerlabs/rabbit-relay/issues">
13
- <img src="https://img.shields.io/github/issues/@bitspacerlabs/rabbit-relay.svg?style=flat-square" alt="Issues">
25
+ <a href="https://github.com/bitspacerlabs/rabbit-relay/stargazers">
26
+ <img alt="GitHub stars" src="https://img.shields.io/github/stars/bitspacerlabs/rabbit-relay?style=flat">
14
27
  </a>
15
- <a href="https://opensource.org/licenses/MIT">
16
- <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="License">
28
+ <a href="LICENSE">
29
+ <img alt="license" src="https://img.shields.io/github/license/bitspacerlabs/rabbit-relay">
17
30
  </a>
18
31
  </p>
19
32
 
20
- ---
21
-
22
- ## Rabbit Relay
23
-
24
- **Rabbit Relay** is a type-safe RabbitMQ framework for Node.js.
25
-
26
- It helps you publish and consume events using real RabbitMQ concepts, with TypeScript types and reliable defaults.
33
+ <p align="center">
34
+ <a href="https://bitspacerlabs.github.io/rabbit-relay/">Docs</a>
35
+ ·
36
+ <a href="https://github.com/bitspacerlabs/rabbit-relay/tree/main/examples">Examples</a>
37
+ ·
38
+ <a href="https://github.com/bitspacerlabs/rabbit-relay/issues">Issues</a>
39
+ ·
40
+ <a href="https://github.com/bitspacerlabs/rabbit-relay/discussions">Discussions</a>
41
+ </p>
27
42
 
28
43
  ---
29
44
 
30
- ## Start Here
45
+ ## Why Rabbit Relay?
46
+
47
+ **amqplib is powerful, but it’s low-level.** Rabbit Relay keeps “real RabbitMQ concepts” (exchanges, queues, routing keys),
48
+ and adds:
31
49
 
32
- **Documentation & Guides**
33
- https://bitspacerlabs.github.io/rabbit-relay/
50
+ - **Type-safe events** (typed payloads + versioning)
51
+ - **Cleaner publish / consume APIs** (less boilerplate)
52
+ - **Explicit topology & ownership** (no hidden abstractions)
53
+ - **Reliable defaults** (so every service doesn’t reinvent the same setup)
34
54
 
55
+ If you already use RabbitMQ and you want a better TypeScript developer experience, Rabbit Relay is for you.
35
56
 
36
57
  ---
37
58
 
38
59
  ## Installation
39
60
 
40
61
  ```bash
41
- npm install @bitspacerlabs/rabbit-relay
62
+ npm i @bitspacerlabs/rabbit-relay
42
63
  ```
43
64
 
65
+ > Tip: Rabbit Relay ships TypeScript-first and supports both ESM and CommonJS builds.
66
+
44
67
  ---
45
68
 
46
- ## Minimal Examples
69
+ ## Quickstart (typed events)
47
70
 
48
71
  ```ts
49
- import { RabbitMQBroker, event } from "rabbit-relay";
72
+ import { RabbitMQBroker, event } from "@bitspacerlabs/rabbit-relay";
50
73
 
51
74
  const broker = new RabbitMQBroker("example.service");
52
75
 
53
- const pub = await broker.queue("example.q").exchange("example.exchange", { exchangeType: "topic" });
76
+ // Create a publisher bound to your queue + exchange
77
+ const pub = await broker
78
+ .queue("example.q")
79
+ .exchange("example.exchange", { exchangeType: "topic" });
54
80
 
81
+ // Define typed events (name + version)
55
82
  const send = event("send", "v1").of<{ message: string }>();
56
83
 
84
+ // Build a typed API and publish
57
85
  const api = pub.with({ send });
58
-
59
86
  await api.send({ message: "hello world" });
60
87
  ```
61
88
 
62
- ---
63
-
89
+ ### Direct publish (produce)
64
90
 
65
91
  ```ts
66
- import { RabbitMQBroker, event } from "rabbit-relay";
92
+ import { RabbitMQBroker, event } from "@bitspacerlabs/rabbit-relay";
67
93
 
68
94
  const broker = new RabbitMQBroker("example.publisher");
69
95
 
70
- const pub = await broker.queue("example.q").exchange("example.direct", { exchangeType: "direct" });
96
+ const pub = await broker
97
+ .queue("example.q")
98
+ .exchange("example.direct", { exchangeType: "direct" });
71
99
 
72
100
  const hello = event("hello", "v1").of<{ msg: string }>();
73
101
 
@@ -76,15 +104,43 @@ await pub.produce(hello({ msg: "world" }));
76
104
 
77
105
  ---
78
106
 
79
- ## When to Use Rabbit Relay
107
+ ## Examples
108
+
109
+ See runnable examples in:
110
+ - `examples/` → https://github.com/bitspacerlabs/rabbit-relay/tree/main/examples
111
+
112
+ ---
113
+
114
+ ## When to use Rabbit Relay
80
115
 
81
116
  - You already use RabbitMQ
82
- - You want type-safe events
83
- - You prefer explicit topology and ownership
84
- - You don’t want hidden abstractions
117
+ - You want **type-safe events**
118
+ - You prefer **explicit topology** and ownership
119
+ - You don’t want “magic” abstractions
120
+
121
+ ---
122
+
123
+ ## Project status
124
+
125
+ Rabbit Relay is actively evolving. If something is unclear or missing, please open an issue (or start a discussion) with:
126
+ - what you’re trying to build
127
+ - the RabbitMQ pattern you’re using (pub/sub, work queue, RPC, etc.)
128
+ - a small code snippet
129
+
130
+ ---
131
+
132
+ ## Contributing
133
+
134
+ Contributions are welcome ❤️
135
+
136
+ - Read: [`CONTRIBUTING.md`](CONTRIBUTING.md)
137
+ - Code of Conduct: [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md)
138
+ - Security: [`SECURITY.md`](SECURITY.md)
139
+
140
+ If you want to help but don’t know where to start, check issues labeled **good first issue**.
85
141
 
86
142
  ---
87
143
 
88
144
  ## License
89
145
 
90
- MIT © BitSpacerLabs
146
+ MIT © BitSpacer Labs
package/SECURITY.md ADDED
@@ -0,0 +1,8 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+ soon
5
+
6
+ ## Reporting a Vulnerability
7
+
8
+ If you have a security issue to report, please contact us at [bitspacerlabs](bitspacerlabs/rabbit-relay).
@@ -0,0 +1,4 @@
1
+ import { Channel, Options } from "amqplib";
2
+ export declare const waitForDrain: (ch: Channel) => Promise<void>;
3
+ export declare const publishWithBackpressure: (ch: Channel, exchange: string, routingKey: string, content: Buffer, options?: Options.Publish) => Promise<void>;
4
+ export declare const maybeWaitForConfirms: (ch: Channel) => Promise<void>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maybeWaitForConfirms = exports.publishWithBackpressure = exports.waitForDrain = void 0;
4
+ const waitForDrain = (ch) => new Promise((resolve) => {
5
+ const anyCh = ch;
6
+ if (typeof anyCh.once === "function")
7
+ anyCh.once("drain", resolve);
8
+ else
9
+ resolve(); // if not supported, resolve immediately
10
+ });
11
+ exports.waitForDrain = waitForDrain;
12
+ const publishWithBackpressure = async (ch, exchange, routingKey, content, options) => {
13
+ const ok = ch.publish(exchange, routingKey, content, options);
14
+ if (!ok) {
15
+ console.warn(`[amqp] publish backpressure: waiting for 'drain' (exchange=${exchange}, key=${routingKey}, size=${content.length})`);
16
+ const t0 = Date.now();
17
+ await (0, exports.waitForDrain)(ch);
18
+ const dt = Date.now() - t0;
19
+ if (dt >= 1) {
20
+ console.warn(`[amqp] drain resolved after ${dt}ms (exchange=${exchange}, key=${routingKey})`);
21
+ }
22
+ }
23
+ };
24
+ exports.publishWithBackpressure = publishWithBackpressure;
25
+ const maybeWaitForConfirms = async (ch) => {
26
+ const anyCh = ch;
27
+ if (typeof anyCh.waitForConfirms === "function") {
28
+ await anyCh.waitForConfirms();
29
+ }
30
+ };
31
+ exports.maybeWaitForConfirms = maybeWaitForConfirms;
@@ -0,0 +1,19 @@
1
+ import { Channel } from "amqplib";
2
+ import { EventEnvelope } from "./eventFactories";
3
+ import { ConsumeOptions } from "./types";
4
+ export type HandlerMap = Map<string, (id: string | number, event: EventEnvelope) => Promise<unknown>>;
5
+ export declare function createConsumer(params: {
6
+ queueName: string;
7
+ handlers: HandlerMap;
8
+ }): {
9
+ startConsume: (getChannel: () => Promise<Channel>, opts?: ConsumeOptions) => Promise<{
10
+ stop: () => Promise<void>;
11
+ }>;
12
+ resumeOnReconnect: (ch: Channel) => Promise<void>;
13
+ getState: () => {
14
+ isConsuming: boolean;
15
+ prefetchCount: number;
16
+ concurrency: number;
17
+ onError: "ack" | "requeue" | "dead-letter";
18
+ };
19
+ };