@geekmidas/events 10.0.0-alpha.9 → 10.0.0-alpha.90
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 +46 -1
- package/dist/SQSSubscriber-BEJBfNTe.mjs +264 -0
- package/dist/SQSSubscriber-BEJBfNTe.mjs.map +1 -0
- package/dist/SQSSubscriber-COTqWvOk.cjs +288 -0
- package/dist/SQSSubscriber-COTqWvOk.cjs.map +1 -0
- package/dist/basic/index.cjs +41 -11
- package/dist/basic/index.cjs.map +1 -1
- package/dist/basic/index.d.cts +11 -10
- package/dist/basic/index.d.cts.map +1 -1
- package/dist/basic/index.d.mts +11 -10
- package/dist/basic/index.d.mts.map +1 -1
- package/dist/basic/index.mjs +39 -10
- package/dist/basic/index.mjs.map +1 -1
- package/dist/index.cjs +47 -151
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +82 -26
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +82 -26
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +34 -151
- package/dist/index.mjs.map +1 -1
- package/dist/pgboss/index.cjs +198 -34
- package/dist/pgboss/index.cjs.map +1 -1
- package/dist/pgboss/index.d.cts +54 -12
- package/dist/pgboss/index.d.cts.map +1 -1
- package/dist/pgboss/index.d.mts +54 -12
- package/dist/pgboss/index.d.mts.map +1 -1
- package/dist/pgboss/index.mjs +193 -34
- package/dist/pgboss/index.mjs.map +1 -1
- package/dist/rabbitmq/index.cjs +173 -27
- package/dist/rabbitmq/index.cjs.map +1 -1
- package/dist/rabbitmq/index.d.cts +19 -10
- package/dist/rabbitmq/index.d.cts.map +1 -1
- package/dist/rabbitmq/index.d.mts +19 -10
- package/dist/rabbitmq/index.d.mts.map +1 -1
- package/dist/rabbitmq/index.mjs +169 -27
- package/dist/rabbitmq/index.mjs.map +1 -1
- package/dist/registry-DIx25Q5s.d.cts +255 -0
- package/dist/registry-DIx25Q5s.d.cts.map +1 -0
- package/dist/registry-DIx25Q5s.d.mts +255 -0
- package/dist/registry-DIx25Q5s.d.mts.map +1 -0
- package/dist/registry-DXLY1Xf6.mjs +99 -0
- package/dist/registry-DXLY1Xf6.mjs.map +1 -0
- package/dist/registry-DlT36229.cjs +122 -0
- package/dist/registry-DlT36229.cjs.map +1 -0
- package/dist/{chunk-CsX-DzYB.cjs → rolldown-runtime-C0BPl7ul.cjs} +17 -16
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/sns/index.cjs +403 -40
- package/dist/sns/index.cjs.map +1 -1
- package/dist/sns/index.d.cts +175 -11
- package/dist/sns/index.d.cts.map +1 -1
- package/dist/sns/index.d.mts +175 -11
- package/dist/sns/index.d.mts.map +1 -1
- package/dist/sns/index.mjs +372 -24
- package/dist/sns/index.mjs.map +1 -1
- package/dist/sns/snsUrl.cjs +91 -6
- package/dist/sns/snsUrl.cjs.map +1 -0
- package/dist/sns/snsUrl.d.cts +57 -2
- package/dist/sns/snsUrl.d.cts.map +1 -0
- package/dist/sns/snsUrl.d.mts +57 -2
- package/dist/sns/snsUrl.d.mts.map +1 -0
- package/dist/sns/snsUrl.mjs +81 -2
- package/dist/sns/snsUrl.mjs.map +1 -0
- package/dist/sqs/index.cjs +31 -65
- package/dist/sqs/index.cjs.map +1 -1
- package/dist/sqs/index.d.cts +28 -11
- package/dist/sqs/index.d.cts.map +1 -1
- package/dist/sqs/index.d.mts +28 -11
- package/dist/sqs/index.d.mts.map +1 -1
- package/dist/sqs/index.mjs +22 -58
- package/dist/sqs/index.mjs.map +1 -1
- package/dist/sqs/sqsUrl.cjs +92 -6
- package/dist/sqs/sqsUrl.cjs.map +1 -0
- package/dist/sqs/sqsUrl.d.cts +56 -2
- package/dist/sqs/sqsUrl.d.cts.map +1 -0
- package/dist/sqs/sqsUrl.d.mts +56 -2
- package/dist/sqs/sqsUrl.d.mts.map +1 -0
- package/dist/sqs/sqsUrl.mjs +82 -2
- package/dist/sqs/sqsUrl.mjs.map +1 -0
- package/dist/telemetry-DG3l807O.cjs +309 -0
- package/dist/telemetry-DG3l807O.cjs.map +1 -0
- package/dist/telemetry-DjjgJMul.mjs +244 -0
- package/dist/telemetry-DjjgJMul.mjs.map +1 -0
- package/package.json +8 -3
- package/dist/PgBossConnection-23soZ_aM.cjs +0 -80
- package/dist/PgBossConnection-23soZ_aM.cjs.map +0 -1
- package/dist/PgBossConnection-CCXhoNzb.cjs +0 -4
- package/dist/PgBossConnection-DvNbd4Zk.mjs +0 -74
- package/dist/PgBossConnection-DvNbd4Zk.mjs.map +0 -1
- package/dist/PgBossConnection-_gdM40JB.mjs +0 -4
- package/dist/RabbitMQConnection-BKEdCUro.cjs +0 -113
- package/dist/RabbitMQConnection-BKEdCUro.cjs.map +0 -1
- package/dist/RabbitMQConnection-CCOqDDnb.cjs +0 -4
- package/dist/RabbitMQConnection-DJEyM-Bu.mjs +0 -4
- package/dist/RabbitMQConnection-DJgUPc19.mjs +0 -107
- package/dist/RabbitMQConnection-DJgUPc19.mjs.map +0 -1
- package/dist/SNSConnection-B2K86hpz.cjs +0 -75
- package/dist/SNSConnection-B2K86hpz.cjs.map +0 -1
- package/dist/SNSConnection-BVo84FeW.mjs +0 -5
- package/dist/SNSConnection-DIHRjrQF.cjs +0 -5
- package/dist/SNSConnection-v9jjF99w.mjs +0 -69
- package/dist/SNSConnection-v9jjF99w.mjs.map +0 -1
- package/dist/SQSConnection-4tBMkVZE.mjs +0 -69
- package/dist/SQSConnection-4tBMkVZE.mjs.map +0 -1
- package/dist/SQSConnection-BBLAvF-1.cjs +0 -5
- package/dist/SQSConnection-BaC7rGhI.cjs +0 -75
- package/dist/SQSConnection-BaC7rGhI.cjs.map +0 -1
- package/dist/SQSConnection-DbavOq8_.mjs +0 -5
- package/dist/SQSSubscriber-BMWZ3s5q.mjs +0 -114
- package/dist/SQSSubscriber-BMWZ3s5q.mjs.map +0 -1
- package/dist/SQSSubscriber-YXPlg2rm.cjs +0 -120
- package/dist/SQSSubscriber-YXPlg2rm.cjs.map +0 -1
- package/dist/chunk-B9dir_RE.mjs +0 -11
- package/dist/snsUrl-ASdc0D1v.d.cts +0 -61
- package/dist/snsUrl-ASdc0D1v.d.cts.map +0 -1
- package/dist/snsUrl-CifYhPAa.mjs +0 -79
- package/dist/snsUrl-CifYhPAa.mjs.map +0 -1
- package/dist/snsUrl-FRbRcwF0.d.mts +0 -61
- package/dist/snsUrl-FRbRcwF0.d.mts.map +0 -1
- package/dist/snsUrl-f2gU3CzK.cjs +0 -114
- package/dist/snsUrl-f2gU3CzK.cjs.map +0 -1
- package/dist/sqsUrl-BV6zS-mi.d.mts +0 -60
- package/dist/sqsUrl-BV6zS-mi.d.mts.map +0 -1
- package/dist/sqsUrl-CbAsBFHI.mjs +0 -80
- package/dist/sqsUrl-CbAsBFHI.mjs.map +0 -1
- package/dist/sqsUrl-CdisN3GU.cjs +0 -115
- package/dist/sqsUrl-CdisN3GU.cjs.map +0 -1
- package/dist/sqsUrl-DZDPHxIk.d.cts +0 -60
- package/dist/sqsUrl-DZDPHxIk.d.cts.map +0 -1
- package/dist/types-BmixGrOD.d.cts +0 -67
- package/dist/types-BmixGrOD.d.cts.map +0 -1
- package/dist/types-Byv8N9ma.cjs +0 -24
- package/dist/types-Byv8N9ma.cjs.map +0 -1
- package/dist/types-CYDt-2RQ.mjs +0 -18
- package/dist/types-CYDt-2RQ.mjs.map +0 -1
- package/dist/types-DycjsYms.d.mts +0 -67
- package/dist/types-DycjsYms.d.mts.map +0 -1
package/dist/pgboss/index.mjs
CHANGED
|
@@ -1,41 +1,158 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { a as consumeTraced, c as withTraceKey, l as withoutTraceKey, s as publishTraced } from "../telemetry-DjjgJMul.mjs";
|
|
3
|
+
import { PgBoss } from "pg-boss";
|
|
4
|
+
//#region src/pgboss/PgBossConnection.ts
|
|
5
|
+
var PgBossConnection_exports = /* @__PURE__ */ __exportAll({ PgBossConnection: () => PgBossConnection });
|
|
6
|
+
var PgBossConnection = class PgBossConnection {
|
|
7
|
+
config;
|
|
8
|
+
type = "pgboss";
|
|
9
|
+
boss;
|
|
10
|
+
connecting;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a PgBossConnection from a connection string.
|
|
16
|
+
* Format: pgboss://user:pass@host:5432/database?schema=pgboss
|
|
17
|
+
*/
|
|
18
|
+
static async fromConnectionString(connectionString) {
|
|
19
|
+
const url = new URL(connectionString);
|
|
20
|
+
const params = url.searchParams;
|
|
21
|
+
const config = {
|
|
22
|
+
connectionString: `postgres://${url.username ? `${url.username}:${url.password}@` : ""}${url.host}${url.pathname}`,
|
|
23
|
+
schema: params.get("schema") || void 0
|
|
24
|
+
};
|
|
25
|
+
const connection = new PgBossConnection(config);
|
|
26
|
+
await connection.connect();
|
|
27
|
+
return connection;
|
|
28
|
+
}
|
|
29
|
+
async connect() {
|
|
30
|
+
if (this.boss) return;
|
|
31
|
+
if (this.connecting) {
|
|
32
|
+
await this.connecting;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
this.connecting = (async () => {
|
|
36
|
+
try {
|
|
37
|
+
const applicationName = this.config.applicationName ?? process.env.GKM_APP_NAME;
|
|
38
|
+
const boss = new PgBoss({
|
|
39
|
+
connectionString: this.config.connectionString,
|
|
40
|
+
...this.config.schema && { schema: this.config.schema },
|
|
41
|
+
...applicationName && { application_name: applicationName }
|
|
42
|
+
});
|
|
43
|
+
await boss.start();
|
|
44
|
+
this.boss = boss;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
this.cleanup();
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
50
|
+
await this.connecting;
|
|
51
|
+
this.connecting = void 0;
|
|
52
|
+
}
|
|
53
|
+
async close() {
|
|
54
|
+
try {
|
|
55
|
+
await this.boss?.stop({ graceful: true });
|
|
56
|
+
} catch {} finally {
|
|
57
|
+
this.cleanup();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
isConnected() {
|
|
61
|
+
return !!this.boss;
|
|
62
|
+
}
|
|
63
|
+
cleanup() {
|
|
64
|
+
this.boss = void 0;
|
|
65
|
+
this.connecting = void 0;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get the underlying pg-boss instance for publishing/subscribing
|
|
69
|
+
*/
|
|
70
|
+
get instance() {
|
|
71
|
+
return this.boss;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/pgboss/errors.ts
|
|
76
|
+
/** pg-boss connected but its instance never started. */
|
|
77
|
+
var PgBossNotStarted = class extends Error {
|
|
78
|
+
constructor() {
|
|
79
|
+
super("pg-boss did not start. Check the database in the connection string is reachable and the role may create the pg-boss schema.");
|
|
80
|
+
this.name = "PgBossNotStarted";
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/** A topic subscription with no name to give the subscriber's own queue. */
|
|
84
|
+
var PgBossSubscriptionNeedsName = class extends Error {
|
|
85
|
+
topic;
|
|
86
|
+
constructor(topic) {
|
|
87
|
+
super(`Subscribing to topic '${topic}' on pg-boss needs a subscription name: each subscriber drains a queue of its own, and that queue is named for it. Pass \`subscription\`.`);
|
|
88
|
+
this.topic = topic;
|
|
89
|
+
this.name = "PgBossSubscriptionNeedsName";
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
//#endregion
|
|
4
93
|
//#region src/pgboss/PgBossPublisher.ts
|
|
94
|
+
/** The pg-boss event a topic's message type is published as. */
|
|
95
|
+
function topicEvent(topic, type) {
|
|
96
|
+
return `${topic}/${type}`;
|
|
97
|
+
}
|
|
5
98
|
var PgBossPublisher = class PgBossPublisher {
|
|
6
|
-
|
|
99
|
+
connection;
|
|
100
|
+
options;
|
|
101
|
+
constructor(connection, options = {}) {
|
|
7
102
|
this.connection = connection;
|
|
103
|
+
this.options = options;
|
|
8
104
|
}
|
|
9
105
|
/**
|
|
10
106
|
* Create a PgBossPublisher from a connection string.
|
|
11
107
|
* Format: pgboss://user:pass@host:5432/database?schema=pgboss
|
|
12
108
|
*/
|
|
13
|
-
static async fromConnectionString(connectionString) {
|
|
14
|
-
const { PgBossConnection
|
|
15
|
-
const connection = await PgBossConnection
|
|
16
|
-
return new PgBossPublisher(connection);
|
|
109
|
+
static async fromConnectionString(connectionString, options = {}) {
|
|
110
|
+
const { PgBossConnection } = await Promise.resolve().then(() => PgBossConnection_exports);
|
|
111
|
+
const connection = await PgBossConnection.fromConnectionString(connectionString);
|
|
112
|
+
return new PgBossPublisher(connection, options);
|
|
17
113
|
}
|
|
18
114
|
async publish(messages) {
|
|
19
115
|
if (!this.connection.isConnected()) await this.connection.connect();
|
|
20
116
|
const boss = this.connection.instance;
|
|
21
|
-
if (!boss) throw new
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
117
|
+
if (!boss) throw new PgBossNotStarted();
|
|
118
|
+
const { topic } = this.options;
|
|
119
|
+
if (topic) {
|
|
120
|
+
await publishTraced(messages, (m) => ({
|
|
121
|
+
system: "pgboss",
|
|
122
|
+
destination: topic,
|
|
123
|
+
type: m.type
|
|
124
|
+
}), async (carriers) => {
|
|
125
|
+
for (const [i, m] of messages.entries()) await boss.publish(topicEvent(topic, m.type), withTraceKey({
|
|
126
|
+
type: m.type,
|
|
127
|
+
payload: m.payload
|
|
128
|
+
}, carriers[i]));
|
|
129
|
+
});
|
|
130
|
+
return;
|
|
31
131
|
}
|
|
132
|
+
await publishTraced(messages, (m) => ({
|
|
133
|
+
system: "pgboss",
|
|
134
|
+
destination: m.type,
|
|
135
|
+
type: m.type
|
|
136
|
+
}), async (carriers) => {
|
|
137
|
+
const groups = /* @__PURE__ */ new Map();
|
|
138
|
+
for (const [i, m] of messages.entries()) {
|
|
139
|
+
const list = groups.get(m.type) ?? [];
|
|
140
|
+
list.push({ data: withTraceKey(m.payload, carriers[i]) });
|
|
141
|
+
groups.set(m.type, list);
|
|
142
|
+
}
|
|
143
|
+
for (const [name, jobs] of groups) {
|
|
144
|
+
await boss.createQueue(name);
|
|
145
|
+
await boss.insert(name, jobs);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
32
148
|
}
|
|
33
149
|
async close() {}
|
|
34
150
|
};
|
|
35
|
-
|
|
36
151
|
//#endregion
|
|
37
152
|
//#region src/pgboss/PgBossSubscriber.ts
|
|
38
153
|
var PgBossSubscriber = class PgBossSubscriber {
|
|
154
|
+
connection;
|
|
155
|
+
options;
|
|
39
156
|
constructor(connection, options = {}) {
|
|
40
157
|
this.connection = connection;
|
|
41
158
|
this.options = options;
|
|
@@ -45,10 +162,9 @@ var PgBossSubscriber = class PgBossSubscriber {
|
|
|
45
162
|
* Format: pgboss://user:pass@host:5432/database?schema=pgboss&batchSize=5
|
|
46
163
|
*/
|
|
47
164
|
static async fromConnectionString(connectionString) {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const connection = await PgBossConnection$1.fromConnectionString(connectionString);
|
|
165
|
+
const params = new URL(connectionString).searchParams;
|
|
166
|
+
const { PgBossConnection } = await Promise.resolve().then(() => PgBossConnection_exports);
|
|
167
|
+
const connection = await PgBossConnection.fromConnectionString(connectionString);
|
|
52
168
|
const options = {
|
|
53
169
|
batchSize: params.get("batchSize") ? Number.parseInt(params.get("batchSize"), 10) : void 0,
|
|
54
170
|
pollingIntervalSeconds: params.get("pollingIntervalSeconds") ? Number.parseInt(params.get("pollingIntervalSeconds"), 10) : void 0
|
|
@@ -58,25 +174,68 @@ var PgBossSubscriber = class PgBossSubscriber {
|
|
|
58
174
|
async subscribe(messages, listener) {
|
|
59
175
|
if (!this.connection.isConnected()) await this.connection.connect();
|
|
60
176
|
const boss = this.connection.instance;
|
|
61
|
-
if (!boss) throw new
|
|
177
|
+
if (!boss) throw new PgBossNotStarted();
|
|
178
|
+
const work = {
|
|
179
|
+
...this.options.batchSize && { batchSize: this.options.batchSize },
|
|
180
|
+
...this.options.pollingIntervalSeconds && { pollingIntervalSeconds: this.options.pollingIntervalSeconds }
|
|
181
|
+
};
|
|
182
|
+
const { topic, subscription } = this.options;
|
|
183
|
+
if (topic) {
|
|
184
|
+
if (!subscription) throw new PgBossSubscriptionNeedsName(topic);
|
|
185
|
+
const queue = topicEvent(topic, subscription);
|
|
186
|
+
await boss.createQueue(queue);
|
|
187
|
+
for (const type of messages) await boss.subscribe(topicEvent(topic, type), queue);
|
|
188
|
+
await boss.work(queue, work, async (jobs) => {
|
|
189
|
+
for (const job of jobs) {
|
|
190
|
+
const { data, carrier } = withoutTraceKey(job.data);
|
|
191
|
+
await consumeTraced({
|
|
192
|
+
system: "pgboss",
|
|
193
|
+
destination: topic,
|
|
194
|
+
type: data.type,
|
|
195
|
+
messageId: job.id
|
|
196
|
+
}, carrier, () => listener({
|
|
197
|
+
type: data.type,
|
|
198
|
+
payload: data.payload
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
62
204
|
for (const messageType of messages) {
|
|
63
205
|
await boss.createQueue(messageType);
|
|
64
|
-
await boss.work(messageType, {
|
|
65
|
-
...this.options.batchSize && { batchSize: this.options.batchSize },
|
|
66
|
-
...this.options.pollingIntervalSeconds && { pollingIntervalSeconds: this.options.pollingIntervalSeconds }
|
|
67
|
-
}, async (jobs) => {
|
|
206
|
+
await boss.work(messageType, work, async (jobs) => {
|
|
68
207
|
for (const job of jobs) {
|
|
69
|
-
const
|
|
208
|
+
const { data, carrier } = withoutTraceKey(job.data);
|
|
209
|
+
await consumeTraced({
|
|
210
|
+
system: "pgboss",
|
|
211
|
+
destination: messageType,
|
|
70
212
|
type: job.name,
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
213
|
+
messageId: job.id
|
|
214
|
+
}, carrier, () => listener({
|
|
215
|
+
type: job.name,
|
|
216
|
+
payload: data
|
|
217
|
+
}));
|
|
74
218
|
}
|
|
75
219
|
});
|
|
76
220
|
}
|
|
77
221
|
}
|
|
78
222
|
};
|
|
79
|
-
|
|
80
223
|
//#endregion
|
|
81
|
-
|
|
224
|
+
//#region src/pgboss/driver.ts
|
|
225
|
+
/**
|
|
226
|
+
* `pgboss://` — queues and topics in Postgres. Register it with
|
|
227
|
+
* `registerEventsDriver(pgbossEventsDriver)`; this subpath is the only one
|
|
228
|
+
* that imports `pg-boss`.
|
|
229
|
+
*/
|
|
230
|
+
const pgbossEventsDriver = {
|
|
231
|
+
scheme: "pgboss",
|
|
232
|
+
connect: (url) => PgBossConnection.fromConnectionString(url),
|
|
233
|
+
publisher: (url, options) => PgBossPublisher.fromConnectionString(url, options),
|
|
234
|
+
publisherFor: (connection, options) => new PgBossPublisher(connection, options),
|
|
235
|
+
subscriber: (url) => PgBossSubscriber.fromConnectionString(url),
|
|
236
|
+
subscriberFor: (connection, options) => new PgBossSubscriber(connection, options)
|
|
237
|
+
};
|
|
238
|
+
//#endregion
|
|
239
|
+
export { PgBossConnection, PgBossNotStarted, PgBossPublisher, PgBossSubscriber, PgBossSubscriptionNeedsName, pgbossEventsDriver, topicEvent };
|
|
240
|
+
|
|
82
241
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["connection: PgBossConnection","connectionString: string","messages: TMessage[]","connection: PgBossConnection","options: PgBossSubscriberOptions","connectionString: string","messages: TMessage['type'][]","listener: (payload: TMessage) => Promise<void>"],"sources":["../../src/pgboss/PgBossPublisher.ts","../../src/pgboss/PgBossSubscriber.ts"],"sourcesContent":["import type { EventPublisher, PublishableMessage } from '../types';\nimport type { PgBossConnection } from './PgBossConnection';\n\nexport class PgBossPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(private connection: PgBossConnection) {}\n\n\t/**\n\t * Create a PgBossPublisher from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<PgBossPublisher<TMessage>> {\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\t\treturn new PgBossPublisher<TMessage>(connection);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new Error('PgBoss instance not initialized');\n\t\t}\n\n\t\t// Group jobs by queue name (v11+ requires per-queue insert calls)\n\t\tconst groups = new Map<string, { data: TMessage['payload'] }[]>();\n\t\tfor (const m of messages) {\n\t\t\tconst list = groups.get(m.type) ?? [];\n\t\t\tlist.push({ data: m.payload });\n\t\t\tgroups.set(m.type, list);\n\t\t}\n\n\t\tfor (const [name, jobs] of groups) {\n\t\t\tawait boss.createQueue(name);\n\t\t\tawait boss.insert(name, jobs);\n\t\t}\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t}\n}\n","import type { EventSubscriber, PublishableMessage } from '../types';\nimport type { PgBossConnection } from './PgBossConnection';\n\nexport interface PgBossSubscriberOptions {\n\tbatchSize?: number;\n\tpollingIntervalSeconds?: number;\n}\n\nexport class PgBossSubscriber<TMessage extends PublishableMessage<string, any>>\n\timplements EventSubscriber<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: PgBossConnection,\n\t\tprivate options: PgBossSubscriberOptions = {},\n\t) {}\n\n\t/**\n\t * Create a PgBossSubscriber from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss&batchSize=5\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<PgBossSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\n\t\tconst options: PgBossSubscriberOptions = {\n\t\t\tbatchSize: params.get('batchSize')\n\t\t\t\t? Number.parseInt(params.get('batchSize')!, 10)\n\t\t\t\t: undefined,\n\t\t\tpollingIntervalSeconds: params.get('pollingIntervalSeconds')\n\t\t\t\t? Number.parseInt(params.get('pollingIntervalSeconds')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new PgBossSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new Error('PgBoss instance not initialized');\n\t\t}\n\n\t\tfor (const messageType of messages) {\n\t\t\tawait boss.createQueue(messageType);\n\t\t\tawait boss.work(\n\t\t\t\tmessageType,\n\t\t\t\t{\n\t\t\t\t\t...(this.options.batchSize && {\n\t\t\t\t\t\tbatchSize: this.options.batchSize,\n\t\t\t\t\t}),\n\t\t\t\t\t...(this.options.pollingIntervalSeconds && {\n\t\t\t\t\t\tpollingIntervalSeconds: this.options.pollingIntervalSeconds,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t\tasync (jobs) => {\n\t\t\t\t\tfor (const job of jobs) {\n\t\t\t\t\t\tconst fullMessage = {\n\t\t\t\t\t\t\ttype: job.name,\n\t\t\t\t\t\t\tpayload: job.data,\n\t\t\t\t\t\t} as TMessage;\n\n\t\t\t\t\t\tawait listener(fullMessage);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t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D;AAED,SAAO,IAAI,iBAA2B,YAAY;CAClD;CAED,MAAM,UACLE,UACAC,UACgB;AAChB,OAAK,KAAK,WAAW,aAAa,CACjC,OAAM,KAAK,WAAW,SAAS;EAGhC,MAAM,OAAO,KAAK,WAAW;AAC7B,OAAK,KACJ,OAAM,IAAI,MAAM;AAGjB,OAAK,MAAM,eAAe,UAAU;AACnC,SAAM,KAAK,YAAY,YAAY;AACnC,SAAM,KAAK,KACV,aACA;IACC,GAAI,KAAK,QAAQ,aAAa,EAC7B,WAAW,KAAK,QAAQ,UACxB;IACD,GAAI,KAAK,QAAQ,0BAA0B,EAC1C,wBAAwB,KAAK,QAAQ,uBACrC;GACD,GACD,OAAO,SAAS;AACf,SAAK,MAAM,OAAO,MAAM;KACvB,MAAM,cAAc;MACnB,MAAM,IAAI;MACV,SAAS,IAAI;KACb;AAED,WAAM,SAAS,YAAY;IAC3B;GACD,EACD;EACD;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/pgboss/PgBossConnection.ts","../../src/pgboss/errors.ts","../../src/pgboss/PgBossPublisher.ts","../../src/pgboss/PgBossSubscriber.ts","../../src/pgboss/driver.ts"],"sourcesContent":["import { PgBoss } from 'pg-boss';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport interface PgBossConnectionConfig {\n\tconnectionString: string;\n\tschema?: string;\n\t/**\n\t * Who this connection is to Postgres. Defaults to `GKM_APP_NAME`, which a\n\t * generated entry sets to the construct it runs — so the broker's\n\t * connections are named for the process that holds them, as its database\n\t * pools are, rather than all being `pgboss`.\n\t */\n\tapplicationName?: string;\n}\n\nexport class PgBossConnection implements EventConnection {\n\treadonly type = EventPublisherType.PgBoss;\n\tprivate boss?: PgBoss;\n\tprivate connecting?: Promise<void>;\n\n\tconstructor(private config: PgBossConnectionConfig) {}\n\n\t/**\n\t * Create a PgBossConnection from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<PgBossConnection> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst postgresUrl = `postgres://${url.username ? `${url.username}:${url.password}@` : ''}${url.host}${url.pathname}`;\n\n\t\tconst config: PgBossConnectionConfig = {\n\t\t\tconnectionString: postgresUrl,\n\t\t\tschema: params.get('schema') || undefined,\n\t\t};\n\n\t\tconst connection = new PgBossConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.boss) return;\n\n\t\tif (this.connecting) {\n\t\t\tawait this.connecting;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.connecting = (async () => {\n\t\t\ttry {\n\t\t\t\tconst applicationName =\n\t\t\t\t\tthis.config.applicationName ?? process.env.GKM_APP_NAME;\n\t\t\t\tconst boss = new PgBoss({\n\t\t\t\t\tconnectionString: this.config.connectionString,\n\t\t\t\t\t...(this.config.schema && { schema: this.config.schema }),\n\t\t\t\t\t...(applicationName && { application_name: applicationName }),\n\t\t\t\t});\n\n\t\t\t\tawait boss.start();\n\t\t\t\tthis.boss = boss;\n\t\t\t} catch (error) {\n\t\t\t\tthis.cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})();\n\n\t\tawait this.connecting;\n\t\tthis.connecting = undefined;\n\t}\n\n\tasync close(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.boss?.stop({ graceful: true });\n\t\t} catch {\n\t\t\t// Ignore errors during close\n\t\t} finally {\n\t\t\tthis.cleanup();\n\t\t}\n\t}\n\n\tisConnected(): boolean {\n\t\treturn !!this.boss;\n\t}\n\n\tprivate cleanup(): void {\n\t\tthis.boss = undefined;\n\t\tthis.connecting = undefined;\n\t}\n\n\t/**\n\t * Get the underlying pg-boss instance for publishing/subscribing\n\t */\n\tget instance(): PgBoss | undefined {\n\t\treturn this.boss;\n\t}\n}\n","// Beside the adapter but apart from its connection module, which imports\n// the broker's client: the publisher and subscriber load that lazily, and\n// importing an error class from it would load it eagerly.\n\n/** pg-boss connected but its instance never started. */\nexport class PgBossNotStarted extends Error {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'pg-boss did not start. Check the database in the connection string is reachable and the role may create the pg-boss schema.',\n\t\t);\n\t\tthis.name = 'PgBossNotStarted';\n\t}\n}\n\n/** A topic subscription with no name to give the subscriber's own queue. */\nexport class PgBossSubscriptionNeedsName extends Error {\n\tconstructor(readonly topic: string) {\n\t\tsuper(\n\t\t\t`Subscribing to topic '${topic}' on pg-boss needs a subscription name: ` +\n\t\t\t\t'each subscriber drains a queue of its own, and that queue is named ' +\n\t\t\t\t'for it. Pass `subscription`.',\n\t\t);\n\t\tthis.name = 'PgBossSubscriptionNeedsName';\n\t}\n}\n","import { publishTraced, withTraceKey } from '../telemetry';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport { PgBossNotStarted } from './errors';\nimport type { PgBossConnection } from './PgBossConnection';\n\nexport interface PgBossPublisherOptions {\n\t/**\n\t * Publishing to a topic: each message is fanned out to every subscriber's\n\t * own queue rather than inserted into one shared queue. Without it, a\n\t * message goes to the queue named by its type — a work queue, one consumer.\n\t */\n\ttopic?: string;\n}\n\n/** The pg-boss event a topic's message type is published as. */\nexport function topicEvent(topic: string, type: string): string {\n\treturn `${topic}/${type}`;\n}\n\nexport class PgBossPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: PgBossConnection,\n\t\tprivate options: PgBossPublisherOptions = {},\n\t) {}\n\n\t/**\n\t * Create a PgBossPublisher from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(\n\t\tconnectionString: string,\n\t\toptions: PgBossPublisherOptions = {},\n\t): Promise<PgBossPublisher<TMessage>> {\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\t\treturn new PgBossPublisher<TMessage>(connection, options);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new PgBossNotStarted();\n\t\t}\n\n\t\t// A topic: pg-boss copies the job into every queue subscribed to the\n\t\t// event — one per subscriber — so each subscriber sees each message.\n\t\t// The type rides in the data, because the job is named for the queue.\n\t\t//\n\t\t// pg-boss has no header field, so the trace context rides in the data\n\t\t// too, under a reserved key the subscriber removes before the handler.\n\t\tconst { topic } = this.options;\n\t\tif (topic) {\n\t\t\tawait publishTraced(\n\t\t\t\tmessages,\n\t\t\t\t(m) => ({ system: 'pgboss', destination: topic, type: m.type }),\n\t\t\t\tasync (carriers) => {\n\t\t\t\t\tfor (const [i, m] of messages.entries()) {\n\t\t\t\t\t\tawait boss.publish(\n\t\t\t\t\t\t\ttopicEvent(topic, m.type),\n\t\t\t\t\t\t\twithTraceKey({ type: m.type, payload: m.payload }, carriers[i]),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tawait publishTraced(\n\t\t\tmessages,\n\t\t\t(m) => ({ system: 'pgboss', destination: m.type, type: m.type }),\n\t\t\tasync (carriers) => {\n\t\t\t\t// Group jobs by queue name (v11+ requires per-queue insert calls)\n\t\t\t\tconst groups = new Map<string, { data: TMessage['payload'] }[]>();\n\t\t\t\tfor (const [i, m] of messages.entries()) {\n\t\t\t\t\tconst list = groups.get(m.type) ?? [];\n\t\t\t\t\tlist.push({ data: withTraceKey(m.payload, carriers[i]) });\n\t\t\t\t\tgroups.set(m.type, list);\n\t\t\t\t}\n\n\t\t\t\tfor (const [name, jobs] of groups) {\n\t\t\t\t\tawait boss.createQueue(name);\n\t\t\t\t\tawait boss.insert(name, jobs);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t}\n}\n","import { consumeTraced, withoutTraceKey } from '../telemetry';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport { PgBossNotStarted, PgBossSubscriptionNeedsName } from './errors';\nimport type { PgBossConnection } from './PgBossConnection';\nimport { topicEvent } from './PgBossPublisher';\n\nexport interface PgBossSubscriberOptions {\n\tbatchSize?: number;\n\tpollingIntervalSeconds?: number;\n\t/**\n\t * Subscribing to a topic. Each subscriber then drains a queue of its own,\n\t * `<topic>/<subscription>`, bound to the events it names — so every\n\t * subscriber sees every message, and replicas of one subscriber share it.\n\t * Without it, messages are drained from the queue named by their type:\n\t * work shared among whoever drains it.\n\t */\n\ttopic?: string;\n\t/** The subscriber's own name on the topic. Required with `topic`. */\n\tsubscription?: string;\n}\n\nexport class PgBossSubscriber<TMessage extends PublishableMessage<string, any>>\n\timplements EventSubscriber<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: PgBossConnection,\n\t\tprivate options: PgBossSubscriberOptions = {},\n\t) {}\n\n\t/**\n\t * Create a PgBossSubscriber from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss&batchSize=5\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<PgBossSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\n\t\tconst options: PgBossSubscriberOptions = {\n\t\t\tbatchSize: params.get('batchSize')\n\t\t\t\t? Number.parseInt(params.get('batchSize')!, 10)\n\t\t\t\t: undefined,\n\t\t\tpollingIntervalSeconds: params.get('pollingIntervalSeconds')\n\t\t\t\t? Number.parseInt(params.get('pollingIntervalSeconds')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new PgBossSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new PgBossNotStarted();\n\t\t}\n\n\t\tconst work = {\n\t\t\t...(this.options.batchSize && { batchSize: this.options.batchSize }),\n\t\t\t...(this.options.pollingIntervalSeconds && {\n\t\t\t\tpollingIntervalSeconds: this.options.pollingIntervalSeconds,\n\t\t\t}),\n\t\t};\n\n\t\tconst { topic, subscription } = this.options;\n\t\tif (topic) {\n\t\t\tif (!subscription) throw new PgBossSubscriptionNeedsName(topic);\n\n\t\t\tconst queue = topicEvent(topic, subscription);\n\t\t\tawait boss.createQueue(queue);\n\t\t\tfor (const type of messages) {\n\t\t\t\tawait boss.subscribe(topicEvent(topic, type), queue);\n\t\t\t}\n\t\t\tawait boss.work<{ type: string; payload: unknown }>(\n\t\t\t\tqueue,\n\t\t\t\twork,\n\t\t\t\tasync (jobs) => {\n\t\t\t\t\tfor (const job of jobs) {\n\t\t\t\t\t\tconst { data, carrier } = withoutTraceKey(job.data);\n\t\t\t\t\t\tawait consumeTraced(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tsystem: 'pgboss',\n\t\t\t\t\t\t\t\tdestination: topic,\n\t\t\t\t\t\t\t\ttype: data.type,\n\t\t\t\t\t\t\t\tmessageId: job.id,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcarrier,\n\t\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\t\tlistener({\n\t\t\t\t\t\t\t\t\ttype: data.type,\n\t\t\t\t\t\t\t\t\tpayload: data.payload,\n\t\t\t\t\t\t\t\t} as TMessage),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const messageType of messages) {\n\t\t\tawait boss.createQueue(messageType);\n\t\t\tawait boss.work(messageType, work, async (jobs) => {\n\t\t\t\tfor (const job of jobs) {\n\t\t\t\t\t// The trace context is taken out of the data here, so the\n\t\t\t\t\t// handler's payload is exactly what was published.\n\t\t\t\t\tconst { data, carrier } = withoutTraceKey(job.data);\n\t\t\t\t\tawait consumeTraced(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsystem: 'pgboss',\n\t\t\t\t\t\t\tdestination: messageType,\n\t\t\t\t\t\t\ttype: job.name,\n\t\t\t\t\t\t\tmessageId: job.id,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcarrier,\n\t\t\t\t\t\t() => listener({ type: job.name, payload: data } as TMessage),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n}\n","import type { EventsDriver } from '../registry';\nimport { EventPublisherType } from '../types';\nimport { PgBossConnection } from './PgBossConnection';\nimport { PgBossPublisher } from './PgBossPublisher';\nimport { PgBossSubscriber } from './PgBossSubscriber';\n\n/**\n * `pgboss://` — queues and topics in Postgres. Register it with\n * `registerEventsDriver(pgbossEventsDriver)`; this subpath is the only one\n * that imports `pg-boss`.\n */\nexport const pgbossEventsDriver: EventsDriver = {\n\tscheme: EventPublisherType.PgBoss,\n\tconnect: (url) => PgBossConnection.fromConnectionString(url),\n\tpublisher: (url, options) =>\n\t\tPgBossPublisher.fromConnectionString(url, options),\n\tpublisherFor: (connection, options) =>\n\t\tnew PgBossPublisher(connection as PgBossConnection, options),\n\tsubscriber: (url) => PgBossSubscriber.fromConnectionString(url),\n\tsubscriberFor: (connection, options) =>\n\t\tnew PgBossSubscriber(connection as PgBossConnection, options),\n};\n"],"mappings":";;;;;AAgBA,IAAa,mBAAb,MAAa,iBAA4C;CAKpC;CAJpB,OAAS;CACT;CACA;CAEA,YAAY,QAAwC;EAAhC,KAAA,SAAA;CAAiC;;;;;CAM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AAI,iBAAiB,YAAgC,OAAO;AAC9D"}
|
package/dist/rabbitmq/index.cjs
CHANGED
|
@@ -1,8 +1,123 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("../rolldown-runtime-C0BPl7ul.cjs");
|
|
3
|
+
const require_telemetry = require("../telemetry-DG3l807O.cjs");
|
|
4
|
+
let amqplib = require("amqplib");
|
|
5
|
+
amqplib = require_rolldown_runtime.__toESM(amqplib, 1);
|
|
6
|
+
//#region src/rabbitmq/RabbitMQConnection.ts
|
|
7
|
+
var RabbitMQConnection_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ RabbitMQConnection: () => RabbitMQConnection });
|
|
8
|
+
var RabbitMQConnection = class RabbitMQConnection {
|
|
9
|
+
type = "rabbitmq";
|
|
10
|
+
connection;
|
|
11
|
+
channel;
|
|
12
|
+
connecting;
|
|
13
|
+
config;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.config = {
|
|
16
|
+
...config,
|
|
17
|
+
exchange: config.exchange || "geekmidas.events",
|
|
18
|
+
exchangeType: config.exchangeType || "topic",
|
|
19
|
+
timeout: config.timeout ?? 5e3,
|
|
20
|
+
exchangeOptions: {
|
|
21
|
+
durable: true,
|
|
22
|
+
...config.exchangeOptions
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a RabbitMQConnection from a connection string
|
|
28
|
+
* Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000
|
|
29
|
+
*/
|
|
30
|
+
static async fromConnectionString(connectionString) {
|
|
31
|
+
const url = new URL(connectionString);
|
|
32
|
+
const params = url.searchParams;
|
|
33
|
+
const baseUrl = `amqp://${url.username ? `${url.username}:${url.password}@` : ""}${url.host}${url.pathname}`;
|
|
34
|
+
const timeoutParam = params.get("timeout");
|
|
35
|
+
const config = {
|
|
36
|
+
url: baseUrl,
|
|
37
|
+
exchange: params.get("exchange") || "geekmidas.events",
|
|
38
|
+
exchangeType: params.get("type") || "topic",
|
|
39
|
+
timeout: timeoutParam ? Number.parseInt(timeoutParam, 10) : void 0
|
|
40
|
+
};
|
|
41
|
+
const connection = new RabbitMQConnection(config);
|
|
42
|
+
await connection.connect();
|
|
43
|
+
return connection;
|
|
44
|
+
}
|
|
45
|
+
async connect() {
|
|
46
|
+
if (this.channel) return;
|
|
47
|
+
if (this.connecting) {
|
|
48
|
+
await this.connecting;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.connecting = (async () => {
|
|
52
|
+
try {
|
|
53
|
+
const connection = await amqplib.default.connect(this.config.url, { timeout: this.config.timeout });
|
|
54
|
+
const channel = await connection.createChannel();
|
|
55
|
+
await channel.assertExchange(this.config.exchange, this.config.exchangeType, this.config.exchangeOptions);
|
|
56
|
+
connection.on("error", (_err) => {
|
|
57
|
+
this.cleanup();
|
|
58
|
+
});
|
|
59
|
+
connection.on("close", () => {
|
|
60
|
+
this.cleanup();
|
|
61
|
+
});
|
|
62
|
+
this.connection = connection;
|
|
63
|
+
this.channel = channel;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
this.cleanup();
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
69
|
+
await this.connecting;
|
|
70
|
+
this.connecting = void 0;
|
|
71
|
+
}
|
|
72
|
+
async close() {
|
|
73
|
+
try {
|
|
74
|
+
await this.channel?.close();
|
|
75
|
+
await this.connection?.close();
|
|
76
|
+
} catch (_error) {} finally {
|
|
77
|
+
this.cleanup();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
isConnected() {
|
|
81
|
+
return !!this.channel;
|
|
82
|
+
}
|
|
83
|
+
cleanup() {
|
|
84
|
+
this.channel = void 0;
|
|
85
|
+
this.connection = void 0;
|
|
86
|
+
this.connecting = void 0;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the underlying channel for publishing/subscribing
|
|
90
|
+
*/
|
|
91
|
+
get amqpChannel() {
|
|
92
|
+
return this.channel;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the exchange name for this connection
|
|
96
|
+
*/
|
|
97
|
+
get exchangeName() {
|
|
98
|
+
return this.config.exchange;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the exchange type for this connection
|
|
102
|
+
*/
|
|
103
|
+
get exchangeType() {
|
|
104
|
+
return this.config.exchangeType;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/rabbitmq/errors.ts
|
|
109
|
+
/** The connection opened but has no channel to publish or consume on. */
|
|
110
|
+
var RabbitMQChannelUnavailable = class extends Error {
|
|
111
|
+
constructor() {
|
|
112
|
+
super("RabbitMQ connected without a channel. Check the broker is reachable and the connection string names a vhost the user can open channels on.");
|
|
113
|
+
this.name = "RabbitMQChannelUnavailable";
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
//#endregion
|
|
4
117
|
//#region src/rabbitmq/RabbitMQPublisher.ts
|
|
5
118
|
var RabbitMQPublisher = class RabbitMQPublisher {
|
|
119
|
+
connection;
|
|
120
|
+
options;
|
|
6
121
|
constructor(connection, options = {}) {
|
|
7
122
|
this.connection = connection;
|
|
8
123
|
this.options = options;
|
|
@@ -12,34 +127,44 @@ var RabbitMQPublisher = class RabbitMQPublisher {
|
|
|
12
127
|
* Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000
|
|
13
128
|
*/
|
|
14
129
|
static async fromConnectionString(connectionString) {
|
|
15
|
-
const { RabbitMQConnection
|
|
16
|
-
const connection = await RabbitMQConnection
|
|
130
|
+
const { RabbitMQConnection } = await Promise.resolve().then(() => RabbitMQConnection_exports);
|
|
131
|
+
const connection = await RabbitMQConnection.fromConnectionString(connectionString);
|
|
17
132
|
return new RabbitMQPublisher(connection);
|
|
18
133
|
}
|
|
19
134
|
async publish(messages) {
|
|
20
135
|
if (!this.connection.isConnected()) await this.connection.connect();
|
|
21
136
|
const channel = this.connection.amqpChannel;
|
|
22
|
-
if (!channel) throw new
|
|
137
|
+
if (!channel) throw new RabbitMQChannelUnavailable();
|
|
23
138
|
const exchange = this.connection.exchangeName;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
139
|
+
await require_telemetry.publishTraced(messages, (message) => ({
|
|
140
|
+
system: "rabbitmq",
|
|
141
|
+
destination: exchange,
|
|
142
|
+
type: message.type
|
|
143
|
+
}), async (carriers) => {
|
|
144
|
+
for (const [i, message] of messages.entries()) {
|
|
145
|
+
const content = Buffer.from(JSON.stringify(message.payload));
|
|
146
|
+
const { headers, ...publishOptions } = this.options.publishOptions ?? {};
|
|
147
|
+
if (!channel.publish(exchange, message.type, content, {
|
|
148
|
+
contentType: "application/json",
|
|
149
|
+
timestamp: Date.now(),
|
|
150
|
+
type: message.type,
|
|
151
|
+
persistent: true,
|
|
152
|
+
...publishOptions,
|
|
153
|
+
...(headers || carriers[i]) && { headers: {
|
|
154
|
+
...headers,
|
|
155
|
+
...carriers[i]
|
|
156
|
+
} }
|
|
157
|
+
})) await new Promise((resolve) => channel.once("drain", resolve));
|
|
158
|
+
}
|
|
159
|
+
});
|
|
36
160
|
}
|
|
37
161
|
async close() {}
|
|
38
162
|
};
|
|
39
|
-
|
|
40
163
|
//#endregion
|
|
41
164
|
//#region src/rabbitmq/RabbitMQSubscriber.ts
|
|
42
165
|
var RabbitMQSubscriber = class RabbitMQSubscriber {
|
|
166
|
+
connection;
|
|
167
|
+
options;
|
|
43
168
|
constructor(connection, options = {}) {
|
|
44
169
|
this.connection = connection;
|
|
45
170
|
this.options = options;
|
|
@@ -49,10 +174,9 @@ var RabbitMQSubscriber = class RabbitMQSubscriber {
|
|
|
49
174
|
* Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&queueName=myqueue&prefetch=10
|
|
50
175
|
*/
|
|
51
176
|
static async fromConnectionString(connectionString) {
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const connection = await RabbitMQConnection$1.fromConnectionString(connectionString);
|
|
177
|
+
const params = new URL(connectionString).searchParams;
|
|
178
|
+
const { RabbitMQConnection } = await Promise.resolve().then(() => RabbitMQConnection_exports);
|
|
179
|
+
const connection = await RabbitMQConnection.fromConnectionString(connectionString);
|
|
56
180
|
const options = {
|
|
57
181
|
queueName: params.get("queueName") || void 0,
|
|
58
182
|
prefetch: params.get("prefetch") ? Number.parseInt(params.get("prefetch"), 10) : void 0
|
|
@@ -62,7 +186,7 @@ var RabbitMQSubscriber = class RabbitMQSubscriber {
|
|
|
62
186
|
async subscribe(messages, listener) {
|
|
63
187
|
if (!this.connection.isConnected()) await this.connection.connect();
|
|
64
188
|
const channel = this.connection.amqpChannel;
|
|
65
|
-
if (!channel) throw new
|
|
189
|
+
if (!channel) throw new RabbitMQChannelUnavailable();
|
|
66
190
|
const exchange = this.connection.exchangeName;
|
|
67
191
|
if (this.options.prefetch) await channel.prefetch(this.options.prefetch);
|
|
68
192
|
const queueName = this.options.queueName || "";
|
|
@@ -82,7 +206,12 @@ var RabbitMQSubscriber = class RabbitMQSubscriber {
|
|
|
82
206
|
type: messageType,
|
|
83
207
|
payload
|
|
84
208
|
};
|
|
85
|
-
await
|
|
209
|
+
await require_telemetry.consumeTraced({
|
|
210
|
+
system: "rabbitmq",
|
|
211
|
+
destination: queue,
|
|
212
|
+
type: messageType,
|
|
213
|
+
messageId: msg.properties.messageId
|
|
214
|
+
}, require_telemetry.carrierFromAttributes(msg.properties.headers), () => listener(fullMessage));
|
|
86
215
|
channel.ack(msg);
|
|
87
216
|
} catch (_error) {
|
|
88
217
|
channel.nack(msg, false, true);
|
|
@@ -90,9 +219,26 @@ var RabbitMQSubscriber = class RabbitMQSubscriber {
|
|
|
90
219
|
}, this.options.consumeOptions);
|
|
91
220
|
}
|
|
92
221
|
};
|
|
93
|
-
|
|
94
222
|
//#endregion
|
|
95
|
-
|
|
223
|
+
//#region src/rabbitmq/driver.ts
|
|
224
|
+
/**
|
|
225
|
+
* `rabbitmq://` — an AMQP exchange. Register it with
|
|
226
|
+
* `registerEventsDriver(rabbitmqEventsDriver)`; this subpath is the only one
|
|
227
|
+
* that imports `amqplib`.
|
|
228
|
+
*/
|
|
229
|
+
const rabbitmqEventsDriver = {
|
|
230
|
+
scheme: "rabbitmq",
|
|
231
|
+
connect: (url) => RabbitMQConnection.fromConnectionString(url),
|
|
232
|
+
publisher: (url) => RabbitMQPublisher.fromConnectionString(url),
|
|
233
|
+
publisherFor: (connection) => new RabbitMQPublisher(connection),
|
|
234
|
+
subscriber: (url) => RabbitMQSubscriber.fromConnectionString(url),
|
|
235
|
+
subscriberFor: (connection) => new RabbitMQSubscriber(connection)
|
|
236
|
+
};
|
|
237
|
+
//#endregion
|
|
238
|
+
exports.RabbitMQChannelUnavailable = RabbitMQChannelUnavailable;
|
|
239
|
+
exports.RabbitMQConnection = RabbitMQConnection;
|
|
96
240
|
exports.RabbitMQPublisher = RabbitMQPublisher;
|
|
97
241
|
exports.RabbitMQSubscriber = RabbitMQSubscriber;
|
|
242
|
+
exports.rabbitmqEventsDriver = rabbitmqEventsDriver;
|
|
243
|
+
|
|
98
244
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["connection: RabbitMQConnection","options: RabbitMQPublisherOptions","connectionString: string","messages: TMessage[]","connection: RabbitMQConnection","options: RabbitMQSubscriberOptions","connectionString: string","messages: TMessage['type'][]","listener: (payload: TMessage) => Promise<void>","queueOptions: amqplib.Options.AssertQueue","fullMessage: TMessage"],"sources":["../../src/rabbitmq/RabbitMQPublisher.ts","../../src/rabbitmq/RabbitMQSubscriber.ts"],"sourcesContent":["import type amqplib from 'amqplib';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport type { RabbitMQConnection } from './RabbitMQConnection';\n\nexport interface RabbitMQPublisherOptions {\n\tpublishOptions?: amqplib.Options.Publish;\n}\n\nexport class RabbitMQPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: RabbitMQConnection,\n\t\tprivate options: RabbitMQPublisherOptions = {},\n\t) {}\n\n\t/**\n\t * Create a RabbitMQPublisher from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<RabbitMQPublisher<TMessage>> {\n\t\tconst { RabbitMQConnection } = await import('./RabbitMQConnection');\n\t\tconst connection =\n\t\t\tawait RabbitMQConnection.fromConnectionString(connectionString);\n\t\treturn new RabbitMQPublisher<TMessage>(connection);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst channel = this.connection.amqpChannel;\n\t\tif (!channel) {\n\t\t\tthrow new Error('Channel not initialized');\n\t\t}\n\n\t\tconst exchange = this.connection.exchangeName;\n\n\t\tfor (const message of messages) {\n\t\t\tconst content = Buffer.from(JSON.stringify(message.payload));\n\n\t\t\t// Use message type as routing key for topic exchanges\n\t\t\tconst routingKey = message.type;\n\n\t\t\tconst published = channel.publish(exchange, routingKey, content, {\n\t\t\t\tcontentType: 'application/json',\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t\ttype: message.type,\n\t\t\t\tpersistent: true,\n\t\t\t\t...this.options.publishOptions,\n\t\t\t});\n\n\t\t\t// Handle backpressure\n\t\t\tif (!published) {\n\t\t\t\tawait new Promise((resolve) => channel.once('drain', resolve));\n\t\t\t}\n\t\t}\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t\t// Connection should be closed by whoever created it\n\t}\n}\n","import type amqplib from 'amqplib';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport type { RabbitMQConnection } from './RabbitMQConnection';\n\nexport interface RabbitMQSubscriberOptions {\n\tqueueName?: string; // If not provided, a unique queue will be generated\n\tqueueOptions?: amqplib.Options.AssertQueue;\n\tconsumeOptions?: amqplib.Options.Consume;\n\tprefetch?: number; // Number of messages to prefetch (default: 1)\n}\n\nexport class RabbitMQSubscriber<\n\tTMessage extends PublishableMessage<string, any>,\n> implements EventSubscriber<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: RabbitMQConnection,\n\t\tprivate options: RabbitMQSubscriberOptions = {},\n\t) {}\n\n\t/**\n\t * Create a RabbitMQSubscriber from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&queueName=myqueue&prefetch=10\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<RabbitMQSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { RabbitMQConnection } = await import('./RabbitMQConnection');\n\t\tconst connection =\n\t\t\tawait RabbitMQConnection.fromConnectionString(connectionString);\n\n\t\tconst options: RabbitMQSubscriberOptions = {\n\t\t\tqueueName: params.get('queueName') || undefined,\n\t\t\tprefetch: params.get('prefetch')\n\t\t\t\t? Number.parseInt(params.get('prefetch')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new RabbitMQSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst channel = this.connection.amqpChannel;\n\t\tif (!channel) {\n\t\t\tthrow new Error('Channel not initialized');\n\t\t}\n\n\t\tconst exchange = this.connection.exchangeName;\n\n\t\t// Set prefetch if specified\n\t\tif (this.options.prefetch) {\n\t\t\tawait channel.prefetch(this.options.prefetch);\n\t\t}\n\n\t\t// Assert queue\n\t\tconst queueName = this.options.queueName || '';\n\t\tconst queueOptions: amqplib.Options.AssertQueue = {\n\t\t\tdurable: true,\n\t\t\t...this.options.queueOptions,\n\t\t};\n\n\t\tconst { queue } = await channel.assertQueue(queueName, queueOptions);\n\n\t\t// Bind queue to exchange for each message type\n\t\tfor (const messageType of messages) {\n\t\t\tawait channel.bindQueue(queue, exchange, messageType);\n\t\t}\n\n\t\t// Consume messages\n\t\tawait channel.consume(\n\t\t\tqueue,\n\t\t\tasync (msg) => {\n\t\t\t\tif (!msg) return;\n\n\t\t\t\ttry {\n\t\t\t\t\t// Parse message payload\n\t\t\t\t\tconst content = msg.content.toString();\n\t\t\t\t\tconst payload = JSON.parse(content);\n\n\t\t\t\t\t// Get message type from properties\n\t\t\t\t\tconst messageType = msg.properties.type;\n\n\t\t\t\t\t// Reconstruct full message\n\t\t\t\t\tconst fullMessage: TMessage = {\n\t\t\t\t\t\ttype: messageType,\n\t\t\t\t\t\tpayload,\n\t\t\t\t\t} as TMessage;\n\n\t\t\t\t\t// Call listener\n\t\t\t\t\tawait listener(fullMessage);\n\n\t\t\t\t\t// Ack message\n\t\t\t\t\tchannel.ack(msg);\n\t\t\t\t} catch (_error) {\n\t\t\t\t\tchannel.nack(msg, false, true);\n\t\t\t\t}\n\t\t\t},\n\t\t\tthis.options.consumeOptions,\n\t\t);\n\t}\n}\n"],"mappings":";;;;AAQA,IAAa,oBAAb,MAAa,kBAEb;CACC,YACSA,YACAC,UAAoC,CAAE,GAC7C;EAFO;EACA;CACL;;;;;CAMJ,aAAa,qBAEXC,kBAAgE;EACjE,MAAM,EAAE,0CAAoB,GAAG,2CAAM;EACrC,MAAM,aACL,MAAM,qBAAmB,qBAAqB,iBAAiB;AAChE,SAAO,IAAI,kBAA4B;CACvC;CAED,MA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ChB,OAAM,QAAQ,SAAS,KAAK,QAAQ,SAAS;EAI9C,MAAM,YAAY,KAAK,QAAQ,aAAa;EAC5C,MAAMC,eAA4C;GACjD,SAAS;GACT,GAAG,KAAK,QAAQ;EAChB;EAED,MAAM,EAAE,OAAO,GAAG,MAAM,QAAQ,YAAY,WAAW,aAAa;AAGpE,OAAK,MAAM,eAAe,SACzB,OAAM,QAAQ,UAAU,OAAO,UAAU,YAAY;AAItD,QAAM,QAAQ,QACb,OACA,OAAO,QAAQ;AACd,QAAK,IAAK;AAEV,OAAI;IAEH,MAAM,UAAU,IAAI,QAAQ,UAAU;IACtC,MAAM,UAAU,KAAK,MAAM,QAAQ;IAGnC,MAAM,cAAc,IAAI,WAAW;IAGnC,MAAMC,cAAwB;KAC7B,MAAM;KACN;IACA;AAGD,UAAM,SAAS,YAAY;AAG3B,YAAQ,IAAI,IAAI;GAChB,SAAQ,QAAQ;AAChB,YAAQ,KAAK,KAAK,OAAO,KAAK;GAC9B;EACD,GACD,KAAK,QAAQ,eACb;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["publishTraced","consumeTraced","carrierFromAttributes"],"sources":["../../src/rabbitmq/RabbitMQConnection.ts","../../src/rabbitmq/errors.ts","../../src/rabbitmq/RabbitMQPublisher.ts","../../src/rabbitmq/RabbitMQSubscriber.ts","../../src/rabbitmq/driver.ts"],"sourcesContent":["import amqplib from 'amqplib';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport interface RabbitMQConnectionConfig {\n\turl: string;\n\texchange?: string;\n\texchangeType?: 'topic' | 'direct' | 'fanout' | 'headers';\n\texchangeOptions?: amqplib.Options.AssertExchange;\n\ttimeout?: number; // Connection timeout in milliseconds (default: 5000)\n}\n\nexport class RabbitMQConnection implements EventConnection {\n\treadonly type = EventPublisherType.RabbitMQ;\n\tprivate connection?: amqplib.ChannelModel;\n\tprivate channel?: amqplib.Channel;\n\tprivate connecting?: Promise<void>;\n\tprivate config: Required<\n\t\tPick<RabbitMQConnectionConfig, 'exchange' | 'exchangeType' | 'timeout'>\n\t> &\n\t\tRabbitMQConnectionConfig;\n\n\tconstructor(config: RabbitMQConnectionConfig) {\n\t\tthis.config = {\n\t\t\t...config,\n\t\t\texchange: config.exchange || 'geekmidas.events',\n\t\t\texchangeType: config.exchangeType || 'topic',\n\t\t\ttimeout: config.timeout ?? 5000,\n\t\t\texchangeOptions: {\n\t\t\t\tdurable: true,\n\t\t\t\t...config.exchangeOptions,\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Create a RabbitMQConnection from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<RabbitMQConnection> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\t// Extract connection URL without query params\n\t\tconst baseUrl = `amqp://${url.username ? `${url.username}:${url.password}@` : ''}${url.host}${url.pathname}`;\n\n\t\tconst timeoutParam = params.get('timeout');\n\t\tconst config: RabbitMQConnectionConfig = {\n\t\t\turl: baseUrl,\n\t\t\texchange: params.get('exchange') || 'geekmidas.events',\n\t\t\texchangeType: (params.get('type') as any) || 'topic',\n\t\t\ttimeout: timeoutParam ? Number.parseInt(timeoutParam, 10) : undefined,\n\t\t};\n\n\t\tconst connection = new RabbitMQConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.channel) return;\n\n\t\t// Prevent multiple simultaneous connection attempts\n\t\tif (this.connecting) {\n\t\t\tawait this.connecting;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.connecting = (async () => {\n\t\t\ttry {\n\t\t\t\tconst connection = await amqplib.connect(this.config.url, {\n\t\t\t\t\ttimeout: this.config.timeout,\n\t\t\t\t});\n\t\t\t\tconst channel = await connection.createChannel();\n\n\t\t\t\t// Assert the exchange exists\n\t\t\t\tawait channel.assertExchange(\n\t\t\t\t\tthis.config.exchange!,\n\t\t\t\t\tthis.config.exchangeType!,\n\t\t\t\t\tthis.config.exchangeOptions,\n\t\t\t\t);\n\n\t\t\t\t// Handle connection errors\n\t\t\t\tconnection.on('error', (_err: Error) => {\n\t\t\t\t\tthis.cleanup();\n\t\t\t\t});\n\n\t\t\t\tconnection.on('close', () => {\n\t\t\t\t\tthis.cleanup();\n\t\t\t\t});\n\n\t\t\t\t// Only set after successful setup\n\t\t\t\tthis.connection = connection;\n\t\t\t\tthis.channel = channel;\n\t\t\t} catch (error) {\n\t\t\t\tthis.cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})();\n\n\t\tawait this.connecting;\n\t\tthis.connecting = undefined;\n\t}\n\n\tasync close(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.channel?.close();\n\t\t\tawait this.connection?.close();\n\t\t} catch (_error) {\n\t\t\t// Ignore errors during close\n\t\t} finally {\n\t\t\tthis.cleanup();\n\t\t}\n\t}\n\n\tisConnected(): boolean {\n\t\treturn !!this.channel;\n\t}\n\n\tprivate cleanup(): void {\n\t\tthis.channel = undefined;\n\t\tthis.connection = undefined;\n\t\tthis.connecting = undefined;\n\t}\n\n\t/**\n\t * Get the underlying channel for publishing/subscribing\n\t */\n\tget amqpChannel(): amqplib.Channel | undefined {\n\t\treturn this.channel;\n\t}\n\n\t/**\n\t * Get the exchange name for this connection\n\t */\n\tget exchangeName(): string {\n\t\treturn this.config.exchange;\n\t}\n\n\t/**\n\t * Get the exchange type for this connection\n\t */\n\tget exchangeType(): string {\n\t\treturn this.config.exchangeType;\n\t}\n}\n","// Beside the adapter but apart from its connection module, which imports\n// the broker's client: the publisher and subscriber load that lazily, and\n// importing an error class from it would load it eagerly.\n\n/** The connection opened but has no channel to publish or consume on. */\nexport class RabbitMQChannelUnavailable extends Error {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'RabbitMQ connected without a channel. Check the broker is reachable and the connection string names a vhost the user can open channels on.',\n\t\t);\n\t\tthis.name = 'RabbitMQChannelUnavailable';\n\t}\n}\n","import type amqplib from 'amqplib';\nimport { publishTraced } from '../telemetry';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport { RabbitMQChannelUnavailable } from './errors';\nimport type { RabbitMQConnection } from './RabbitMQConnection';\n\nexport interface RabbitMQPublisherOptions {\n\tpublishOptions?: amqplib.Options.Publish;\n}\n\nexport class RabbitMQPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: RabbitMQConnection,\n\t\tprivate options: RabbitMQPublisherOptions = {},\n\t) {}\n\n\t/**\n\t * Create a RabbitMQPublisher from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<RabbitMQPublisher<TMessage>> {\n\t\tconst { RabbitMQConnection } = await import('./RabbitMQConnection');\n\t\tconst connection =\n\t\t\tawait RabbitMQConnection.fromConnectionString(connectionString);\n\t\treturn new RabbitMQPublisher<TMessage>(connection);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst channel = this.connection.amqpChannel;\n\t\tif (!channel) {\n\t\t\tthrow new RabbitMQChannelUnavailable();\n\t\t}\n\n\t\tconst exchange = this.connection.exchangeName;\n\n\t\tawait publishTraced(\n\t\t\tmessages,\n\t\t\t(message) => ({\n\t\t\t\tsystem: 'rabbitmq',\n\t\t\t\tdestination: exchange,\n\t\t\t\ttype: message.type,\n\t\t\t}),\n\t\t\tasync (carriers) => {\n\t\t\t\tfor (const [i, message] of messages.entries()) {\n\t\t\t\t\tconst content = Buffer.from(JSON.stringify(message.payload));\n\t\t\t\t\tconst { headers, ...publishOptions } =\n\t\t\t\t\t\tthis.options.publishOptions ?? {};\n\n\t\t\t\t\t// Use message type as routing key for topic exchanges; the trace\n\t\t\t\t\t// context goes in the message's headers.\n\t\t\t\t\tconst published = channel.publish(exchange, message.type, content, {\n\t\t\t\t\t\tcontentType: 'application/json',\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\ttype: message.type,\n\t\t\t\t\t\tpersistent: true,\n\t\t\t\t\t\t...publishOptions,\n\t\t\t\t\t\t...((headers || carriers[i]) && {\n\t\t\t\t\t\t\theaders: { ...headers, ...carriers[i] },\n\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\n\t\t\t\t\t// Handle backpressure\n\t\t\t\t\tif (!published) {\n\t\t\t\t\t\tawait new Promise((resolve) => channel.once('drain', resolve));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t\t// Connection should be closed by whoever created it\n\t}\n}\n","import type amqplib from 'amqplib';\nimport { carrierFromAttributes, consumeTraced } from '../telemetry';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport { RabbitMQChannelUnavailable } from './errors';\nimport type { RabbitMQConnection } from './RabbitMQConnection';\n\nexport interface RabbitMQSubscriberOptions {\n\tqueueName?: string; // If not provided, a unique queue will be generated\n\tqueueOptions?: amqplib.Options.AssertQueue;\n\tconsumeOptions?: amqplib.Options.Consume;\n\tprefetch?: number; // Number of messages to prefetch (default: 1)\n}\n\nexport class RabbitMQSubscriber<\n\tTMessage extends PublishableMessage<string, any>,\n> implements EventSubscriber<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: RabbitMQConnection,\n\t\tprivate options: RabbitMQSubscriberOptions = {},\n\t) {}\n\n\t/**\n\t * Create a RabbitMQSubscriber from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&queueName=myqueue&prefetch=10\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<RabbitMQSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { RabbitMQConnection } = await import('./RabbitMQConnection');\n\t\tconst connection =\n\t\t\tawait RabbitMQConnection.fromConnectionString(connectionString);\n\n\t\tconst options: RabbitMQSubscriberOptions = {\n\t\t\tqueueName: params.get('queueName') || undefined,\n\t\t\tprefetch: params.get('prefetch')\n\t\t\t\t? Number.parseInt(params.get('prefetch')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new RabbitMQSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst channel = this.connection.amqpChannel;\n\t\tif (!channel) {\n\t\t\tthrow new RabbitMQChannelUnavailable();\n\t\t}\n\n\t\tconst exchange = this.connection.exchangeName;\n\n\t\t// Set prefetch if specified\n\t\tif (this.options.prefetch) {\n\t\t\tawait channel.prefetch(this.options.prefetch);\n\t\t}\n\n\t\t// Assert queue\n\t\tconst queueName = this.options.queueName || '';\n\t\tconst queueOptions: amqplib.Options.AssertQueue = {\n\t\t\tdurable: true,\n\t\t\t...this.options.queueOptions,\n\t\t};\n\n\t\tconst { queue } = await channel.assertQueue(queueName, queueOptions);\n\n\t\t// Bind queue to exchange for each message type\n\t\tfor (const messageType of messages) {\n\t\t\tawait channel.bindQueue(queue, exchange, messageType);\n\t\t}\n\n\t\t// Consume messages\n\t\tawait channel.consume(\n\t\t\tqueue,\n\t\t\tasync (msg) => {\n\t\t\t\tif (!msg) return;\n\n\t\t\t\ttry {\n\t\t\t\t\t// Parse message payload\n\t\t\t\t\tconst content = msg.content.toString();\n\t\t\t\t\tconst payload = JSON.parse(content);\n\n\t\t\t\t\t// Get message type from properties\n\t\t\t\t\tconst messageType = msg.properties.type;\n\n\t\t\t\t\t// Reconstruct full message\n\t\t\t\t\tconst fullMessage: TMessage = {\n\t\t\t\t\t\ttype: messageType,\n\t\t\t\t\t\tpayload,\n\t\t\t\t\t} as TMessage;\n\n\t\t\t\t\t// Call listener, as a child of the publisher's span\n\t\t\t\t\tawait consumeTraced(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsystem: 'rabbitmq',\n\t\t\t\t\t\t\tdestination: queue,\n\t\t\t\t\t\t\ttype: messageType,\n\t\t\t\t\t\t\tmessageId: msg.properties.messageId,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcarrierFromAttributes(msg.properties.headers),\n\t\t\t\t\t\t() => listener(fullMessage),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Ack message\n\t\t\t\t\tchannel.ack(msg);\n\t\t\t\t} catch (_error) {\n\t\t\t\t\tchannel.nack(msg, false, true);\n\t\t\t\t}\n\t\t\t},\n\t\t\tthis.options.consumeOptions,\n\t\t);\n\t}\n}\n","import type { EventsDriver } from '../registry';\nimport { EventPublisherType } from '../types';\nimport { RabbitMQConnection } from './RabbitMQConnection';\nimport { RabbitMQPublisher } from './RabbitMQPublisher';\nimport { RabbitMQSubscriber } from './RabbitMQSubscriber';\n\n/**\n * `rabbitmq://` — an AMQP exchange. Register it with\n * `registerEventsDriver(rabbitmqEventsDriver)`; this subpath is the only one\n * that imports `amqplib`.\n */\nexport const rabbitmqEventsDriver: EventsDriver = {\n\tscheme: EventPublisherType.RabbitMQ,\n\tconnect: (url) => RabbitMQConnection.fromConnectionString(url),\n\tpublisher: (url) => RabbitMQPublisher.fromConnectionString(url),\n\tpublisherFor: (connection) =>\n\t\tnew RabbitMQPublisher(connection as RabbitMQConnection),\n\tsubscriber: (url) => RabbitMQSubscriber.fromConnectionString(url),\n\tsubscriberFor: (connection) =>\n\t\tnew RabbitMQSubscriber(connection as RabbitMQConnection),\n};\n"],"mappings":";;;;;;;AAYA,IAAa,qBAAb,MAAa,mBAA8C;CAC1D,OAAS;CACT;CACA;CACA;CACA;CAKA,YAAY,QAAkC;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