@kaushverse/rabbitmq-core 1.0.1 → 1.0.3
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/dist/index.d.ts +20 -17
- package/dist/index.js +25 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,33 +6,20 @@ interface RabbitTLSOptions {
|
|
|
6
6
|
servername?: string;
|
|
7
7
|
rejectUnauthorized?: boolean;
|
|
8
8
|
}
|
|
9
|
-
interface RabbitConnectionOptions$1 {
|
|
10
|
-
url: string;
|
|
11
|
-
tls?: RabbitTLSOptions;
|
|
12
|
-
socketOptions?: Options.Connect;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
interface RabbitConnectionOptions {
|
|
16
10
|
url: string;
|
|
17
11
|
tls?: RabbitTLSOptions;
|
|
12
|
+
socketOptions?: Options.Connect;
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
declare function connectRabbitMQ(options: RabbitConnectionOptions): Promise<Channel>;
|
|
21
|
-
declare function getChannel(): Channel;
|
|
22
|
-
declare function closeRabbitMQ(): Promise<void>;
|
|
23
|
-
declare function isRabbitConnected(): boolean;
|
|
24
|
-
|
|
14
|
+
type ExchangeType = "direct" | "topic" | "fanout" | "headers";
|
|
25
15
|
interface ConsumeOptions {
|
|
26
16
|
queue: string;
|
|
27
17
|
exchange: string;
|
|
28
|
-
type:
|
|
18
|
+
type: ExchangeType;
|
|
29
19
|
routingKey?: string;
|
|
30
20
|
prefetch?: number;
|
|
31
21
|
noAck?: boolean;
|
|
32
22
|
}
|
|
33
|
-
declare function consumeMessage(options: ConsumeOptions, handler: (data: any, raw: ConsumeMessage) => Promise<void> | void): Promise<void>;
|
|
34
|
-
|
|
35
|
-
type ExchangeType = "direct" | "topic" | "fanout" | "headers";
|
|
36
23
|
interface PublishOptions {
|
|
37
24
|
exchange: string;
|
|
38
25
|
type: ExchangeType;
|
|
@@ -40,6 +27,22 @@ interface PublishOptions {
|
|
|
40
27
|
message: Buffer | string | object;
|
|
41
28
|
headers?: Record<string, any>;
|
|
42
29
|
}
|
|
30
|
+
|
|
31
|
+
declare const rabbitEvents: EventEmitter<[never]>;
|
|
32
|
+
declare function getChannel(): Channel;
|
|
33
|
+
|
|
34
|
+
declare function consumeMessage(options: ConsumeOptions, handler: (data: any, raw: ConsumeMessage) => Promise<void> | void): Promise<void>;
|
|
35
|
+
|
|
43
36
|
declare function publishMessage({ exchange, type, routingKey, message, headers, }: PublishOptions): Promise<void>;
|
|
44
37
|
|
|
45
|
-
|
|
38
|
+
type BootstrapOptions = {
|
|
39
|
+
serviceName?: string;
|
|
40
|
+
start: () => void | Promise<void>;
|
|
41
|
+
rabbit: {
|
|
42
|
+
url: string;
|
|
43
|
+
tls?: RabbitTLSOptions;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
declare function bootstrap(options: BootstrapOptions): Promise<void>;
|
|
47
|
+
|
|
48
|
+
export { type ConsumeOptions, type ExchangeType, type PublishOptions, type RabbitConnectionOptions, type RabbitTLSOptions, bootstrap, consumeMessage, getChannel, publishMessage, rabbitEvents };
|
package/dist/index.js
CHANGED
|
@@ -30,11 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
|
|
34
|
-
connectRabbitMQ: () => connectRabbitMQ,
|
|
33
|
+
bootstrap: () => bootstrap,
|
|
35
34
|
consumeMessage: () => consumeMessage,
|
|
36
35
|
getChannel: () => getChannel,
|
|
37
|
-
isRabbitConnected: () => isRabbitConnected,
|
|
38
36
|
publishMessage: () => publishMessage,
|
|
39
37
|
rabbitEvents: () => rabbitEvents
|
|
40
38
|
});
|
|
@@ -106,9 +104,6 @@ async function closeRabbitMQ() {
|
|
|
106
104
|
rabbitEvents.emit("disconnected");
|
|
107
105
|
}
|
|
108
106
|
}
|
|
109
|
-
function isRabbitConnected() {
|
|
110
|
-
return connected;
|
|
111
|
-
}
|
|
112
107
|
|
|
113
108
|
// src/consumer.ts
|
|
114
109
|
async function consumeMessage(options, handler) {
|
|
@@ -169,13 +164,34 @@ async function publishMessage({
|
|
|
169
164
|
headers
|
|
170
165
|
});
|
|
171
166
|
}
|
|
167
|
+
|
|
168
|
+
// src/bootstrap.ts
|
|
169
|
+
async function bootstrap(options) {
|
|
170
|
+
const { serviceName = "service", start, rabbit } = options;
|
|
171
|
+
try {
|
|
172
|
+
await connectRabbitMQ({
|
|
173
|
+
url: rabbit.url,
|
|
174
|
+
tls: rabbit.tls
|
|
175
|
+
});
|
|
176
|
+
await start();
|
|
177
|
+
console.log(`\u{1F680} ${serviceName} started successfully`);
|
|
178
|
+
const shutdown = async (signal) => {
|
|
179
|
+
console.log(`\u{1F6D1} ${serviceName} shutting down (${signal})...`);
|
|
180
|
+
await closeRabbitMQ();
|
|
181
|
+
process.exit(0);
|
|
182
|
+
};
|
|
183
|
+
process.on("SIGINT", shutdown);
|
|
184
|
+
process.on("SIGTERM", shutdown);
|
|
185
|
+
} catch (err) {
|
|
186
|
+
console.error(`\u274C ${serviceName} startup failed:`, err);
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
172
190
|
// Annotate the CommonJS export names for ESM import in node:
|
|
173
191
|
0 && (module.exports = {
|
|
174
|
-
|
|
175
|
-
connectRabbitMQ,
|
|
192
|
+
bootstrap,
|
|
176
193
|
consumeMessage,
|
|
177
194
|
getChannel,
|
|
178
|
-
isRabbitConnected,
|
|
179
195
|
publishMessage,
|
|
180
196
|
rabbitEvents
|
|
181
197
|
});
|