@lakutata/nats 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -99
- package/README.zh-CN.md +251 -0
- package/dist/cjs/components/NATS.d.ts +2 -2
- package/dist/cjs/components/NATS.js +2 -2
- package/dist/cjs/exceptions/NatsBadRequestException.d.ts +7 -1
- package/dist/cjs/exceptions/NatsBadRequestException.js +8 -3
- package/dist/cjs/exceptions/NatsForbiddenException.d.ts +7 -1
- package/dist/cjs/exceptions/NatsForbiddenException.js +8 -3
- package/dist/cjs/exceptions/NatsInternalServerException.d.ts +7 -1
- package/dist/cjs/exceptions/NatsInternalServerException.js +8 -3
- package/dist/cjs/exceptions/NatsNoRespondersAvailableException.d.ts +7 -1
- package/dist/cjs/exceptions/NatsNoRespondersAvailableException.js +8 -3
- package/dist/cjs/exceptions/NatsNotFoundException.d.ts +7 -1
- package/dist/cjs/exceptions/NatsNotFoundException.js +8 -3
- package/dist/cjs/exceptions/NatsRequestTimeoutException.d.ts +7 -1
- package/dist/cjs/exceptions/NatsRequestTimeoutException.js +8 -3
- package/dist/esm/components/NATS.js +2 -2
- package/dist/esm/exceptions/NatsBadRequestException.js +8 -3
- package/dist/esm/exceptions/NatsForbiddenException.js +8 -3
- package/dist/esm/exceptions/NatsInternalServerException.js +8 -3
- package/dist/esm/exceptions/NatsNoRespondersAvailableException.js +8 -3
- package/dist/esm/exceptions/NatsNotFoundException.js +8 -3
- package/dist/esm/exceptions/NatsRequestTimeoutException.js +8 -3
- package/dist/types/components/NATS.d.ts +2 -2
- package/dist/types/exceptions/NatsBadRequestException.d.ts +7 -1
- package/dist/types/exceptions/NatsForbiddenException.d.ts +7 -1
- package/dist/types/exceptions/NatsInternalServerException.d.ts +7 -1
- package/dist/types/exceptions/NatsNoRespondersAvailableException.d.ts +7 -1
- package/dist/types/exceptions/NatsNotFoundException.d.ts +7 -1
- package/dist/types/exceptions/NatsRequestTimeoutException.d.ts +7 -1
- package/package.json +26 -5
package/README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# @lakutata/nats
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
English | [中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
The NATS component of the lakutata framework. It provides a connection to a NATS server to publish, subscribe and send
|
|
6
|
+
requests (with MessagePack or JSON payloads), serves an application's service channel over NATS
|
|
7
|
+
(`natsServiceEntrypoint`), offers proxies that invoke the actions of other services and listen to their events
|
|
8
|
+
(`ServiceProxy`), and relays large payloads through a JetStream object store. The umbrella package `lakutata` does not
|
|
9
|
+
re-export it: import it from `@lakutata/nats`.
|
|
8
10
|
|
|
9
11
|
## Installation
|
|
10
12
|
|
|
@@ -12,11 +14,11 @@ from `@lakutata/nats`.
|
|
|
12
14
|
npm install lakutata @lakutata/nats
|
|
13
15
|
```
|
|
14
16
|
|
|
15
|
-
It uses the NATS client `nats` (a dependency)
|
|
17
|
+
It uses the NATS client `nats` (installed as a dependency). On the server side, it needs:
|
|
16
18
|
|
|
17
|
-
- a NATS server 2.2 or later (
|
|
18
|
-
- JetStream enabled (`nats-server -js`, or `jetstream {}` in
|
|
19
|
-
component starts
|
|
19
|
+
- a NATS server 2.2 or later (for message headers, which large payloads need);
|
|
20
|
+
- JetStream enabled (`nats-server -js`, or `jetstream {}` in the server configuration) for large payloads. Without it,
|
|
21
|
+
the component still starts and prints a warning; only payloads over the server's `max_payload` then fail.
|
|
20
22
|
|
|
21
23
|
```shell
|
|
22
24
|
docker run -d --name nats -p 4222:4222 nats:2.12-alpine -js
|
|
@@ -27,7 +29,9 @@ docker run -d --name nats -p 4222:4222 nats:2.12-alpine -js
|
|
|
27
29
|
### The NATS component
|
|
28
30
|
|
|
29
31
|
Register the `NATS` component with `buildNatsClientOptions`, then get it with `getObject()` or `@Inject`. It connects
|
|
30
|
-
when it is created:
|
|
32
|
+
when it is created: when no server can be reached, its creation fails after `timeout` (20 seconds by default). The
|
|
33
|
+
application then fails to start if the component is created during the start (listed in `bootstrap`, or injected into
|
|
34
|
+
an object that is).
|
|
31
35
|
|
|
32
36
|
```typescript
|
|
33
37
|
import {Application} from 'lakutata'
|
|
@@ -55,35 +59,36 @@ Application
|
|
|
55
59
|
})
|
|
56
60
|
```
|
|
57
61
|
|
|
58
|
-
- `publish()` sends a message to every subscription of the subject (one
|
|
59
|
-
|
|
60
|
-
- `subscribe()` accepts the wildcards `*` (one token) and `>` (
|
|
61
|
-
message as it arrives, or one message after
|
|
62
|
+
- `publish()` sends a message to every subscription of the subject (only one member of each queue group receives
|
|
63
|
+
it); the message is lost when nobody is listening.
|
|
64
|
+
- `subscribe()` accepts the wildcards `*` (one token) and `>` (all remaining tokens). Its callback is called for each
|
|
65
|
+
message as it arrives, or for one message after another with `{iterator: true}`; `{max: n}` ends the subscription
|
|
62
66
|
after `n` messages. It returns the NATS `Subscription` (`unsubscribe()`, `drain()`).
|
|
63
|
-
- `request()` waits for the first response
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
`
|
|
73
|
-
`
|
|
67
|
+
- `request()` waits for the first response. Its timeout is in milliseconds and defaults to 10 minutes. When a
|
|
68
|
+
responder's callback throws, the request goes unanswered and the requester times out, unless the subscription has
|
|
69
|
+
an `errorResponse`.
|
|
70
|
+
- A lost connection is reestablished in the background (`reconnect`; `maxReconnectAttempts` is 10 attempts per server
|
|
71
|
+
by default, `-1` to retry forever). Requests sent in the meantime fail when their timeout expires. Once the client
|
|
72
|
+
gives up, every call fails with the NATS client error `CONNECTION_CLOSED`.
|
|
73
|
+
- When the application stops, the component drains its connections: messages in progress are handled and outgoing
|
|
74
|
+
messages are flushed before the connections close.
|
|
75
|
+
|
|
76
|
+
The connection options are `servers`, `codec`, `timeout`, `token`, `user`, `pass`, `debug`, `maxPingOut`,
|
|
77
|
+
`maxReconnectAttempts`, `name`, `noEcho`, `noRandomize`, `pingInterval` and `reconnect`, plus the large-payload options
|
|
78
|
+
`bulk`, `bulkBucket`, `bulkTTL` and `bulkReplicas` (see [Large payloads](#large-payloads)).
|
|
74
79
|
|
|
75
80
|
### The codecs
|
|
76
81
|
|
|
77
|
-
Every payload is encoded with the component's `codec`, the same on both sides of a subject:
|
|
82
|
+
Every payload is encoded with the component's `codec`, which must be the same on both sides of a subject:
|
|
78
83
|
|
|
79
84
|
- `messagePackCodec()` (the default): MessagePack, compact and fast;
|
|
80
|
-
- `jsonCodec()`: JSON text, readable and easy for
|
|
85
|
+
- `jsonCodec()`: JSON text, readable and easy to handle for clients written in other languages.
|
|
81
86
|
|
|
82
|
-
Both send a value as a one-element array (`[value]`) and normalize it through JSON
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
Both send a value as a one-element array (`[value]`) and first normalize it through JSON, so that clients in other
|
|
88
|
+
languages receive plain JSON data: a `Date` arrives as its ISO string, a `Buffer` as `{type: 'Buffer', data: [...]}`,
|
|
89
|
+
a class instance as a plain object, and `undefined` as `null`; a `bigint` cannot be encoded. Any object with
|
|
90
|
+
`encode(value): Uint8Array` and `decode(bytes)` can serve as the codec, such as `StringCodec()` (re-exported from
|
|
91
|
+
`nats`) for string payloads.
|
|
87
92
|
|
|
88
93
|
```typescript
|
|
89
94
|
import {Application} from 'lakutata'
|
|
@@ -100,9 +105,9 @@ Application.run({
|
|
|
100
105
|
|
|
101
106
|
### Serving the service actions over NATS
|
|
102
107
|
|
|
103
|
-
`natsServiceEntrypoint` serves the service channel
|
|
104
|
-
application's id are dispatched to the `@ServiceAction` methods
|
|
105
|
-
|
|
108
|
+
`natsServiceEntrypoint` serves the `Entrypoint` component's service channel over NATS: requests sent to the
|
|
109
|
+
application's id are dispatched to the controllers' `@ServiceAction` methods and answered with a service response
|
|
110
|
+
`{success, error, payload}`.
|
|
106
111
|
|
|
107
112
|
```typescript
|
|
108
113
|
import {Application, DTO} from 'lakutata'
|
|
@@ -145,26 +150,26 @@ Application
|
|
|
145
150
|
})
|
|
146
151
|
```
|
|
147
152
|
|
|
148
|
-
- The subject is the application id unless the `subject` option sets another;
|
|
149
|
-
`serviceId`. The
|
|
150
|
-
-
|
|
151
|
-
|
|
152
|
-
- A failed action (no matching action, invalid input, access denied, an exception) is answered with
|
|
153
|
-
|
|
153
|
+
- The subject is the application id, unless the `subject` option sets another one; proxies use the subject as their
|
|
154
|
+
`serviceId`. The events of `NATS.emitServiceEvent()` always use the application id.
|
|
155
|
+
- All instances of the service join one queue group (`{subject}.serviceQueue` by default), so each request is handled
|
|
156
|
+
by a single instance.
|
|
157
|
+
- A failed action (no matching action, invalid input, access denied, an exception) is answered with the properties of
|
|
158
|
+
its error. A request that cannot be decoded is also answered with an error, so the requester never waits for its
|
|
154
159
|
timeout.
|
|
155
|
-
- `Entrypoint.broadcast()` publishes its events under the entrypoint's subject,
|
|
156
|
-
NATS does not tell how many receive them
|
|
157
|
-
`Entrypoint.notify()` does not reach
|
|
158
|
-
- When the entrypoint stops, its subscription is drained: no new
|
|
160
|
+
- `Entrypoint.broadcast()` publishes its events to the service proxies under the entrypoint's subject, and returns 0,
|
|
161
|
+
because NATS does not tell how many clients receive them; `NATS.emitServiceEvent()` publishes under the application
|
|
162
|
+
id. `Entrypoint.notify()` does not reach NATS clients, since NATS has no client ids.
|
|
163
|
+
- When the entrypoint stops, its subscription is drained: it receives no new requests (callers retry them, see below),
|
|
159
164
|
and the requests in progress are answered.
|
|
160
|
-
-
|
|
161
|
-
their calls, as
|
|
162
|
-
(`messagePackCodec`).
|
|
165
|
+
- In 2.x it was `SetupNatsServiceEntrypoint`. Like all functions in 3.0, it was renamed without an alias, so
|
|
166
|
+
applications written for 2.x must rename their calls, as they must for `BuildServiceProxy` (now `buildServiceProxy`),
|
|
167
|
+
`JSONCodec` (`jsonCodec`) and `MessagePackCodec` (`messagePackCodec`).
|
|
163
168
|
|
|
164
169
|
### Invoking a service: the service proxy
|
|
165
170
|
|
|
166
|
-
A `ServiceProxy` invokes the actions of one remote service and listens to its events. It is a singleton provider
|
|
167
|
-
by
|
|
171
|
+
A `ServiceProxy` invokes the actions of one remote service and listens to its events. It is a singleton provider shared
|
|
172
|
+
by all requests: declare one per service with `buildServiceProxy` in the application's `providers`, as in 2.x.
|
|
168
173
|
|
|
169
174
|
```typescript
|
|
170
175
|
import {Application} from 'lakutata'
|
|
@@ -201,41 +206,44 @@ Application
|
|
|
201
206
|
})
|
|
202
207
|
```
|
|
203
208
|
|
|
204
|
-
- `invoke(input, timeout)` returns the action's result. Its timeout defaults to 10 minutes: a service
|
|
205
|
-
running fails at once, so the timeout only
|
|
206
|
-
- A request
|
|
207
|
-
again
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
209
|
+
- `invoke(input, timeout)` returns the action's result. Its timeout defaults to 10 minutes: a call to a service that is
|
|
210
|
+
not running fails at once, so the timeout only limits actions that are too slow.
|
|
211
|
+
- A request that no instance received (`NatsNoRespondersAvailableException`: the service is not running, or is
|
|
212
|
+
restarting) is sent again up to `maxRetries` times (3 by default), every `retryDelay` milliseconds (100 by default);
|
|
213
|
+
after that, the exception is thrown. Timeouts and failures of the service are never retried, because the action may
|
|
214
|
+
already have run: this way, a non-idempotent action never runs twice.
|
|
215
|
+
- A failed action is thrown as a `ServiceInvokeException`. Its message is that of the remote error, its `errno`,
|
|
216
|
+
`statusCode` and other properties are copied from the remote error, and its `service` is the service id.
|
|
217
|
+
- `on(event, listener)`, `once(event, listener)` and `off(event, listener?)` manage listeners for the events that the
|
|
218
|
+
service emits with `NATS.emitServiceEvent()`. With `on(event, listener, true)`, each event goes to only one of the
|
|
219
|
+
listeners registered this way, across all applications (a queue group). Events are delivered at most once: an
|
|
220
|
+
application that is not connected when an event is emitted misses it. The listeners registered through a proxy are
|
|
221
|
+
removed when the proxy is destroyed.
|
|
216
222
|
|
|
217
223
|
### Large payloads
|
|
218
224
|
|
|
219
|
-
A NATS message cannot exceed the server's `max_payload` (1 MiB by default). The component relays
|
|
220
|
-
responses of 90% of `max_payload` or more through a JetStream object store, over a second connection, so
|
|
221
|
-
transfers never delay
|
|
222
|
-
receiver reads the object
|
|
225
|
+
A NATS message cannot exceed the server's `max_payload` (1 MiB by default). The component relays requests and
|
|
226
|
+
responses of 90% of `max_payload` or more through a JetStream object store, over a second connection, so that large
|
|
227
|
+
transfers never delay small messages: the sender stores the encoded payload and sends a small reference, and the
|
|
228
|
+
receiver reads the object, then deletes it. Callbacks, actions and `invoke()` always see the whole value.
|
|
223
229
|
|
|
224
|
-
-
|
|
225
|
-
component prints a warning and starts without it.
|
|
226
|
-
-
|
|
227
|
-
|
|
230
|
+
- This bulk channel is on by default (`bulk: true`) and needs JetStream. When it cannot start (no JetStream, or the
|
|
231
|
+
server refuses the bucket), the component prints a warning and starts without it.
|
|
232
|
+
- Applications that exchange large payloads must share a bucket: set the same `bulkBucket` on all of them. The default
|
|
233
|
+
bucket depends on the `name` option (`lkt-bulk-{name}`, or `lkt-bulk-default` without a name), so two applications
|
|
228
234
|
with different names cannot read each other's objects (`NatsBulkException`).
|
|
229
|
-
-
|
|
230
|
-
`bulkReplicas` sets the
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
-
|
|
238
|
-
|
|
235
|
+
- Objects that are never read (the requester has gone, a response was lost) expire after `bulkTTL` (5 minutes by
|
|
236
|
+
default); `bulkReplicas` sets the number of replicas of the bucket in a cluster. Both apply when the bucket is
|
|
237
|
+
created.
|
|
238
|
+
- A large response is relayed when the requester has declared the bulk channel (its requests carry this declaration). A
|
|
239
|
+
large request is relayed when the responders support it. The component learns this from an earlier response on the
|
|
240
|
+
same subject, or else asks once with a probe of the subject (`_LKT.BULK.<subject>`): responders with the bulk channel
|
|
241
|
+
answer it and older versions ignore it, in which case the request is sent as a plain message and fails if it exceeds
|
|
242
|
+
`max_payload`.
|
|
243
|
+
- Applications without the bulk channel (`bulk: false`, or versions that predate it) keep working with the others: they
|
|
244
|
+
receive the payloads directly, and a payload over `max_payload` fails.
|
|
245
|
+
- Published messages and service events are never relayed: over `max_payload`, `publish()` and `emitServiceEvent()`
|
|
246
|
+
throw the NATS client error `MAX_PAYLOAD_EXCEEDED`.
|
|
239
247
|
|
|
240
248
|
```typescript
|
|
241
249
|
import {Application} from 'lakutata'
|
|
@@ -256,47 +264,52 @@ Application.run({
|
|
|
256
264
|
})
|
|
257
265
|
```
|
|
258
266
|
|
|
259
|
-
`NATS.bulkEnabled`, `bulkThreshold`, `bulkStatus()` and `headersSupported`
|
|
260
|
-
`putBulk()`, `getBulk()` and `deleteBulk()`
|
|
261
|
-
`docs/large-payload-design.md` (Chinese).
|
|
267
|
+
`NATS.bulkEnabled`, `bulkThreshold`, `bulkStatus()` and `headersSupported` report the state of the bulk channel;
|
|
268
|
+
`putBulk()`, `getBulk()` and `deleteBulk()` access its object store directly. The design is described in
|
|
269
|
+
`docs/large-payload-design.md` (in Chinese).
|
|
262
270
|
|
|
263
271
|
## API
|
|
264
272
|
|
|
265
273
|
| Export | What it is |
|
|
266
274
|
|---|---|
|
|
267
|
-
| `NATS` | The component: `publish`, `request`, `subscribe`, `emitServiceEvent`, `onServiceEvent`, `onceServiceEvent`, `offServiceEvent`, the bulk channel (`bulkEnabled`, `bulkThreshold`, `headersSupported`, `putBulk`, `getBulk`, `deleteBulk`, `bulkStatus`)
|
|
268
|
-
| `buildNatsClientOptions` | Builds the component options
|
|
275
|
+
| `NATS` | The component: `publish`, `request`, `subscribe`, `emitServiceEvent`, `onServiceEvent`, `onceServiceEvent`, `offServiceEvent`, the bulk channel (`bulkEnabled`, `bulkThreshold`, `headersSupported`, `putBulk`, `getBulk`, `deleteBulk`, `bulkStatus`); the `error` event |
|
|
276
|
+
| `buildNatsClientOptions` | Builds the component options for a `NATS` component |
|
|
269
277
|
| `NatsClientOptions` | Its options: the connection, the codec and the bulk channel |
|
|
270
278
|
| `SubscribeOptions` | The options of `subscribe()`: `queue`, `max`, `iterator`, `errorResponse` |
|
|
271
|
-
| `messagePackCodec`, `jsonCodec` | The codecs
|
|
279
|
+
| `messagePackCodec`, `jsonCodec` | The payload codecs |
|
|
272
280
|
| `StringCodec`, `Codec`, `Subscription`, `RetentionPolicy` | Re-exported from `nats` |
|
|
273
|
-
| `natsServiceEntrypoint` | The service adapter
|
|
281
|
+
| `natsServiceEntrypoint` | The entrypoint's service adapter over NATS |
|
|
274
282
|
| `NatsServiceEntrypointOptions` | Its options: `subject`, `queue`, `name`, `middlewares` |
|
|
275
|
-
| `ServiceProxy` | The singleton provider
|
|
276
|
-
| `buildServiceProxy` | Builds the provider options
|
|
283
|
+
| `ServiceProxy` | The singleton provider that invokes the actions of a remote service and listens to its events |
|
|
284
|
+
| `buildServiceProxy` | Builds the provider options for a `ServiceProxy` |
|
|
277
285
|
| `BuildServiceProxyOptions` | Its options: `natsComponentName`, `serviceId`, `maxRetries`, `retryDelay` |
|
|
278
286
|
| `ServiceInvokeException` and the `Nats*Exception` classes | See [Errors](#errors) |
|
|
279
287
|
|
|
280
|
-
The typings document
|
|
288
|
+
The typings document every declaration, with examples.
|
|
281
289
|
|
|
282
290
|
## Errors
|
|
283
291
|
|
|
284
292
|
| Exception | Thrown when |
|
|
285
293
|
|---|---|
|
|
286
294
|
| `ServiceInvokeException` (`E_SERVICE_INVOKE`, or the remote error's `errno`) | `ServiceProxy.invoke()`: the remote action failed; it carries the remote error's properties and the `service` id. Re-exported from `@lakutata/entrypoint` |
|
|
287
|
-
| `NatsNoRespondersAvailableException` (`E_NATS_NO_RESPONDERS_AVAILABLE`, 503) | `request()`: nobody
|
|
295
|
+
| `NatsNoRespondersAvailableException` (`E_NATS_NO_RESPONDERS_AVAILABLE`, 503) | `request()`: nobody is listening on the subject; `invoke()`, after its retries |
|
|
288
296
|
| `NatsRequestTimeoutException` (`E_NATS_REQUEST_TIMEOUT`, 408) | `request()`, `invoke()`: no response in time |
|
|
289
|
-
| `NatsBulkException` (`E_NATS_BULK`, 502) | The bulk channel failed: disabled, the object store refused a write or a read, an object expired or in another bucket.
|
|
290
|
-
| `NatsBadRequestException` (400), `NatsForbiddenException` (403), `NatsNotFoundException` (404), `NatsInternalServerException` (500) | `request()`:
|
|
291
|
-
| `
|
|
297
|
+
| `NatsBulkException` (`E_NATS_BULK`, 502) | The bulk channel failed: it is disabled, the object store refused a write or a read, or an object expired or is in another bucket. When this happens on the service side, the requester receives a `ServiceInvokeException` whose `errno` is `E_NATS_BULK` |
|
|
298
|
+
| `NatsBadRequestException` (400), `NatsForbiddenException` (403), `NatsNotFoundException` (404), `NatsInternalServerException` (500) | `request()`: a NATS client error with that code; core NATS requests do not produce them |
|
|
299
|
+
| `InvalidObjectOptionsException` (from `lakutata`) | An option of the component has an invalid value; the application fails to start |
|
|
300
|
+
| `InvalidValueException` (from `lakutata`) | The component is created without `servers` |
|
|
292
301
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
connection timeout when no server can be reached at the start.
|
|
302
|
+
Other failures are errors of the NATS client (`NatsError`, with a `code`): `MAX_PAYLOAD_EXCEEDED` for a payload over
|
|
303
|
+
`max_payload` that is not relayed, `CONNECTION_CLOSED` once the connection is closed, and `CONNECTION_REFUSED` or a
|
|
304
|
+
connection timeout when no server can be reached at the start. Codec errors (a `bigint`, a circular value) are thrown
|
|
305
|
+
as they are.
|
|
296
306
|
|
|
297
307
|
## See also
|
|
298
308
|
|
|
299
|
-
-
|
|
300
|
-
|
|
309
|
+
- The guide on the website: [NATS](https://lakutata.com/guide/NATS).
|
|
310
|
+
- `doc/en/NATS.md` in the `lakutata` package (Chinese version in `doc/zh`): the guide to NATS.
|
|
311
|
+
- `@lakutata/entrypoint` (`lakutata/com/entrypoint`, `lakutata/decorator/ctrl`): controllers, `@ServiceAction` and the
|
|
312
|
+
other transports; for patterns, see section 2 of `doc/en/ServiceCalls.md` in the `lakutata` package (Chinese version
|
|
313
|
+
in `doc/zh`).
|
|
301
314
|
- `@lakutata/grpc/service`: the same service channel and proxy over gRPC.
|
|
302
315
|
- `docs/large-payload-design.md`: the design of the large payloads.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# @lakutata/nats
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 中文
|
|
4
|
+
|
|
5
|
+
lakutata 框架的 NATS 组件。它连接 NATS 服务器,用来发布、订阅和发送请求(数据为 MessagePack 或 JSON 格式);通过 NATS 提供应用的服务通道(`natsServiceEntrypoint`);提供服务代理,用来调用其他服务的动作并监听它们的事件(`ServiceProxy`);还会通过 JetStream 的对象存储转发大数据。`lakutata` 包没有重新导出它:请从 `@lakutata/nats` 导入。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
npm install lakutata @lakutata/nats
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
它使用 NATS 客户端 `nats`(作为依赖一起安装)。服务器方面,它需要:
|
|
14
|
+
|
|
15
|
+
- NATS 服务器 2.2 或更高版本(大数据传输要用到消息头);
|
|
16
|
+
- 为大数据传输启用 JetStream(`nats-server -js`,或者在服务器配置中写 `jetstream {}`)。没有 JetStream 时,组件仍然会启动,并打印一条警告;这时只有超过服务器 `max_payload` 的数据会失败。
|
|
17
|
+
|
|
18
|
+
```shell
|
|
19
|
+
docker run -d --name nats -p 4222:4222 nats:2.12-alpine -js
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 用法
|
|
23
|
+
|
|
24
|
+
### NATS 组件
|
|
25
|
+
|
|
26
|
+
用 `buildNatsClientOptions` 注册 `NATS` 组件,然后通过 `getObject()` 或 `@Inject` 获取它。组件在创建时连接服务器:所有服务器都连不上时,创建会在 `timeout`(默认 20 秒)之后失败。如果组件是在应用启动过程中创建的(列在 `bootstrap` 里,或者注入到了这样的对象中),应用的启动也会随之失败。
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import {Application} from 'lakutata'
|
|
30
|
+
import {buildNatsClientOptions, type NATS} from '@lakutata/nats'
|
|
31
|
+
|
|
32
|
+
Application
|
|
33
|
+
.run({
|
|
34
|
+
id: 'pricing.app',
|
|
35
|
+
name: 'Pricing',
|
|
36
|
+
components: {
|
|
37
|
+
nats: buildNatsClientOptions({servers: 'nats://127.0.0.1:4222', name: 'pricing'})
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
.onLaunched(async (app: Application): Promise<void> => {
|
|
41
|
+
const nats: NATS = await app.getObject('nats')
|
|
42
|
+
//回调和订阅的失败
|
|
43
|
+
nats.on('error', (error: Error): void => console.error('NATS', error))
|
|
44
|
+
//应答者:返回值就是请求的响应;同一个队列组里的实例分担请求
|
|
45
|
+
nats.subscribe('price.get', async (input: {sku: string}): Promise<number> => input.sku.length * 10, {queue: 'pricing'})
|
|
46
|
+
//带通配符的订阅者:第二个参数是消息到达的主题
|
|
47
|
+
nats.subscribe('price.changed.*', (price: number, subject: string): void => console.log(subject, price))
|
|
48
|
+
nats.publish('price.changed.eu', 42)
|
|
49
|
+
//返回响应;没有应答者时立即抛出 NatsNoRespondersAvailableException,5 秒内没有响应时抛出 NatsRequestTimeoutException
|
|
50
|
+
console.log(await nats.request('price.get', {sku: 'ABC'}, 5000)) //30
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- `publish()` 把消息发给该主题的所有订阅(每个队列组只有一个成员收到);没有人监听时,消息就丢失了。
|
|
55
|
+
- `subscribe()` 支持通配符 `*`(一段)和 `>`(剩下的所有段)。每条消息一到达就调用回调;设置 `{iterator: true}` 时则逐条依次处理;`{max: n}` 在收到 `n` 条消息后结束订阅。它返回 NATS 的 `Subscription`(`unsubscribe()`、`drain()`)。
|
|
56
|
+
- `request()` 等待第一个响应。超时以毫秒为单位,默认 10 分钟。应答者的回调抛出错误时,请求得不到响应,请求方最终超时;除非订阅设置了 `errorResponse`。
|
|
57
|
+
- 连接断开后会在后台重新连接(`reconnect`;`maxReconnectAttempts` 默认每个服务器 10 次,`-1` 表示一直重试)。在此期间发送的请求会在超时后失败。客户端放弃重连之后,所有调用都以 NATS 客户端错误 `CONNECTION_CLOSED` 失败。
|
|
58
|
+
- 应用停止时,组件会排空它的连接:在连接关闭之前,正在处理的消息处理完,待发送的消息发送出去。
|
|
59
|
+
|
|
60
|
+
连接选项有 `servers`、`codec`、`timeout`、`token`、`user`、`pass`、`debug`、`maxPingOut`、`maxReconnectAttempts`、`name`、`noEcho`、`noRandomize`、`pingInterval` 和 `reconnect`,以及大数据传输的选项 `bulk`、`bulkBucket`、`bulkTTL` 和 `bulkReplicas`(见[大数据传输](#大数据传输))。
|
|
61
|
+
|
|
62
|
+
### 编码方式
|
|
63
|
+
|
|
64
|
+
所有数据都用组件的 `codec` 编码,同一个主题的两端必须相同:
|
|
65
|
+
|
|
66
|
+
- `messagePackCodec()`(默认):MessagePack,紧凑而且快;
|
|
67
|
+
- `jsonCodec()`:JSON 文本,可以直接阅读,也方便其他语言写的客户端处理。
|
|
68
|
+
|
|
69
|
+
两者都把值放进只有一个元素的数组(`[value]`)发送,并且先把值转成 JSON,让其他语言的客户端收到的都是普通的 JSON 数据:`Date` 变成 ISO 字符串,`Buffer` 变成 `{type: 'Buffer', data: [...]}`,类的实例变成普通对象,`undefined` 变成 `null`;`bigint` 无法编码。任何带有 `encode(value): Uint8Array` 和 `decode(bytes)` 的对象都可以作为编码方式,比如用于字符串数据的 `StringCodec()`(从 `nats` 重新导出)。
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import {Application} from 'lakutata'
|
|
73
|
+
import {buildNatsClientOptions, jsonCodec} from '@lakutata/nats'
|
|
74
|
+
|
|
75
|
+
Application.run({
|
|
76
|
+
id: 'json.app',
|
|
77
|
+
name: 'JSON',
|
|
78
|
+
components: {
|
|
79
|
+
nats: buildNatsClientOptions({servers: 'nats://127.0.0.1:4222', codec: jsonCodec()})
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 通过 NATS 提供服务动作
|
|
85
|
+
|
|
86
|
+
`natsServiceEntrypoint` 通过 NATS 提供 `Entrypoint` 组件的服务通道:发给应用 id 的请求会分派给控制器的 `@ServiceAction` 方法,并以封套 `{success, error, payload}` 响应。
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import {Application, DTO} from 'lakutata'
|
|
90
|
+
import {buildEntrypoints, Controller} from 'lakutata/com/entrypoint'
|
|
91
|
+
import {ServiceAction} from 'lakutata/decorator/ctrl'
|
|
92
|
+
import {Expect} from 'lakutata/decorator/dto'
|
|
93
|
+
import {buildNatsClientOptions, natsServiceEntrypoint, type NATS} from '@lakutata/nats'
|
|
94
|
+
|
|
95
|
+
class GetOrderDTO extends DTO {
|
|
96
|
+
@Expect(DTO.Number().integer().required())
|
|
97
|
+
public id!: number
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
class OrderController extends Controller {
|
|
101
|
+
@ServiceAction({cmd: 'order.get'}, GetOrderDTO)
|
|
102
|
+
public async get(input: GetOrderDTO): Promise<{ id: number, total: number }> {
|
|
103
|
+
return {id: input.id, total: 42}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
Application
|
|
108
|
+
.run({
|
|
109
|
+
//请求的主题,也是调用这个服务的代理所用的 serviceId
|
|
110
|
+
id: 'order.service',
|
|
111
|
+
name: 'OrderService',
|
|
112
|
+
components: {
|
|
113
|
+
nats: buildNatsClientOptions({servers: 'nats://127.0.0.1:4222'}),
|
|
114
|
+
entrypoint: buildEntrypoints({
|
|
115
|
+
controllers: [OrderController],
|
|
116
|
+
//主题为 "order.service"(应用 id),队列组为 "order.service.serviceQueue"
|
|
117
|
+
service: natsServiceEntrypoint('nats')
|
|
118
|
+
})
|
|
119
|
+
},
|
|
120
|
+
bootstrap: ['entrypoint']
|
|
121
|
+
})
|
|
122
|
+
.onLaunched(async (app: Application): Promise<void> => {
|
|
123
|
+
//服务事件:这个服务的代理如果监听了 "orderPaid",就会收到它
|
|
124
|
+
const nats: NATS = await app.getObject('nats')
|
|
125
|
+
nats.emitServiceEvent('orderPaid', 1, 42)
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- 主题是应用 id,`subject` 选项可以换成别的主题;代理把这个主题作为自己的 `serviceId`。`NATS.emitServiceEvent()` 的事件始终使用应用 id。
|
|
130
|
+
- 服务的所有实例加入同一个队列组(默认为 `{subject}.serviceQueue`),所以每个请求只由一个实例处理。
|
|
131
|
+
- 动作失败时(没有匹配的动作、输入不合法、访问被拒绝、抛出异常),响应中带有错误的各个属性。无法解码的请求也会得到错误响应,所以请求方不会一直等到超时。
|
|
132
|
+
- `Entrypoint.broadcast()` 在入口的主题下把事件发布给服务代理,并返回 0,因为 NATS 不会告诉发送方有多少客户端收到了事件;`NATS.emitServiceEvent()` 则在应用 id 下发布。`Entrypoint.notify()` 到达不了 NATS 客户端,因为 NATS 没有客户端 id。
|
|
133
|
+
- 入口停止时,它的订阅会被排空:不再接收新请求(调用方会重试,见下文),正在处理的请求会得到响应。
|
|
134
|
+
- 它在 2.x 中叫 `SetupNatsServiceEntrypoint`。与 3.0 中的所有函数一样,它改了名字,没有保留别名,所以为 2.x 编写的应用必须修改调用处的名字;`BuildServiceProxy`(现在是 `buildServiceProxy`)、`JSONCodec`(`jsonCodec`)和 `MessagePackCodec`(`messagePackCodec`)也是如此。
|
|
135
|
+
|
|
136
|
+
### 调用服务:服务代理
|
|
137
|
+
|
|
138
|
+
`ServiceProxy` 用来调用某个远端服务的动作,并监听它的事件。它是所有请求共用的单例提供者:每个服务用 `buildServiceProxy` 在应用的 `providers` 中声明一个,与 2.x 相同。
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import {Application} from 'lakutata'
|
|
142
|
+
import {
|
|
143
|
+
buildNatsClientOptions,
|
|
144
|
+
buildServiceProxy,
|
|
145
|
+
NatsRequestTimeoutException,
|
|
146
|
+
ServiceInvokeException,
|
|
147
|
+
type ServiceProxy
|
|
148
|
+
} from '@lakutata/nats'
|
|
149
|
+
|
|
150
|
+
Application
|
|
151
|
+
.run({
|
|
152
|
+
id: 'billing.app',
|
|
153
|
+
name: 'Billing',
|
|
154
|
+
components: {
|
|
155
|
+
nats: buildNatsClientOptions({servers: 'nats://127.0.0.1:4222'})
|
|
156
|
+
},
|
|
157
|
+
providers: {
|
|
158
|
+
orderService: buildServiceProxy({natsComponentName: 'nats', serviceId: 'order.service'})
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
.onLaunched(async (app: Application): Promise<void> => {
|
|
162
|
+
const orderService: ServiceProxy = await app.getObject('orderService')
|
|
163
|
+
orderService.on('orderPaid', (id: number, total: number): void => console.log(`Order ${id} paid: ${total}`))
|
|
164
|
+
try {
|
|
165
|
+
//动作的模式和输入放在同一个对象里,最多等待 30 秒
|
|
166
|
+
console.log(await orderService.invoke({cmd: 'order.get', id: 1}, 30000))
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (error instanceof ServiceInvokeException) console.error(error.service, error.errno, error.message)
|
|
169
|
+
else if (error instanceof NatsRequestTimeoutException) console.error('No response in time')
|
|
170
|
+
else throw error
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
- `invoke(input, timeout)` 返回动作的结果。timeout 默认 10 分钟:服务没有运行时调用会立即失败,所以 timeout 只用来限制太慢的动作。
|
|
176
|
+
- 如果服务没有任何实例收到请求(`NatsNoRespondersAvailableException`:服务没有运行,或者正在重启),代理会重新发送,最多 `maxRetries` 次(默认 3 次),每次间隔 `retryDelay` 毫秒(默认 100);之后抛出这个异常。超时和服务端的失败从不重试,因为动作可能已经执行过了:这样,非幂等的动作就不会执行两次。
|
|
177
|
+
- 动作失败时,代理抛出 `ServiceInvokeException`。它的消息就是远端错误的消息,`errno`、`statusCode` 和其他属性都从远端错误复制而来,`service` 是服务 id。
|
|
178
|
+
- 服务用 `NATS.emitServiceEvent()` 发出事件,`on(event, listener)`、`once(event, listener)` 和 `off(event, listener?)` 用来添加和移除这些事件的监听器。用 `on(event, listener, true)` 注册时,在所有应用中这样注册的监听器里,每个事件只发给其中一个(队列组)。事件最多送达一次:发送时没有连接的应用会错过它。代理被销毁时,通过它注册的监听器也会被移除。
|
|
179
|
+
|
|
180
|
+
### 大数据传输
|
|
181
|
+
|
|
182
|
+
一条 NATS 消息的大小不能超过服务器的 `max_payload`(默认 1 MiB)。达到 `max_payload` 90% 的请求和响应,组件会通过 JetStream 的对象存储转发,并且使用第二条连接,这样大数据的传输就不会拖慢小消息:发送方存入编码后的数据,只发送一个很小的引用;接收方读取对象后把它删除。回调、动作和 `invoke()` 拿到的始终是完整的值。
|
|
183
|
+
|
|
184
|
+
- 这个大数据通道默认开启(`bulk: true`),需要 JetStream。通道无法启动时(没有 JetStream,或者服务器拒绝了这个对象存储),组件会打印一条警告,然后不带它启动。
|
|
185
|
+
- 互相传输大数据的应用必须使用同一个对象存储:给它们设置相同的 `bulkBucket`。默认的对象存储取决于 `name` 选项(`lkt-bulk-{name}`,没有 name 时是 `lkt-bulk-default`),所以 name 不同的两个应用读不到对方的对象(`NatsBulkException`)。
|
|
186
|
+
- 一直没有被读取的对象(请求方已经离开,或者响应丢失)会在 `bulkTTL`(默认 5 分钟)后过期;`bulkReplicas` 设置对象存储在集群中的副本数。这两项在创建对象存储时生效。
|
|
187
|
+
- 只有请求方声明了大数据通道(它的请求带有这个声明),大的响应才会转发。只有应答者支持时,大的请求才会转发。组件从同一主题上之前的响应得知应答者是否支持;不知道时,就向这个主题发送一次探测(`_LKT.BULK.<subject>`):有大数据通道的应答者会回答,旧版本则会忽略。后一种情况下,请求作为普通消息发送,超过 `max_payload` 就会失败。
|
|
188
|
+
- 没有大数据通道的应用(`bulk: false`,或者更早的版本)仍然可以和其他应用一起工作:它们直接收到数据,超过 `max_payload` 的数据会失败。
|
|
189
|
+
- 发布的消息和服务事件从不经过对象存储:超过 `max_payload` 时,`publish()` 和 `emitServiceEvent()` 抛出 NATS 客户端错误 `MAX_PAYLOAD_EXCEEDED`。
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import {Application} from 'lakutata'
|
|
193
|
+
import {buildNatsClientOptions} from '@lakutata/nats'
|
|
194
|
+
|
|
195
|
+
Application.run({
|
|
196
|
+
id: 'report.service',
|
|
197
|
+
name: 'ReportService',
|
|
198
|
+
components: {
|
|
199
|
+
nats: buildNatsClientOptions({
|
|
200
|
+
servers: 'nats://127.0.0.1:4222',
|
|
201
|
+
//所有互相传输大数据的应用使用同一个对象存储
|
|
202
|
+
bulkBucket: 'lkt-bulk-shared',
|
|
203
|
+
bulkTTL: 10 * 60 * 1000,
|
|
204
|
+
bulkReplicas: 3
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
`NATS.bulkEnabled`、`bulkThreshold`、`bulkStatus()` 和 `headersSupported` 反映大数据通道的状态;`putBulk()`、`getBulk()` 和 `deleteBulk()` 直接访问它的对象存储。设计见 `docs/large-payload-design.md`。
|
|
211
|
+
|
|
212
|
+
## API
|
|
213
|
+
|
|
214
|
+
| 导出 | 说明 |
|
|
215
|
+
|---|---|
|
|
216
|
+
| `NATS` | 组件:`publish`、`request`、`subscribe`、`emitServiceEvent`、`onServiceEvent`、`onceServiceEvent`、`offServiceEvent`,大数据通道(`bulkEnabled`、`bulkThreshold`、`headersSupported`、`putBulk`、`getBulk`、`deleteBulk`、`bulkStatus`);`error` 事件 |
|
|
217
|
+
| `buildNatsClientOptions` | 构建 `NATS` 组件的选项 |
|
|
218
|
+
| `NatsClientOptions` | 它的选项:连接、编码方式和大数据通道 |
|
|
219
|
+
| `SubscribeOptions` | `subscribe()` 的选项:`queue`、`max`、`iterator`、`errorResponse` |
|
|
220
|
+
| `messagePackCodec`、`jsonCodec` | 数据的编码方式 |
|
|
221
|
+
| `StringCodec`、`Codec`、`Subscription`、`RetentionPolicy` | 从 `nats` 重新导出 |
|
|
222
|
+
| `natsServiceEntrypoint` | 入口的 NATS 服务适配器 |
|
|
223
|
+
| `NatsServiceEntrypointOptions` | 它的选项:`subject`、`queue`、`name`、`middlewares` |
|
|
224
|
+
| `ServiceProxy` | 单例提供者,调用远端服务的动作并监听它的事件 |
|
|
225
|
+
| `buildServiceProxy` | 构建 `ServiceProxy` 的提供者选项 |
|
|
226
|
+
| `BuildServiceProxyOptions` | 它的选项:`natsComponentName`、`serviceId`、`maxRetries`、`retryDelay` |
|
|
227
|
+
| `ServiceInvokeException` 和各个 `Nats*Exception` 类 | 见[错误](#错误) |
|
|
228
|
+
|
|
229
|
+
类型声明中的每一项都附有说明和示例。
|
|
230
|
+
|
|
231
|
+
## 错误
|
|
232
|
+
|
|
233
|
+
| 异常 | 什么时候抛出 |
|
|
234
|
+
|---|---|
|
|
235
|
+
| `ServiceInvokeException`(`E_SERVICE_INVOKE`,或远端错误的 `errno`) | `ServiceProxy.invoke()`:远端动作失败;它带有远端错误的属性和服务 id `service`。从 `@lakutata/entrypoint` 重新导出 |
|
|
236
|
+
| `NatsNoRespondersAvailableException`(`E_NATS_NO_RESPONDERS_AVAILABLE`,503) | `request()`:没有人监听这个主题;`invoke()`:重试之后仍然如此 |
|
|
237
|
+
| `NatsRequestTimeoutException`(`E_NATS_REQUEST_TIMEOUT`,408) | `request()`、`invoke()`:超时前没有收到响应 |
|
|
238
|
+
| `NatsBulkException`(`E_NATS_BULK`,502) | 大数据通道失败:通道已禁用,对象存储拒绝了写入或读取,或者对象已过期、在另一个对象存储中。在服务端发生时,请求方收到 `errno` 为 `E_NATS_BULK` 的 `ServiceInvokeException` |
|
|
239
|
+
| `NatsBadRequestException`(400)、`NatsForbiddenException`(403)、`NatsNotFoundException`(404)、`NatsInternalServerException`(500) | `request()`:带有对应错误码的 NATS 客户端错误;核心 NATS 的请求不会产生它们 |
|
|
240
|
+
| `InvalidObjectOptionsException`(来自 `lakutata`) | 组件的某个选项值不合法;应用启动失败 |
|
|
241
|
+
| `InvalidValueException`(来自 `lakutata`) | 创建组件时没有给出 `servers` |
|
|
242
|
+
|
|
243
|
+
其他失败都是 NATS 客户端的错误(`NatsError`,带有 `code`):数据超过 `max_payload` 又没有经过对象存储转发时为 `MAX_PAYLOAD_EXCEEDED`,连接关闭之后为 `CONNECTION_CLOSED`,启动时连不上任何服务器则为 `CONNECTION_REFUSED` 或连接超时。编码方式的错误(`bigint`、带循环引用的值)原样抛出。
|
|
244
|
+
|
|
245
|
+
## 另见
|
|
246
|
+
|
|
247
|
+
- 网站上的指南:[NATS](https://lakutata.com/zh/guide/NATS)。
|
|
248
|
+
- `lakutata` 包中的 `doc/zh/NATS.md`:NATS 指南。
|
|
249
|
+
- `@lakutata/entrypoint`(`lakutata/com/entrypoint`、`lakutata/decorator/ctrl`):控制器、`@ServiceAction` 和其他传输方式;模式见 `lakutata` 包中 `doc/zh/ServiceCalls.md` 的第 2 节。
|
|
250
|
+
- `@lakutata/grpc/service`:同样的服务通道和代理,基于 gRPC。
|
|
251
|
+
- `docs/large-payload-design.md`:大数据传输的设计。
|
|
@@ -342,8 +342,8 @@ export declare class NATS extends Component {
|
|
|
342
342
|
emitServiceEvent(eventName: string, ...args: any[]): this;
|
|
343
343
|
/**
|
|
344
344
|
* Listen to a service event of an application. A listener registered again for the same event (by this method or
|
|
345
|
-
* {@link NATS.onceServiceEvent}) is ignored. A listener which throws
|
|
346
|
-
*
|
|
345
|
+
* {@link NATS.onceServiceEvent}) is ignored. A listener which throws, or an asynchronous listener which rejects, is
|
|
346
|
+
* reported as an `'error'` event.
|
|
347
347
|
* @param serviceId The id of the application emitting the event (its `id` option).
|
|
348
348
|
* @param eventName The event name.
|
|
349
349
|
* @param listener The listener, receiving the event's arguments.
|
|
@@ -615,8 +615,8 @@ class NATS extends core_1.Component {
|
|
|
615
615
|
}
|
|
616
616
|
/**
|
|
617
617
|
* Listen to a service event of an application. A listener registered again for the same event (by this method or
|
|
618
|
-
* {@link NATS.onceServiceEvent}) is ignored. A listener which throws
|
|
619
|
-
*
|
|
618
|
+
* {@link NATS.onceServiceEvent}) is ignored. A listener which throws, or an asynchronous listener which rejects, is
|
|
619
|
+
* reported as an `'error'` event.
|
|
620
620
|
* @param serviceId The id of the application emitting the event (its `id` option).
|
|
621
621
|
* @param eventName The event name.
|
|
622
622
|
* @param listener The listener, receiving the event's arguments.
|
|
@@ -6,6 +6,12 @@ import { Exception } from '@lakutata/core';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class NatsBadRequestException extends Exception {
|
|
8
8
|
errno: string | number;
|
|
9
|
-
message: string;
|
|
10
9
|
statusCode: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create the exception: its message is "Bad Request" unless one is given.
|
|
12
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
13
|
+
* message it takes; "Bad Request" by default.
|
|
14
|
+
* @param params The parameters of the template.
|
|
15
|
+
*/
|
|
16
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
11
17
|
}
|
|
@@ -8,10 +8,15 @@ const core_1 = require("@lakutata/core");
|
|
|
8
8
|
* requests the component sends, so it is rarely seen. Its `errno` is `E_NATS_BAD_REQUEST`, its `statusCode` 400.
|
|
9
9
|
*/
|
|
10
10
|
class NatsBadRequestException extends core_1.Exception {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Create the exception: its message is "Bad Request" unless one is given.
|
|
13
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
14
|
+
* message it takes; "Bad Request" by default.
|
|
15
|
+
* @param params The parameters of the template.
|
|
16
|
+
*/
|
|
17
|
+
constructor(template, ...params) {
|
|
18
|
+
super((template ?? 'Bad Request'), ...params);
|
|
13
19
|
this.errno = 'E_NATS_BAD_REQUEST';
|
|
14
|
-
this.message = 'Bad Request';
|
|
15
20
|
this.statusCode = 400;
|
|
16
21
|
}
|
|
17
22
|
}
|
|
@@ -6,6 +6,12 @@ import { Exception } from '@lakutata/core';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class NatsForbiddenException extends Exception {
|
|
8
8
|
errno: string | number;
|
|
9
|
-
message: string;
|
|
10
9
|
statusCode: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create the exception: its message is "Forbidden" unless one is given.
|
|
12
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
13
|
+
* message it takes; "Forbidden" by default.
|
|
14
|
+
* @param params The parameters of the template.
|
|
15
|
+
*/
|
|
16
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
11
17
|
}
|
|
@@ -8,10 +8,15 @@ const core_1 = require("@lakutata/core");
|
|
|
8
8
|
* core requests the component sends, so it is rarely seen. Its `errno` is `E_NATS_FORBIDDEN`, its `statusCode` 403.
|
|
9
9
|
*/
|
|
10
10
|
class NatsForbiddenException extends core_1.Exception {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Create the exception: its message is "Forbidden" unless one is given.
|
|
13
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
14
|
+
* message it takes; "Forbidden" by default.
|
|
15
|
+
* @param params The parameters of the template.
|
|
16
|
+
*/
|
|
17
|
+
constructor(template, ...params) {
|
|
18
|
+
super((template ?? 'Forbidden'), ...params);
|
|
13
19
|
this.errno = 'E_NATS_FORBIDDEN';
|
|
14
|
-
this.message = 'Forbidden';
|
|
15
20
|
this.statusCode = 403;
|
|
16
21
|
}
|
|
17
22
|
}
|
|
@@ -7,6 +7,12 @@ import { Exception } from '@lakutata/core';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class NatsInternalServerException extends Exception {
|
|
9
9
|
errno: string | number;
|
|
10
|
-
message: string;
|
|
11
10
|
statusCode: number;
|
|
11
|
+
/**
|
|
12
|
+
* Create the exception: its message is "Internal Server Error" unless one is given.
|
|
13
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
14
|
+
* message it takes; "Internal Server Error" by default.
|
|
15
|
+
* @param params The parameters of the template.
|
|
16
|
+
*/
|
|
17
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
12
18
|
}
|
|
@@ -9,10 +9,15 @@ const core_1 = require("@lakutata/core");
|
|
|
9
9
|
* `statusCode` 500.
|
|
10
10
|
*/
|
|
11
11
|
class NatsInternalServerException extends core_1.Exception {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Create the exception: its message is "Internal Server Error" unless one is given.
|
|
14
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
15
|
+
* message it takes; "Internal Server Error" by default.
|
|
16
|
+
* @param params The parameters of the template.
|
|
17
|
+
*/
|
|
18
|
+
constructor(template, ...params) {
|
|
19
|
+
super((template ?? 'Internal Server Error'), ...params);
|
|
14
20
|
this.errno = 'E_NATS_INTERNAL_SERVER';
|
|
15
|
-
this.message = 'Internal Server Error';
|
|
16
21
|
this.statusCode = 500;
|
|
17
22
|
}
|
|
18
23
|
}
|
|
@@ -7,6 +7,12 @@ import { Exception } from '@lakutata/core';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class NatsNoRespondersAvailableException extends Exception {
|
|
9
9
|
errno: string | number;
|
|
10
|
-
message: string;
|
|
11
10
|
statusCode: number;
|
|
11
|
+
/**
|
|
12
|
+
* Create the exception: its message is "No Responders Available" unless one is given.
|
|
13
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
14
|
+
* message it takes; "No Responders Available" by default.
|
|
15
|
+
* @param params The parameters of the template.
|
|
16
|
+
*/
|
|
17
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
12
18
|
}
|
|
@@ -9,10 +9,15 @@ const core_1 = require("@lakutata/core");
|
|
|
9
9
|
* `E_NATS_NO_RESPONDERS_AVAILABLE`, its `statusCode` 503.
|
|
10
10
|
*/
|
|
11
11
|
class NatsNoRespondersAvailableException extends core_1.Exception {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Create the exception: its message is "No Responders Available" unless one is given.
|
|
14
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
15
|
+
* message it takes; "No Responders Available" by default.
|
|
16
|
+
* @param params The parameters of the template.
|
|
17
|
+
*/
|
|
18
|
+
constructor(template, ...params) {
|
|
19
|
+
super((template ?? 'No Responders Available'), ...params);
|
|
14
20
|
this.errno = 'E_NATS_NO_RESPONDERS_AVAILABLE';
|
|
15
|
-
this.message = 'No Responders Available';
|
|
16
21
|
this.statusCode = 503;
|
|
17
22
|
}
|
|
18
23
|
}
|
|
@@ -6,6 +6,12 @@ import { Exception } from '@lakutata/core';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class NatsNotFoundException extends Exception {
|
|
8
8
|
errno: string | number;
|
|
9
|
-
message: string;
|
|
10
9
|
statusCode: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create the exception: its message is "Subject Not Found" unless one is given.
|
|
12
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
13
|
+
* message it takes; "Subject Not Found" by default.
|
|
14
|
+
* @param params The parameters of the template.
|
|
15
|
+
*/
|
|
16
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
11
17
|
}
|
|
@@ -8,10 +8,15 @@ const core_1 = require("@lakutata/core");
|
|
|
8
8
|
* core requests the component sends, so it is rarely seen. Its `errno` is `E_NATS_NOT_FOUND`, its `statusCode` 404.
|
|
9
9
|
*/
|
|
10
10
|
class NatsNotFoundException extends core_1.Exception {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Create the exception: its message is "Subject Not Found" unless one is given.
|
|
13
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
14
|
+
* message it takes; "Subject Not Found" by default.
|
|
15
|
+
* @param params The parameters of the template.
|
|
16
|
+
*/
|
|
17
|
+
constructor(template, ...params) {
|
|
18
|
+
super((template ?? 'Subject Not Found'), ...params);
|
|
13
19
|
this.errno = 'E_NATS_NOT_FOUND';
|
|
14
|
-
this.message = 'Subject Not Found';
|
|
15
20
|
this.statusCode = 404;
|
|
16
21
|
}
|
|
17
22
|
}
|
|
@@ -6,6 +6,12 @@ import { Exception } from '@lakutata/core';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class NatsRequestTimeoutException extends Exception {
|
|
8
8
|
errno: string | number;
|
|
9
|
-
message: string;
|
|
10
9
|
statusCode: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create the exception: its message is "Request Timeout" unless one is given.
|
|
12
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
13
|
+
* message it takes; "Request Timeout" by default.
|
|
14
|
+
* @param params The parameters of the template.
|
|
15
|
+
*/
|
|
16
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
11
17
|
}
|
|
@@ -8,10 +8,15 @@ const core_1 = require("@lakutata/core");
|
|
|
8
8
|
* `E_NATS_REQUEST_TIMEOUT`, its `statusCode` 408.
|
|
9
9
|
*/
|
|
10
10
|
class NatsRequestTimeoutException extends core_1.Exception {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Create the exception: its message is "Request Timeout" unless one is given.
|
|
13
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
14
|
+
* message it takes; "Request Timeout" by default.
|
|
15
|
+
* @param params The parameters of the template.
|
|
16
|
+
*/
|
|
17
|
+
constructor(template, ...params) {
|
|
18
|
+
super((template ?? 'Request Timeout'), ...params);
|
|
13
19
|
this.errno = 'E_NATS_REQUEST_TIMEOUT';
|
|
14
|
-
this.message = 'Request Timeout';
|
|
15
20
|
this.statusCode = 408;
|
|
16
21
|
}
|
|
17
22
|
}
|
|
@@ -611,8 +611,8 @@ export class NATS extends Component {
|
|
|
611
611
|
}
|
|
612
612
|
/**
|
|
613
613
|
* Listen to a service event of an application. A listener registered again for the same event (by this method or
|
|
614
|
-
* {@link NATS.onceServiceEvent}) is ignored. A listener which throws
|
|
615
|
-
*
|
|
614
|
+
* {@link NATS.onceServiceEvent}) is ignored. A listener which throws, or an asynchronous listener which rejects, is
|
|
615
|
+
* reported as an `'error'` event.
|
|
616
616
|
* @param serviceId The id of the application emitting the event (its `id` option).
|
|
617
617
|
* @param eventName The event name.
|
|
618
618
|
* @param listener The listener, receiving the event's arguments.
|
|
@@ -5,10 +5,15 @@ import { Exception } from '@lakutata/core';
|
|
|
5
5
|
* requests the component sends, so it is rarely seen. Its `errno` is `E_NATS_BAD_REQUEST`, its `statusCode` 400.
|
|
6
6
|
*/
|
|
7
7
|
export class NatsBadRequestException extends Exception {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Create the exception: its message is "Bad Request" unless one is given.
|
|
10
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
11
|
+
* message it takes; "Bad Request" by default.
|
|
12
|
+
* @param params The parameters of the template.
|
|
13
|
+
*/
|
|
14
|
+
constructor(template, ...params) {
|
|
15
|
+
super((template ?? 'Bad Request'), ...params);
|
|
10
16
|
this.errno = 'E_NATS_BAD_REQUEST';
|
|
11
|
-
this.message = 'Bad Request';
|
|
12
17
|
this.statusCode = 400;
|
|
13
18
|
}
|
|
14
19
|
}
|
|
@@ -5,10 +5,15 @@ import { Exception } from '@lakutata/core';
|
|
|
5
5
|
* core requests the component sends, so it is rarely seen. Its `errno` is `E_NATS_FORBIDDEN`, its `statusCode` 403.
|
|
6
6
|
*/
|
|
7
7
|
export class NatsForbiddenException extends Exception {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Create the exception: its message is "Forbidden" unless one is given.
|
|
10
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
11
|
+
* message it takes; "Forbidden" by default.
|
|
12
|
+
* @param params The parameters of the template.
|
|
13
|
+
*/
|
|
14
|
+
constructor(template, ...params) {
|
|
15
|
+
super((template ?? 'Forbidden'), ...params);
|
|
10
16
|
this.errno = 'E_NATS_FORBIDDEN';
|
|
11
|
-
this.message = 'Forbidden';
|
|
12
17
|
this.statusCode = 403;
|
|
13
18
|
}
|
|
14
19
|
}
|
|
@@ -6,10 +6,15 @@ import { Exception } from '@lakutata/core';
|
|
|
6
6
|
* `statusCode` 500.
|
|
7
7
|
*/
|
|
8
8
|
export class NatsInternalServerException extends Exception {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Create the exception: its message is "Internal Server Error" unless one is given.
|
|
11
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
12
|
+
* message it takes; "Internal Server Error" by default.
|
|
13
|
+
* @param params The parameters of the template.
|
|
14
|
+
*/
|
|
15
|
+
constructor(template, ...params) {
|
|
16
|
+
super((template ?? 'Internal Server Error'), ...params);
|
|
11
17
|
this.errno = 'E_NATS_INTERNAL_SERVER';
|
|
12
|
-
this.message = 'Internal Server Error';
|
|
13
18
|
this.statusCode = 500;
|
|
14
19
|
}
|
|
15
20
|
}
|
|
@@ -6,10 +6,15 @@ import { Exception } from '@lakutata/core';
|
|
|
6
6
|
* `E_NATS_NO_RESPONDERS_AVAILABLE`, its `statusCode` 503.
|
|
7
7
|
*/
|
|
8
8
|
export class NatsNoRespondersAvailableException extends Exception {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Create the exception: its message is "No Responders Available" unless one is given.
|
|
11
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
12
|
+
* message it takes; "No Responders Available" by default.
|
|
13
|
+
* @param params The parameters of the template.
|
|
14
|
+
*/
|
|
15
|
+
constructor(template, ...params) {
|
|
16
|
+
super((template ?? 'No Responders Available'), ...params);
|
|
11
17
|
this.errno = 'E_NATS_NO_RESPONDERS_AVAILABLE';
|
|
12
|
-
this.message = 'No Responders Available';
|
|
13
18
|
this.statusCode = 503;
|
|
14
19
|
}
|
|
15
20
|
}
|
|
@@ -5,10 +5,15 @@ import { Exception } from '@lakutata/core';
|
|
|
5
5
|
* core requests the component sends, so it is rarely seen. Its `errno` is `E_NATS_NOT_FOUND`, its `statusCode` 404.
|
|
6
6
|
*/
|
|
7
7
|
export class NatsNotFoundException extends Exception {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Create the exception: its message is "Subject Not Found" unless one is given.
|
|
10
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
11
|
+
* message it takes; "Subject Not Found" by default.
|
|
12
|
+
* @param params The parameters of the template.
|
|
13
|
+
*/
|
|
14
|
+
constructor(template, ...params) {
|
|
15
|
+
super((template ?? 'Subject Not Found'), ...params);
|
|
10
16
|
this.errno = 'E_NATS_NOT_FOUND';
|
|
11
|
-
this.message = 'Subject Not Found';
|
|
12
17
|
this.statusCode = 404;
|
|
13
18
|
}
|
|
14
19
|
}
|
|
@@ -5,10 +5,15 @@ import { Exception } from '@lakutata/core';
|
|
|
5
5
|
* `E_NATS_REQUEST_TIMEOUT`, its `statusCode` 408.
|
|
6
6
|
*/
|
|
7
7
|
export class NatsRequestTimeoutException extends Exception {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Create the exception: its message is "Request Timeout" unless one is given.
|
|
10
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
11
|
+
* message it takes; "Request Timeout" by default.
|
|
12
|
+
* @param params The parameters of the template.
|
|
13
|
+
*/
|
|
14
|
+
constructor(template, ...params) {
|
|
15
|
+
super((template ?? 'Request Timeout'), ...params);
|
|
10
16
|
this.errno = 'E_NATS_REQUEST_TIMEOUT';
|
|
11
|
-
this.message = 'Request Timeout';
|
|
12
17
|
this.statusCode = 408;
|
|
13
18
|
}
|
|
14
19
|
}
|
|
@@ -342,8 +342,8 @@ export declare class NATS extends Component {
|
|
|
342
342
|
emitServiceEvent(eventName: string, ...args: any[]): this;
|
|
343
343
|
/**
|
|
344
344
|
* Listen to a service event of an application. A listener registered again for the same event (by this method or
|
|
345
|
-
* {@link NATS.onceServiceEvent}) is ignored. A listener which throws
|
|
346
|
-
*
|
|
345
|
+
* {@link NATS.onceServiceEvent}) is ignored. A listener which throws, or an asynchronous listener which rejects, is
|
|
346
|
+
* reported as an `'error'` event.
|
|
347
347
|
* @param serviceId The id of the application emitting the event (its `id` option).
|
|
348
348
|
* @param eventName The event name.
|
|
349
349
|
* @param listener The listener, receiving the event's arguments.
|
|
@@ -6,6 +6,12 @@ import { Exception } from '@lakutata/core';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class NatsBadRequestException extends Exception {
|
|
8
8
|
errno: string | number;
|
|
9
|
-
message: string;
|
|
10
9
|
statusCode: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create the exception: its message is "Bad Request" unless one is given.
|
|
12
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
13
|
+
* message it takes; "Bad Request" by default.
|
|
14
|
+
* @param params The parameters of the template.
|
|
15
|
+
*/
|
|
16
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
11
17
|
}
|
|
@@ -6,6 +6,12 @@ import { Exception } from '@lakutata/core';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class NatsForbiddenException extends Exception {
|
|
8
8
|
errno: string | number;
|
|
9
|
-
message: string;
|
|
10
9
|
statusCode: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create the exception: its message is "Forbidden" unless one is given.
|
|
12
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
13
|
+
* message it takes; "Forbidden" by default.
|
|
14
|
+
* @param params The parameters of the template.
|
|
15
|
+
*/
|
|
16
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
11
17
|
}
|
|
@@ -7,6 +7,12 @@ import { Exception } from '@lakutata/core';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class NatsInternalServerException extends Exception {
|
|
9
9
|
errno: string | number;
|
|
10
|
-
message: string;
|
|
11
10
|
statusCode: number;
|
|
11
|
+
/**
|
|
12
|
+
* Create the exception: its message is "Internal Server Error" unless one is given.
|
|
13
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
14
|
+
* message it takes; "Internal Server Error" by default.
|
|
15
|
+
* @param params The parameters of the template.
|
|
16
|
+
*/
|
|
17
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
12
18
|
}
|
|
@@ -7,6 +7,12 @@ import { Exception } from '@lakutata/core';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class NatsNoRespondersAvailableException extends Exception {
|
|
9
9
|
errno: string | number;
|
|
10
|
-
message: string;
|
|
11
10
|
statusCode: number;
|
|
11
|
+
/**
|
|
12
|
+
* Create the exception: its message is "No Responders Available" unless one is given.
|
|
13
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
14
|
+
* message it takes; "No Responders Available" by default.
|
|
15
|
+
* @param params The parameters of the template.
|
|
16
|
+
*/
|
|
17
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
12
18
|
}
|
|
@@ -6,6 +6,12 @@ import { Exception } from '@lakutata/core';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class NatsNotFoundException extends Exception {
|
|
8
8
|
errno: string | number;
|
|
9
|
-
message: string;
|
|
10
9
|
statusCode: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create the exception: its message is "Subject Not Found" unless one is given.
|
|
12
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
13
|
+
* message it takes; "Subject Not Found" by default.
|
|
14
|
+
* @param params The parameters of the template.
|
|
15
|
+
*/
|
|
16
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
11
17
|
}
|
|
@@ -6,6 +6,12 @@ import { Exception } from '@lakutata/core';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class NatsRequestTimeoutException extends Exception {
|
|
8
8
|
errno: string | number;
|
|
9
|
-
message: string;
|
|
10
9
|
statusCode: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create the exception: its message is "Request Timeout" unless one is given.
|
|
12
|
+
* @param template The message, or a template filled from the parameters (see `Exception`), or an error whose
|
|
13
|
+
* message it takes; "Request Timeout" by default.
|
|
14
|
+
* @param params The parameters of the template.
|
|
15
|
+
*/
|
|
16
|
+
constructor(template?: string | Error, ...params: any[]);
|
|
11
17
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakutata/nats",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "The NATS component of the lakutata framework: messaging, service proxies, service entrypoint and large payloads.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"lakutata",
|
|
7
|
+
"nats",
|
|
8
|
+
"messaging",
|
|
9
|
+
"pubsub",
|
|
10
|
+
"microservices",
|
|
11
|
+
"rpc",
|
|
12
|
+
"typescript"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://lakutata.com/packages/nats",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/lakutata/lakutata/issues",
|
|
17
|
+
"email": "admin@lakutata.com"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/lakutata/lakutata.git",
|
|
22
|
+
"directory": "packages/nats"
|
|
23
|
+
},
|
|
24
|
+
"author": "alex.ma",
|
|
25
|
+
"license": "MIT",
|
|
5
26
|
"type": "module",
|
|
6
27
|
"main": "./dist/cjs/exports/Nats.js",
|
|
7
28
|
"types": "./dist/cjs/exports/Nats.d.ts",
|
|
@@ -33,12 +54,12 @@
|
|
|
33
54
|
"nats": "^2.29.3"
|
|
34
55
|
},
|
|
35
56
|
"peerDependencies": {
|
|
36
|
-
"@lakutata/core": "3.
|
|
37
|
-
"@lakutata/entrypoint": "3.
|
|
38
|
-
"@lakutata/utils": "3.
|
|
57
|
+
"@lakutata/core": "3.1.0",
|
|
58
|
+
"@lakutata/entrypoint": "3.1.0",
|
|
59
|
+
"@lakutata/utils": "3.1.0"
|
|
39
60
|
},
|
|
40
61
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
62
|
+
"node": "^22.13.0 || >=24.11.0"
|
|
42
63
|
},
|
|
43
64
|
"files": [
|
|
44
65
|
"dist",
|