@warlock.js/herald 4.0.174 → 4.1.2
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 +36 -33
- package/cjs/index.cjs +1355 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/communicators/broker-registry.d.mts +157 -0
- package/esm/communicators/broker-registry.d.mts.map +1 -0
- package/esm/communicators/broker-registry.mjs +204 -0
- package/esm/communicators/broker-registry.mjs.map +1 -0
- package/esm/communicators/broker.d.mts +104 -0
- package/esm/communicators/broker.d.mts.map +1 -0
- package/esm/communicators/broker.mjs +104 -0
- package/esm/communicators/broker.mjs.map +1 -0
- package/esm/communicators/index.d.mts +2 -0
- package/esm/communicators/index.mjs +4 -0
- package/esm/contracts/broker-driver.contract.d.mts +200 -0
- package/esm/contracts/broker-driver.contract.d.mts.map +1 -0
- package/esm/contracts/channel.contract.d.mts +197 -0
- package/esm/contracts/channel.contract.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +2 -0
- package/esm/decorators/consumable.d.mts +17 -0
- package/esm/decorators/consumable.d.mts.map +1 -0
- package/esm/decorators/consumable.mjs +36 -0
- package/esm/decorators/consumable.mjs.map +1 -0
- package/esm/decorators/index.d.mts +1 -0
- package/esm/decorators/index.mjs +3 -0
- package/esm/drivers/index.d.mts +2 -0
- package/esm/drivers/index.mjs +5 -0
- package/esm/drivers/rabbitmq/index.d.mts +2 -0
- package/esm/drivers/rabbitmq/index.mjs +4 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.mts +85 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.mts.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.mjs +352 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.mjs.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.mts +130 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.mts.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.mjs +291 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.mjs.map +1 -0
- package/esm/index.d.mts +20 -0
- package/esm/index.mjs +16 -0
- package/esm/message-managers/event-consumer.d.mts +61 -0
- package/esm/message-managers/event-consumer.d.mts.map +1 -0
- package/esm/message-managers/event-consumer.mjs +63 -0
- package/esm/message-managers/event-consumer.mjs.map +1 -0
- package/esm/message-managers/event-message.d.mts +87 -0
- package/esm/message-managers/event-message.d.mts.map +1 -0
- package/esm/message-managers/event-message.mjs +68 -0
- package/esm/message-managers/event-message.mjs.map +1 -0
- package/esm/message-managers/index.d.mts +3 -0
- package/esm/message-managers/index.mjs +4 -0
- package/esm/message-managers/prepare-consumer-subscription.mjs +42 -0
- package/esm/message-managers/prepare-consumer-subscription.mjs.map +1 -0
- package/esm/message-managers/types.d.mts +23 -0
- package/esm/message-managers/types.d.mts.map +1 -0
- package/esm/types/channel.types.d.mts +23 -0
- package/esm/types/channel.types.d.mts.map +1 -0
- package/esm/types/connection.types.d.mts +67 -0
- package/esm/types/connection.types.d.mts.map +1 -0
- package/esm/types/driver.types.d.mts +13 -0
- package/esm/types/driver.types.d.mts.map +1 -0
- package/esm/types/index.d.mts +7 -0
- package/esm/types/message.types.d.mts +37 -0
- package/esm/types/message.types.d.mts.map +1 -0
- package/esm/types/publish.types.d.mts +16 -0
- package/esm/types/publish.types.d.mts.map +1 -0
- package/esm/types/registry.types.d.mts +8 -0
- package/esm/types/registry.types.d.mts.map +1 -0
- package/esm/types/subscribe.types.d.mts +21 -0
- package/esm/types/subscribe.types.d.mts.map +1 -0
- package/esm/use-case-broadcast.d.mts +41 -0
- package/esm/use-case-broadcast.d.mts.map +1 -0
- package/esm/use-case-broadcast.mjs +30 -0
- package/esm/use-case-broadcast.mjs.map +1 -0
- package/esm/utils/{connect-to-broker.d.ts → connect-to-broker.d.mts} +15 -10
- package/esm/utils/connect-to-broker.d.mts.map +1 -0
- package/esm/utils/connect-to-broker.mjs +168 -0
- package/esm/utils/connect-to-broker.mjs.map +1 -0
- package/esm/utils/index.d.mts +1 -0
- package/esm/utils/index.mjs +3 -0
- package/llms-full.txt +581 -0
- package/llms.txt +12 -0
- package/package.json +46 -46
- package/skills/README.md +21 -0
- package/skills/consume-message/SKILL.md +217 -0
- package/skills/herald-basics/SKILL.md +96 -0
- package/skills/publish-message/SKILL.md +172 -0
- package/skills/request-and-respond/SKILL.md +74 -0
- package/cjs/communicators/broker-registry.d.ts +0 -155
- package/cjs/communicators/broker-registry.d.ts.map +0 -1
- package/cjs/communicators/broker-registry.js +0 -206
- package/cjs/communicators/broker-registry.js.map +0 -1
- package/cjs/communicators/broker.d.ts +0 -100
- package/cjs/communicators/broker.d.ts.map +0 -1
- package/cjs/communicators/broker.js +0 -105
- package/cjs/communicators/broker.js.map +0 -1
- package/cjs/communicators/index.d.ts +0 -3
- package/cjs/communicators/index.d.ts.map +0 -1
- package/cjs/contracts/broker-driver.contract.d.ts +0 -196
- package/cjs/contracts/broker-driver.contract.d.ts.map +0 -1
- package/cjs/contracts/channel.contract.d.ts +0 -191
- package/cjs/contracts/channel.contract.d.ts.map +0 -1
- package/cjs/contracts/index.d.ts +0 -3
- package/cjs/contracts/index.d.ts.map +0 -1
- package/cjs/decorators/consumable.d.ts +0 -13
- package/cjs/decorators/consumable.d.ts.map +0 -1
- package/cjs/decorators/consumable.js +0 -33
- package/cjs/decorators/consumable.js.map +0 -1
- package/cjs/decorators/index.d.ts +0 -2
- package/cjs/decorators/index.d.ts.map +0 -1
- package/cjs/drivers/index.d.ts +0 -2
- package/cjs/drivers/index.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/index.d.ts +0 -3
- package/cjs/drivers/rabbitmq/index.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts +0 -79
- package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-channel.js +0 -414
- package/cjs/drivers/rabbitmq/rabbitmq-channel.js.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts +0 -124
- package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-driver.js +0 -347
- package/cjs/drivers/rabbitmq/rabbitmq-driver.js.map +0 -1
- package/cjs/index.d.ts +0 -47
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js +0 -1
- package/cjs/index.js.map +0 -1
- package/cjs/message-managers/event-consumer.d.ts +0 -64
- package/cjs/message-managers/event-consumer.d.ts.map +0 -1
- package/cjs/message-managers/event-consumer.js +0 -71
- package/cjs/message-managers/event-consumer.js.map +0 -1
- package/cjs/message-managers/event-message.d.ts +0 -90
- package/cjs/message-managers/event-message.d.ts.map +0 -1
- package/cjs/message-managers/event-message.js +0 -84
- package/cjs/message-managers/event-message.js.map +0 -1
- package/cjs/message-managers/index.d.ts +0 -4
- package/cjs/message-managers/index.d.ts.map +0 -1
- package/cjs/message-managers/prepare-consumer-subscription.d.ts +0 -4
- package/cjs/message-managers/prepare-consumer-subscription.d.ts.map +0 -1
- package/cjs/message-managers/prepare-consumer-subscription.js +0 -40
- package/cjs/message-managers/prepare-consumer-subscription.js.map +0 -1
- package/cjs/message-managers/types.d.ts +0 -20
- package/cjs/message-managers/types.d.ts.map +0 -1
- package/cjs/types/channel.types.d.ts +0 -19
- package/cjs/types/channel.types.d.ts.map +0 -1
- package/cjs/types/connection.types.d.ts +0 -65
- package/cjs/types/connection.types.d.ts.map +0 -1
- package/cjs/types/driver.types.d.ts +0 -10
- package/cjs/types/driver.types.d.ts.map +0 -1
- package/cjs/types/index.d.ts +0 -8
- package/cjs/types/index.d.ts.map +0 -1
- package/cjs/types/message.types.d.ts +0 -34
- package/cjs/types/message.types.d.ts.map +0 -1
- package/cjs/types/publish.types.d.ts +0 -13
- package/cjs/types/publish.types.d.ts.map +0 -1
- package/cjs/types/registry.types.d.ts +0 -4
- package/cjs/types/registry.types.d.ts.map +0 -1
- package/cjs/types/subscribe.types.d.ts +0 -18
- package/cjs/types/subscribe.types.d.ts.map +0 -1
- package/cjs/utils/connect-to-broker.d.ts +0 -131
- package/cjs/utils/connect-to-broker.d.ts.map +0 -1
- package/cjs/utils/connect-to-broker.js +0 -171
- package/cjs/utils/connect-to-broker.js.map +0 -1
- package/cjs/utils/index.d.ts +0 -2
- package/cjs/utils/index.d.ts.map +0 -1
- package/esm/communicators/broker-registry.d.ts +0 -155
- package/esm/communicators/broker-registry.d.ts.map +0 -1
- package/esm/communicators/broker-registry.js +0 -206
- package/esm/communicators/broker-registry.js.map +0 -1
- package/esm/communicators/broker.d.ts +0 -100
- package/esm/communicators/broker.d.ts.map +0 -1
- package/esm/communicators/broker.js +0 -105
- package/esm/communicators/broker.js.map +0 -1
- package/esm/communicators/index.d.ts +0 -3
- package/esm/communicators/index.d.ts.map +0 -1
- package/esm/contracts/broker-driver.contract.d.ts +0 -196
- package/esm/contracts/broker-driver.contract.d.ts.map +0 -1
- package/esm/contracts/channel.contract.d.ts +0 -191
- package/esm/contracts/channel.contract.d.ts.map +0 -1
- package/esm/contracts/index.d.ts +0 -3
- package/esm/contracts/index.d.ts.map +0 -1
- package/esm/decorators/consumable.d.ts +0 -13
- package/esm/decorators/consumable.d.ts.map +0 -1
- package/esm/decorators/consumable.js +0 -33
- package/esm/decorators/consumable.js.map +0 -1
- package/esm/decorators/index.d.ts +0 -2
- package/esm/decorators/index.d.ts.map +0 -1
- package/esm/drivers/index.d.ts +0 -2
- package/esm/drivers/index.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/index.d.ts +0 -3
- package/esm/drivers/rabbitmq/index.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts +0 -79
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-channel.js +0 -414
- package/esm/drivers/rabbitmq/rabbitmq-channel.js.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts +0 -124
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-driver.js +0 -347
- package/esm/drivers/rabbitmq/rabbitmq-driver.js.map +0 -1
- package/esm/index.d.ts +0 -47
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +0 -1
- package/esm/message-managers/event-consumer.d.ts +0 -64
- package/esm/message-managers/event-consumer.d.ts.map +0 -1
- package/esm/message-managers/event-consumer.js +0 -71
- package/esm/message-managers/event-consumer.js.map +0 -1
- package/esm/message-managers/event-message.d.ts +0 -90
- package/esm/message-managers/event-message.d.ts.map +0 -1
- package/esm/message-managers/event-message.js +0 -84
- package/esm/message-managers/event-message.js.map +0 -1
- package/esm/message-managers/index.d.ts +0 -4
- package/esm/message-managers/index.d.ts.map +0 -1
- package/esm/message-managers/prepare-consumer-subscription.d.ts +0 -4
- package/esm/message-managers/prepare-consumer-subscription.d.ts.map +0 -1
- package/esm/message-managers/prepare-consumer-subscription.js +0 -40
- package/esm/message-managers/prepare-consumer-subscription.js.map +0 -1
- package/esm/message-managers/types.d.ts +0 -20
- package/esm/message-managers/types.d.ts.map +0 -1
- package/esm/types/channel.types.d.ts +0 -19
- package/esm/types/channel.types.d.ts.map +0 -1
- package/esm/types/connection.types.d.ts +0 -65
- package/esm/types/connection.types.d.ts.map +0 -1
- package/esm/types/driver.types.d.ts +0 -10
- package/esm/types/driver.types.d.ts.map +0 -1
- package/esm/types/index.d.ts +0 -8
- package/esm/types/index.d.ts.map +0 -1
- package/esm/types/message.types.d.ts +0 -34
- package/esm/types/message.types.d.ts.map +0 -1
- package/esm/types/publish.types.d.ts +0 -13
- package/esm/types/publish.types.d.ts.map +0 -1
- package/esm/types/registry.types.d.ts +0 -4
- package/esm/types/registry.types.d.ts.map +0 -1
- package/esm/types/subscribe.types.d.ts +0 -18
- package/esm/types/subscribe.types.d.ts.map +0 -1
- package/esm/utils/connect-to-broker.d.ts.map +0 -1
- package/esm/utils/connect-to-broker.js +0 -171
- package/esm/utils/connect-to-broker.js.map +0 -1
- package/esm/utils/index.d.ts +0 -2
- package/esm/utils/index.d.ts.map +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: request-and-respond
|
|
3
|
+
description: 'Synchronous-style RPC over the message bus — channel.request<R>(payload, {timeout}) waits for a reply, channel.respond(handler) registers the responder, ctx.reply(response) sends the answer. Triggers: `channel.request`, `channel.respond`, `ctx.reply`, `timeout`, `correlationId`, `headers.correlationId`; "RPC over message bus", "request-response across services", "wait for a reply", "internal service-to-service call instead of HTTP"; typical import `import { herald } from "@warlock.js/herald"`. Skip: setup — `@warlock.js/herald/herald-basics/SKILL.md`; fire-and-forget — `@warlock.js/herald/publish-message/SKILL.md`; consumer ctx flow — `@warlock.js/herald/consume-message/SKILL.md`; competing libs `amqplib` RPC, `nats` request/reply; NestJS `ClientProxy.send`; gRPC; HTTP.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Request-response over the bus
|
|
7
|
+
|
|
8
|
+
Most messaging is fire-and-forget. When you need a reply, use the request/respond pair — a reply-queue + correlation-id pattern under the hood, surfaced as a typed promise.
|
|
9
|
+
|
|
10
|
+
## Shape
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
// Caller (client)
|
|
14
|
+
const response = await herald()
|
|
15
|
+
.channel<RequestPayload>("compute.tax")
|
|
16
|
+
.request<TaxResponse>({ amount: 1000, country: "US" }, { timeout: 30_000 });
|
|
17
|
+
|
|
18
|
+
// Responder (server)
|
|
19
|
+
herald()
|
|
20
|
+
.channel<RequestPayload>("compute.tax")
|
|
21
|
+
.respond(async (message, ctx) => {
|
|
22
|
+
const tax = await computeTax(message.payload);
|
|
23
|
+
return { tax, currency: "USD" }; // ← the return value IS the reply
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`request` returns a promise that resolves with the responder's return value. `respond` registers a handler and **automatically replies with whatever the handler returns** (then acks) — so just `return` the response; you don't call `ctx.reply()` yourself inside a `respond` handler. (`ctx.reply` is the lower-level primitive used when you wire a plain `.subscribe()` as a responder by hand.)
|
|
28
|
+
|
|
29
|
+
## Timeout
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
await channel.request(payload, { timeout: 30_000 });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The promise rejects if no reply arrives within `timeout` ms. Pick a sane number — too short rejects mid-work; too long lets a hung responder block the caller.
|
|
36
|
+
|
|
37
|
+
## When to use it vs HTTP
|
|
38
|
+
|
|
39
|
+
| Use HTTP | Use request/respond |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| Stateless, fast, idempotent ops | Slow / queued ops where the caller can wait |
|
|
42
|
+
| Public API surface | Internal service-to-service |
|
|
43
|
+
| Frontend consumption | Backend orchestration |
|
|
44
|
+
| Synchronous user-facing flow | Async-but-needs-result patterns |
|
|
45
|
+
|
|
46
|
+
The bus adds queue persistence and retry. HTTP is faster for sub-100ms ops; the bus shines when the operation has variable duration or needs a queue's backpressure.
|
|
47
|
+
|
|
48
|
+
## When NOT to use it
|
|
49
|
+
|
|
50
|
+
- "I need a result in under 50ms" — too much overhead on the bus.
|
|
51
|
+
- "The responder might be down for hours" — request will time out repeatedly; consider `publish` + write the result somewhere the caller polls.
|
|
52
|
+
- "Many callers, the response is the same for all" — cache the result and use `publish` for invalidation.
|
|
53
|
+
|
|
54
|
+
## Multiple responders
|
|
55
|
+
|
|
56
|
+
`respond(handler)` takes no options — there's no `group` knob here. If multiple consumers `respond()` to the same channel, they all sit on the same queue, so RabbitMQ round-robins between them: **one responder handles each request, and the caller gets exactly one reply.** That's the "share work across responders" pattern — a synchronous worker pool. Make every responder functionally identical, since the caller has no say in which one answers.
|
|
57
|
+
|
|
58
|
+
For "multiple replies expected" patterns, use a regular `subscribe` + a request id, then the caller listens on a result channel.
|
|
59
|
+
|
|
60
|
+
## Correlation across replies
|
|
61
|
+
|
|
62
|
+
Each `request()` generates its own correlation ID and an exclusive reply queue under the hood. The reply carries the same ID; the client matches it to the awaiting promise and resolves. You don't manage correlation IDs manually — and you shouldn't pass your own `correlationId` on a `request()`, since herald overwrites it with the one it uses to match the reply. To thread your own trace id (e.g. a transaction id for logs) through to the responder, put it in `headers` instead — the responder reads it from `message.metadata.headers`.
|
|
63
|
+
|
|
64
|
+
## Things NOT to do
|
|
65
|
+
|
|
66
|
+
- Don't use request/respond for high-throughput, low-latency ops. The reply-queue round-trip adds at least one broker hop. HTTP is the right tool.
|
|
67
|
+
- Don't return huge payloads from `respond`. Reply messages travel through the broker; a multi-MB response is a load on the bus and on memory. For big results, write to S3 / cache and reply with a reference.
|
|
68
|
+
- Don't forget to `respond` in long-lived consumers. If the responder crashes, every caller's request will time out — they don't know why.
|
|
69
|
+
- Don't set timeout to `Infinity`. A stuck request becomes a leaked promise — set a real timeout and handle the rejection.
|
|
70
|
+
|
|
71
|
+
## See also
|
|
72
|
+
|
|
73
|
+
- [`@warlock.js/herald/publish-message/SKILL.md`](@warlock.js/herald/publish-message/SKILL.md) — fire-and-forget pattern
|
|
74
|
+
- [`@warlock.js/herald/consume-message/SKILL.md`](@warlock.js/herald/consume-message/SKILL.md) — subscribe + ctx flow control (including `ctx.reply`)
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import type { BrokerRegistryEvent, BrokerRegistryListener } from "../types";
|
|
2
|
-
import { Broker, type BrokerOptions } from "./broker";
|
|
3
|
-
/**
|
|
4
|
-
* Error thrown when a broker is not found
|
|
5
|
-
*/
|
|
6
|
-
export declare class MissingBrokerError extends Error {
|
|
7
|
-
readonly brokerName?: string;
|
|
8
|
-
constructor(message: string, brokerName?: string);
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Broker Registry
|
|
12
|
-
*
|
|
13
|
-
* Maintains registry of named brokers.
|
|
14
|
-
* Similar to DataSourceRegistry in @warlock.js/cascade
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* // Register a broker
|
|
19
|
-
* brokerRegistry.register({
|
|
20
|
-
* name: "default",
|
|
21
|
-
* driver: rabbitMQDriver,
|
|
22
|
-
* isDefault: true,
|
|
23
|
-
* });
|
|
24
|
-
*
|
|
25
|
-
* // Get the default broker
|
|
26
|
-
* const comm = brokerRegistry.get();
|
|
27
|
-
*
|
|
28
|
-
* // Get a specific broker by name
|
|
29
|
-
* const analytics = brokerRegistry.get("analytics");
|
|
30
|
-
*
|
|
31
|
-
* // Listen for events
|
|
32
|
-
* brokerRegistry.on("connected", (comm) => {
|
|
33
|
-
* console.log(`${comm.name} connected`);
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
declare class BrokerRegistry {
|
|
38
|
-
private readonly sources;
|
|
39
|
-
private defaultSource?;
|
|
40
|
-
private readonly events;
|
|
41
|
-
/**
|
|
42
|
-
* Register a new broker
|
|
43
|
-
*
|
|
44
|
-
* Sets up event forwarding from the driver to the registry.
|
|
45
|
-
*
|
|
46
|
-
* @param options - Broker configuration
|
|
47
|
-
* @returns The registered broker instance
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```typescript
|
|
51
|
-
* const broker = brokerRegistry.register({
|
|
52
|
-
* name: "primary",
|
|
53
|
-
* driver: myDriver,
|
|
54
|
-
* isDefault: true,
|
|
55
|
-
* });
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
register(options: BrokerOptions): Broker;
|
|
59
|
-
/**
|
|
60
|
-
* Clear all registered brokers
|
|
61
|
-
*/
|
|
62
|
-
clear(): void;
|
|
63
|
-
/**
|
|
64
|
-
* Listen for registry events
|
|
65
|
-
*
|
|
66
|
-
* @param event - Event to listen for
|
|
67
|
-
* @param listener - Callback function
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* brokerRegistry.on("registered", (comm) => {
|
|
72
|
-
* console.log(`Broker "${comm.name}" registered`);
|
|
73
|
-
* });
|
|
74
|
-
*
|
|
75
|
-
* brokerRegistry.on("connected", (comm) => {
|
|
76
|
-
* console.log(`Broker "${comm.name}" connected`);
|
|
77
|
-
* });
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
on(event: BrokerRegistryEvent, listener: BrokerRegistryListener): void;
|
|
81
|
-
/**
|
|
82
|
-
* Listen for a registry event once
|
|
83
|
-
*
|
|
84
|
-
* @param event - Event to listen for
|
|
85
|
-
* @param listener - Callback function
|
|
86
|
-
*/
|
|
87
|
-
once(event: BrokerRegistryEvent, listener: BrokerRegistryListener): void;
|
|
88
|
-
/**
|
|
89
|
-
* Remove an event listener
|
|
90
|
-
*
|
|
91
|
-
* @param event - Event to stop listening for
|
|
92
|
-
* @param listener - Callback to remove
|
|
93
|
-
*/
|
|
94
|
-
off(event: BrokerRegistryEvent, listener: BrokerRegistryListener): void;
|
|
95
|
-
/**
|
|
96
|
-
* Get a broker by name or the default one
|
|
97
|
-
*
|
|
98
|
-
* @param name - Optional broker name
|
|
99
|
-
* @returns Broker instance
|
|
100
|
-
* @throws MissingBrokerError if not found
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* // Get default broker
|
|
105
|
-
* const comm = brokerRegistry.get();
|
|
106
|
-
*
|
|
107
|
-
* // Get specific broker
|
|
108
|
-
* const analytics = brokerRegistry.get("analytics");
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
get(name?: string): Broker;
|
|
112
|
-
/**
|
|
113
|
-
* Check if a broker exists
|
|
114
|
-
*
|
|
115
|
-
* @param name - Broker name to check
|
|
116
|
-
* @returns True if exists
|
|
117
|
-
*/
|
|
118
|
-
has(name: string): boolean;
|
|
119
|
-
/**
|
|
120
|
-
* Check if any brokers are registered
|
|
121
|
-
*/
|
|
122
|
-
hasAny(): boolean;
|
|
123
|
-
/**
|
|
124
|
-
* Get all registered brokers
|
|
125
|
-
*
|
|
126
|
-
* @returns Array of all brokers
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```typescript
|
|
130
|
-
* // Disconnect all brokers
|
|
131
|
-
* for (const comm of brokerRegistry.getAll()) {
|
|
132
|
-
* await comm.disconnect();
|
|
133
|
-
* }
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
getAll(): Broker[];
|
|
137
|
-
/**
|
|
138
|
-
* Get all broker names
|
|
139
|
-
*
|
|
140
|
-
* @returns Array of broker names
|
|
141
|
-
*/
|
|
142
|
-
getNames(): string[];
|
|
143
|
-
/**
|
|
144
|
-
* Get the default broker (if any)
|
|
145
|
-
*
|
|
146
|
-
* @returns Default broker or undefined
|
|
147
|
-
*/
|
|
148
|
-
getDefault(): Broker | undefined;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Global broker registry instance
|
|
152
|
-
*/
|
|
153
|
-
export declare const brokerRegistry: BrokerRegistry;
|
|
154
|
-
export {};
|
|
155
|
-
//# sourceMappingURL=broker-registry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"broker-registry.d.ts","sourceRoot":"","sources":["../../src/communicators/broker-registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAEtD;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAKxD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,cAAM,cAAc;IAClB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,aAAa,CAAC,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAE7C;;;;;;;;;;;;;;;;OAgBG;IACI,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM;IA6B/C;;OAEG;IACI,KAAK,IAAI,IAAI;IAKpB;;;;;;;;;;;;;;;;OAgBG;IACI,EAAE,CAAC,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,sBAAsB,GAAG,IAAI;IAI7E;;;;;OAKG;IACI,IAAI,CAAC,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,sBAAsB,GAAG,IAAI;IAI/E;;;;;OAKG;IACI,GAAG,CAAC,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,sBAAsB,GAAG,IAAI;IAI9E;;;;;;;;;;;;;;;OAeG;IACI,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;IAgBjC;;;;;OAKG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC;;OAEG;IACI,MAAM,IAAI,OAAO;IAIxB;;;;;;;;;;;;OAYG;IACI,MAAM,IAAI,MAAM,EAAE;IAIzB;;;;OAIG;IACI,QAAQ,IAAI,MAAM,EAAE;IAI3B;;;;OAIG;IACI,UAAU,IAAI,MAAM,GAAG,SAAS;CAGxC;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
'use strict';var node_events=require('node:events'),broker=require('./broker.js');/**
|
|
2
|
-
* Error thrown when a broker is not found
|
|
3
|
-
*/
|
|
4
|
-
class MissingBrokerError extends Error {
|
|
5
|
-
brokerName;
|
|
6
|
-
constructor(message, brokerName) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = "MissingBrokerError";
|
|
9
|
-
this.brokerName = brokerName;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Broker Registry
|
|
14
|
-
*
|
|
15
|
-
* Maintains registry of named brokers.
|
|
16
|
-
* Similar to DataSourceRegistry in @warlock.js/cascade
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* // Register a broker
|
|
21
|
-
* brokerRegistry.register({
|
|
22
|
-
* name: "default",
|
|
23
|
-
* driver: rabbitMQDriver,
|
|
24
|
-
* isDefault: true,
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* // Get the default broker
|
|
28
|
-
* const comm = brokerRegistry.get();
|
|
29
|
-
*
|
|
30
|
-
* // Get a specific broker by name
|
|
31
|
-
* const analytics = brokerRegistry.get("analytics");
|
|
32
|
-
*
|
|
33
|
-
* // Listen for events
|
|
34
|
-
* brokerRegistry.on("connected", (comm) => {
|
|
35
|
-
* console.log(`${comm.name} connected`);
|
|
36
|
-
* });
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
class BrokerRegistry {
|
|
40
|
-
sources = new Map();
|
|
41
|
-
defaultSource;
|
|
42
|
-
events = new node_events.EventEmitter();
|
|
43
|
-
/**
|
|
44
|
-
* Register a new broker
|
|
45
|
-
*
|
|
46
|
-
* Sets up event forwarding from the driver to the registry.
|
|
47
|
-
*
|
|
48
|
-
* @param options - Broker configuration
|
|
49
|
-
* @returns The registered broker instance
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* const broker = brokerRegistry.register({
|
|
54
|
-
* name: "primary",
|
|
55
|
-
* driver: myDriver,
|
|
56
|
-
* isDefault: true,
|
|
57
|
-
* });
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
register(options) {
|
|
61
|
-
const broker$1 = new broker.Broker(options);
|
|
62
|
-
this.sources.set(broker$1.name, broker$1);
|
|
63
|
-
const isNewDefault = broker$1.isDefault || !this.defaultSource;
|
|
64
|
-
if (isNewDefault) {
|
|
65
|
-
this.defaultSource = broker$1;
|
|
66
|
-
}
|
|
67
|
-
// Emit registration events
|
|
68
|
-
this.events.emit("registered", broker$1);
|
|
69
|
-
if (isNewDefault) {
|
|
70
|
-
this.events.emit("default-registered", broker$1);
|
|
71
|
-
}
|
|
72
|
-
// Forward driver events to registry
|
|
73
|
-
broker$1.driver.on("connected", () => {
|
|
74
|
-
this.events.emit("connected", broker$1);
|
|
75
|
-
});
|
|
76
|
-
broker$1.driver.on("disconnected", () => {
|
|
77
|
-
this.events.emit("disconnected", broker$1);
|
|
78
|
-
});
|
|
79
|
-
return broker$1;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Clear all registered brokers
|
|
83
|
-
*/
|
|
84
|
-
clear() {
|
|
85
|
-
this.defaultSource = undefined;
|
|
86
|
-
this.sources.clear();
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Listen for registry events
|
|
90
|
-
*
|
|
91
|
-
* @param event - Event to listen for
|
|
92
|
-
* @param listener - Callback function
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* brokerRegistry.on("registered", (comm) => {
|
|
97
|
-
* console.log(`Broker "${comm.name}" registered`);
|
|
98
|
-
* });
|
|
99
|
-
*
|
|
100
|
-
* brokerRegistry.on("connected", (comm) => {
|
|
101
|
-
* console.log(`Broker "${comm.name}" connected`);
|
|
102
|
-
* });
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
on(event, listener) {
|
|
106
|
-
this.events.on(event, listener);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Listen for a registry event once
|
|
110
|
-
*
|
|
111
|
-
* @param event - Event to listen for
|
|
112
|
-
* @param listener - Callback function
|
|
113
|
-
*/
|
|
114
|
-
once(event, listener) {
|
|
115
|
-
this.events.once(event, listener);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Remove an event listener
|
|
119
|
-
*
|
|
120
|
-
* @param event - Event to stop listening for
|
|
121
|
-
* @param listener - Callback to remove
|
|
122
|
-
*/
|
|
123
|
-
off(event, listener) {
|
|
124
|
-
this.events.off(event, listener);
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Get a broker by name or the default one
|
|
128
|
-
*
|
|
129
|
-
* @param name - Optional broker name
|
|
130
|
-
* @returns Broker instance
|
|
131
|
-
* @throws MissingBrokerError if not found
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```typescript
|
|
135
|
-
* // Get default broker
|
|
136
|
-
* const comm = brokerRegistry.get();
|
|
137
|
-
*
|
|
138
|
-
* // Get specific broker
|
|
139
|
-
* const analytics = brokerRegistry.get("analytics");
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
get(name) {
|
|
143
|
-
if (name !== undefined) {
|
|
144
|
-
const source = this.sources.get(name);
|
|
145
|
-
if (!source) {
|
|
146
|
-
throw new MissingBrokerError(`Broker "${name}" is not registered.`, name);
|
|
147
|
-
}
|
|
148
|
-
return source;
|
|
149
|
-
}
|
|
150
|
-
if (!this.defaultSource) {
|
|
151
|
-
throw new MissingBrokerError("No default broker registered.");
|
|
152
|
-
}
|
|
153
|
-
return this.defaultSource;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Check if a broker exists
|
|
157
|
-
*
|
|
158
|
-
* @param name - Broker name to check
|
|
159
|
-
* @returns True if exists
|
|
160
|
-
*/
|
|
161
|
-
has(name) {
|
|
162
|
-
return this.sources.has(name);
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Check if any brokers are registered
|
|
166
|
-
*/
|
|
167
|
-
hasAny() {
|
|
168
|
-
return this.sources.size > 0;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Get all registered brokers
|
|
172
|
-
*
|
|
173
|
-
* @returns Array of all brokers
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```typescript
|
|
177
|
-
* // Disconnect all brokers
|
|
178
|
-
* for (const comm of brokerRegistry.getAll()) {
|
|
179
|
-
* await comm.disconnect();
|
|
180
|
-
* }
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
getAll() {
|
|
184
|
-
return Array.from(this.sources.values());
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Get all broker names
|
|
188
|
-
*
|
|
189
|
-
* @returns Array of broker names
|
|
190
|
-
*/
|
|
191
|
-
getNames() {
|
|
192
|
-
return Array.from(this.sources.keys());
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Get the default broker (if any)
|
|
196
|
-
*
|
|
197
|
-
* @returns Default broker or undefined
|
|
198
|
-
*/
|
|
199
|
-
getDefault() {
|
|
200
|
-
return this.defaultSource;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Global broker registry instance
|
|
205
|
-
*/
|
|
206
|
-
const brokerRegistry = new BrokerRegistry();exports.MissingBrokerError=MissingBrokerError;exports.brokerRegistry=brokerRegistry;//# sourceMappingURL=broker-registry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"broker-registry.js","sources":["../../src/communicators/broker-registry.ts"],"sourcesContent":[null],"names":["EventEmitter","broker","Broker"],"mappings":"kFAIA;;AAEG;AACG,MAAO,kBAAmB,SAAQ,KAAK,CAAA;AAC3B,IAAA,UAAU,CAAU;IAEpC,WAAmB,CAAA,OAAe,EAAE,UAAmB,EAAA;QACrD,KAAK,CAAC,OAAO,CAAC,CAAC;AACf,QAAA,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;AACjC,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;KAC9B;AACF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACH,MAAM,cAAc,CAAA;AACD,IAAA,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;AAC7C,IAAA,aAAa,CAAU;AACd,IAAA,MAAM,GAAG,IAAIA,wBAAY,EAAE,CAAC;AAE7C;;;;;;;;;;;;;;;;AAgBG;AACI,IAAA,QAAQ,CAAC,OAAsB,EAAA;AACpC,QAAA,MAAMC,QAAM,GAAG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AAC,aAAa,CAAC;KAC3B;AACF,CAAA;AAED;;AAEG;AACU,MAAA,cAAc,GAAG,IAAI,cAAc"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import type { BrokerDriverContract } from "../contracts";
|
|
2
|
-
import type { ChannelContract } from "../contracts/channel.contract";
|
|
3
|
-
import { EventMessage } from "../message-managers/event-message";
|
|
4
|
-
import { EventConsumerClass } from "../message-managers/types";
|
|
5
|
-
import type { ChannelOptions } from "../types";
|
|
6
|
-
/**
|
|
7
|
-
* Options for creating a Broker
|
|
8
|
-
*/
|
|
9
|
-
export interface BrokerOptions {
|
|
10
|
-
/** Unique name for this broker */
|
|
11
|
-
name: string;
|
|
12
|
-
/** The underlying driver */
|
|
13
|
-
driver: BrokerDriverContract;
|
|
14
|
-
/** Whether this is the default broker */
|
|
15
|
-
isDefault?: boolean;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Broker - wrapper around a driver with metadata
|
|
19
|
-
*
|
|
20
|
-
* Similar to DataSource in @warlock.js/cascade
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* const broker = new Broker({
|
|
25
|
-
* name: "default",
|
|
26
|
-
* driver: rabbitMQDriver,
|
|
27
|
-
* isDefault: true,
|
|
28
|
-
* });
|
|
29
|
-
*
|
|
30
|
-
* // Get a channel
|
|
31
|
-
* const channel = broker.channel("user.created");
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export declare class Broker {
|
|
35
|
-
/** Unique name identifying this broker */
|
|
36
|
-
readonly name: string;
|
|
37
|
-
/** The underlying driver */
|
|
38
|
-
readonly driver: BrokerDriverContract;
|
|
39
|
-
/** Whether this is the default broker */
|
|
40
|
-
readonly isDefault: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Create a new Broker
|
|
43
|
-
*
|
|
44
|
-
* @param options - Broker configuration
|
|
45
|
-
*/
|
|
46
|
-
constructor(options: BrokerOptions);
|
|
47
|
-
/**
|
|
48
|
-
* Subscribe the given consumer
|
|
49
|
-
*/
|
|
50
|
-
subscribe(consumer: EventConsumerClass<any>): () => void;
|
|
51
|
-
/**
|
|
52
|
-
* Publish the given event message
|
|
53
|
-
*/
|
|
54
|
-
publish<TPayload = Record<string, any>>(event: EventMessage<TPayload>): void;
|
|
55
|
-
/**
|
|
56
|
-
* Get or create a channel
|
|
57
|
-
*
|
|
58
|
-
* @param name - Channel name
|
|
59
|
-
* @param options - Channel options
|
|
60
|
-
* @returns Channel instance
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```typescript
|
|
64
|
-
* // Simple channel
|
|
65
|
-
* const channel = broker.channel("notifications");
|
|
66
|
-
*
|
|
67
|
-
* // Typed channel with schema
|
|
68
|
-
* const orderChannel = broker.channel<OrderPayload>("orders", {
|
|
69
|
-
* schema: OrderSchema,
|
|
70
|
-
* durable: true,
|
|
71
|
-
* });
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
channel<TPayload = unknown>(name: string, options?: ChannelOptions<TPayload>): ChannelContract<TPayload>;
|
|
75
|
-
/**
|
|
76
|
-
* Check if the broker is connected
|
|
77
|
-
*/
|
|
78
|
-
get isConnected(): boolean;
|
|
79
|
-
/**
|
|
80
|
-
* Connect the underlying driver
|
|
81
|
-
*/
|
|
82
|
-
connect(): Promise<void>;
|
|
83
|
-
/**
|
|
84
|
-
* Disconnect the underlying driver
|
|
85
|
-
*/
|
|
86
|
-
disconnect(): Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* Start consuming messages
|
|
89
|
-
*/
|
|
90
|
-
startConsuming(): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* Stop consuming messages
|
|
93
|
-
*/
|
|
94
|
-
stopConsuming(): Promise<void>;
|
|
95
|
-
/**
|
|
96
|
-
* Health check
|
|
97
|
-
*/
|
|
98
|
-
healthCheck(): Promise<import("../types").HealthCheckResult>;
|
|
99
|
-
}
|
|
100
|
-
//# sourceMapping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AW,IAAI,OAAO,CAEhC;IAED;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrC;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxC;;OAEG;IACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5C;;OAEG;IACU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3C;;OAEG;IACU,WAAW;CAGzB"}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
'use strict';/**
|
|
2
|
-
* Broker - wrapper around a driver with metadata
|
|
3
|
-
*
|
|
4
|
-
* Similar to DataSource in @warlock.js/cascade
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* const broker = new Broker({
|
|
9
|
-
* name: "default",
|
|
10
|
-
* driver: rabbitMQDriver,
|
|
11
|
-
* isDefault: true,
|
|
12
|
-
* });
|
|
13
|
-
*
|
|
14
|
-
* // Get a channel
|
|
15
|
-
* const channel = broker.channel("user.created");
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
class Broker {
|
|
19
|
-
/** Unique name identifying this broker */
|
|
20
|
-
name;
|
|
21
|
-
/** The underlying driver */
|
|
22
|
-
driver;
|
|
23
|
-
/** Whether this is the default broker */
|
|
24
|
-
isDefault;
|
|
25
|
-
/**
|
|
26
|
-
* Create a new Broker
|
|
27
|
-
*
|
|
28
|
-
* @param options - Broker configuration
|
|
29
|
-
*/
|
|
30
|
-
constructor(options) {
|
|
31
|
-
this.name = options.name;
|
|
32
|
-
this.driver = options.driver;
|
|
33
|
-
this.isDefault = Boolean(options.isDefault);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Subscribe the given consumer
|
|
37
|
-
*/
|
|
38
|
-
subscribe(consumer) {
|
|
39
|
-
return this.driver.subscribe(consumer);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Publish the given event message
|
|
43
|
-
*/
|
|
44
|
-
publish(event) {
|
|
45
|
-
this.driver.publish(event);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Get or create a channel
|
|
49
|
-
*
|
|
50
|
-
* @param name - Channel name
|
|
51
|
-
* @param options - Channel options
|
|
52
|
-
* @returns Channel instance
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* // Simple channel
|
|
57
|
-
* const channel = broker.channel("notifications");
|
|
58
|
-
*
|
|
59
|
-
* // Typed channel with schema
|
|
60
|
-
* const orderChannel = broker.channel<OrderPayload>("orders", {
|
|
61
|
-
* schema: OrderSchema,
|
|
62
|
-
* durable: true,
|
|
63
|
-
* });
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
channel(name, options) {
|
|
67
|
-
return this.driver.channel(name, options);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Check if the broker is connected
|
|
71
|
-
*/
|
|
72
|
-
get isConnected() {
|
|
73
|
-
return this.driver.isConnected;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Connect the underlying driver
|
|
77
|
-
*/
|
|
78
|
-
async connect() {
|
|
79
|
-
await this.driver.connect();
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Disconnect the underlying driver
|
|
83
|
-
*/
|
|
84
|
-
async disconnect() {
|
|
85
|
-
await this.driver.disconnect();
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Start consuming messages
|
|
89
|
-
*/
|
|
90
|
-
async startConsuming() {
|
|
91
|
-
await this.driver.startConsuming();
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Stop consuming messages
|
|
95
|
-
*/
|
|
96
|
-
async stopConsuming() {
|
|
97
|
-
await this.driver.stopConsuming();
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Health check
|
|
101
|
-
*/
|
|
102
|
-
async healthCheck() {
|
|
103
|
-
return this.driver.healthCheck();
|
|
104
|
-
}
|
|
105
|
-
}exports.Broker=Broker;//# sourceMappingURL=broker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"broker.js","sources":["../../src/communicators/broker.ts"],"sourcesContent":[null],"names":[],"mappings":"aAkBA;;;;;;;;;;;;;;;;AAgBG;MACU,MAAM,CAAA;;AAED,IAAA,IAAI,CAAS;;AAGb,IAAA,MAAM,CAAuB;;AAG7B,IAAA,SAAS,CAAU;AAEnC;;;;AAIG;AACH,IAAA,WAAA,CAAmB,OAAsB,EAAA;AACvC,QAAA,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;AACzB,QAAA,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;KAC7C;AAED;;AAEG;AACI,IAAA,SAAS,CAAC,QAAiC,EAAA;QAChD,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;KACxC;AAED;;AAEG;AACI,IAAA,OAAO,CAAiC,KAA6B,EAAA;AAC1E,QAAA,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;KAC5B;AAED;;;;;;;;;;;;;;;;;;AAkBG;IACI,OAAO,CACZ,IAAY,EACZ,OAAkC,EAAA;QAElC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAW,IAAI,EAAE,OAAO,CAAC,CAAC;KACrD;AAED;;AAEG;AACH,IAAA,IAAW,WAAW,GAAA;AACpB,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;KAChC;AAED;;AAEG;AACI,IAAA,MAAM,OAAO,GAAA;AAClB,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;KAC7B;AAED;;AAEG;AACI,IAAA,MAAM,UAAU,GAAA;AACrB,QAAA,MAAM,IAAI,CAAC,MAAM,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