@venizia/ignis-docs 0.2.0 → 0.2.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.
Files changed (142) hide show
  1. package/README.md +14 -14
  2. package/content/best-practices/api-usage-examples.md +39 -19
  3. package/content/best-practices/architectural-patterns.md +22 -11
  4. package/content/best-practices/architecture-decisions.md +29 -16
  5. package/content/best-practices/code-style-standards/advanced-patterns.md +43 -31
  6. package/content/best-practices/code-style-standards/constants-configuration.md +19 -4
  7. package/content/best-practices/code-style-standards/control-flow.md +33 -1
  8. package/content/best-practices/code-style-standards/documentation.md +28 -8
  9. package/content/best-practices/code-style-standards/function-patterns.md +15 -4
  10. package/content/best-practices/code-style-standards/index.md +7 -2
  11. package/content/best-practices/code-style-standards/naming-conventions.md +26 -2
  12. package/content/best-practices/code-style-standards/route-definitions.md +9 -5
  13. package/content/best-practices/code-style-standards/tooling.md +14 -1
  14. package/content/best-practices/code-style-standards/type-safety.md +39 -6
  15. package/content/best-practices/common-pitfalls.md +59 -35
  16. package/content/best-practices/contribution-workflow.md +6 -2
  17. package/content/best-practices/data-modeling.md +78 -62
  18. package/content/best-practices/deployment-strategies.md +56 -19
  19. package/content/best-practices/error-handling.md +182 -93
  20. package/content/best-practices/index.md +6 -0
  21. package/content/best-practices/performance-optimization.md +26 -13
  22. package/content/best-practices/security-guidelines.md +35 -9
  23. package/content/best-practices/testing-strategies.md +7 -2
  24. package/content/best-practices/troubleshooting-tips.md +27 -17
  25. package/content/extensions/components/api-reference.md +107 -322
  26. package/content/extensions/components/authentication/api.md +454 -603
  27. package/content/extensions/components/authentication/errors.md +121 -498
  28. package/content/extensions/components/authentication/index.md +88 -801
  29. package/content/extensions/components/authentication/usage.md +207 -956
  30. package/content/extensions/components/authorization/api.md +736 -656
  31. package/content/extensions/components/authorization/errors.md +168 -206
  32. package/content/extensions/components/authorization/index.md +82 -797
  33. package/content/extensions/components/authorization/usage.md +194 -527
  34. package/content/extensions/components/health-check.md +71 -243
  35. package/content/extensions/components/mail/api.md +504 -287
  36. package/content/extensions/components/mail/errors.md +73 -61
  37. package/content/extensions/components/mail/index.md +96 -467
  38. package/content/extensions/components/mail/usage.md +130 -172
  39. package/content/extensions/components/request-tracker.md +66 -173
  40. package/content/extensions/components/socket-io/api.md +195 -13
  41. package/content/extensions/components/socket-io/errors.md +3 -3
  42. package/content/extensions/components/socket-io/index.md +50 -337
  43. package/content/extensions/components/socket-io/usage.md +143 -26
  44. package/content/extensions/components/static-asset/api.md +410 -142
  45. package/content/extensions/components/static-asset/errors.md +110 -53
  46. package/content/extensions/components/static-asset/index.md +79 -608
  47. package/content/extensions/components/static-asset/usage.md +180 -300
  48. package/content/extensions/components/websocket/api.md +275 -399
  49. package/content/extensions/components/websocket/errors.md +47 -56
  50. package/content/extensions/components/websocket/index.md +74 -407
  51. package/content/extensions/components/websocket/usage.md +110 -341
  52. package/content/extensions/helpers/cron/index.md +51 -160
  53. package/content/extensions/helpers/crypto/index.md +62 -483
  54. package/content/extensions/helpers/crypto/reference.md +456 -0
  55. package/content/extensions/helpers/env/index.md +60 -178
  56. package/content/extensions/helpers/error/index.md +221 -207
  57. package/content/extensions/helpers/inversion/index.md +65 -556
  58. package/content/extensions/helpers/inversion/reference.md +522 -0
  59. package/content/extensions/helpers/kafka/admin.md +20 -1
  60. package/content/extensions/helpers/kafka/compile-binary.md +41 -35
  61. package/content/extensions/helpers/kafka/consumer.md +54 -20
  62. package/content/extensions/helpers/kafka/examples.md +21 -16
  63. package/content/extensions/helpers/kafka/index.md +80 -610
  64. package/content/extensions/helpers/kafka/producer.md +134 -5
  65. package/content/extensions/helpers/kafka/schema-registry.md +45 -70
  66. package/content/extensions/helpers/logger/hf-logger.md +193 -0
  67. package/content/extensions/helpers/logger/index.md +64 -563
  68. package/content/extensions/helpers/logger/pino.md +85 -0
  69. package/content/extensions/helpers/logger/reference.md +746 -0
  70. package/content/extensions/helpers/network/api.md +241 -195
  71. package/content/extensions/helpers/network/index.md +72 -530
  72. package/content/extensions/helpers/queue/index.md +72 -900
  73. package/content/extensions/helpers/queue/reference.md +467 -0
  74. package/content/extensions/helpers/redis/index.md +73 -645
  75. package/content/extensions/helpers/redis/reference.md +727 -0
  76. package/content/extensions/helpers/secrets/index.md +66 -0
  77. package/content/extensions/helpers/socket-io/api.md +305 -203
  78. package/content/extensions/helpers/socket-io/index.md +66 -432
  79. package/content/extensions/helpers/storage/api.md +564 -462
  80. package/content/extensions/helpers/storage/index.md +77 -573
  81. package/content/extensions/helpers/types/index.md +66 -499
  82. package/content/extensions/helpers/types/reference.md +650 -0
  83. package/content/extensions/helpers/uid/index.md +58 -227
  84. package/content/extensions/helpers/websocket/api.md +329 -216
  85. package/content/extensions/helpers/websocket/index.md +65 -503
  86. package/content/extensions/helpers/worker-thread/index.md +58 -396
  87. package/content/extensions/helpers/worker-thread/reference.md +428 -0
  88. package/content/guides/core-concepts/persistent/models.md +1 -1
  89. package/content/guides/core-concepts/persistent/search-typesense.md +3 -3
  90. package/content/guides/core-concepts/persistent/transactions.md +1 -1
  91. package/content/guides/core-concepts/secrets-vault.md +177 -0
  92. package/content/guides/core-concepts/services.md +1 -1
  93. package/content/guides/migrations/redis-helpers-migration.md +1 -1
  94. package/content/guides/migrations/unified-connectors-migration.md +2 -2
  95. package/content/guides/tutorials/ecommerce-api.md +3 -8
  96. package/content/references/base/application.md +1 -1
  97. package/content/references/base/connectors.md +79 -136
  98. package/content/references/base/datasources-reference.md +599 -0
  99. package/content/references/base/datasources.md +84 -444
  100. package/content/references/base/dependency-injection.md +17 -39
  101. package/content/references/base/filter-system/application-usage.md +69 -121
  102. package/content/references/base/filter-system/array-operators.md +12 -0
  103. package/content/references/base/filter-system/comparison-operators.md +12 -0
  104. package/content/references/base/filter-system/default-filter.md +136 -348
  105. package/content/references/base/filter-system/fields-order-pagination.md +38 -16
  106. package/content/references/base/filter-system/index.md +106 -257
  107. package/content/references/base/filter-system/json-filtering.md +12 -2
  108. package/content/references/base/filter-system/list-operators.md +16 -2
  109. package/content/references/base/filter-system/logical-operators.md +13 -0
  110. package/content/references/base/filter-system/null-operators.md +13 -0
  111. package/content/references/base/filter-system/pattern-matching.md +12 -0
  112. package/content/references/base/filter-system/quick-reference.md +11 -2
  113. package/content/references/base/filter-system/range-operators.md +12 -0
  114. package/content/references/base/filter-system/tips.md +70 -133
  115. package/content/references/base/filter-system/use-cases.md +156 -233
  116. package/content/references/base/middlewares.md +35 -21
  117. package/content/references/base/models-reference.md +886 -0
  118. package/content/references/base/models.md +80 -1452
  119. package/content/references/base/repositories/advanced.md +156 -192
  120. package/content/references/base/repositories/index.md +77 -650
  121. package/content/references/base/repositories/mixins.md +22 -18
  122. package/content/references/base/repositories/relations.md +123 -171
  123. package/content/references/base/repositories/soft-deletable.md +58 -56
  124. package/content/references/base/secrets.md +263 -0
  125. package/content/references/base/services.md +2 -2
  126. package/content/references/configuration/environment-variables.md +48 -4
  127. package/content/references/configuration/index.md +49 -31
  128. package/content/references/quick-reference.md +3 -16
  129. package/content/references/utilities/crypto.md +35 -76
  130. package/content/references/utilities/date.md +33 -73
  131. package/content/references/utilities/index.md +1 -1
  132. package/content/references/utilities/jsx-reference.md +298 -0
  133. package/content/references/utilities/jsx.md +82 -525
  134. package/content/references/utilities/module.md +29 -62
  135. package/content/references/utilities/parse.md +34 -64
  136. package/content/references/utilities/performance.md +33 -58
  137. package/content/references/utilities/promise.md +28 -62
  138. package/content/references/utilities/request.md +57 -218
  139. package/content/references/utilities/schema.md +43 -137
  140. package/content/references/utilities/statuses-reference.md +361 -0
  141. package/content/references/utilities/statuses.md +63 -667
  142. package/package.json +8 -8
@@ -1,41 +1,41 @@
1
+ ---
2
+ title: Kafka - Compiling to a Single Binary
3
+ description: The platformaticWasmPlugin() Bun bundler plugin required when compiling an app that imports a Kafka helper
4
+ difficulty: advanced
5
+ ---
6
+
1
7
  # Compiling to a Single Binary
2
8
 
3
- `bun build --compile` produces a standalone executable that crashes on startup when the application
4
- imports any Kafka helper, unless the build registers `platformaticWasmPlugin`.
9
+ This page covers `platformaticWasmPlugin()`, the Bun bundler plugin required when compiling an application that imports any Kafka helper into a standalone `bun build --compile` executable.
5
10
 
6
- ```
7
- ENOENT: no such file or directory, open '/$bunfs/dist/native.wasm'
8
- ```
11
+ ## The problem
9
12
 
10
- The failure happens while the module graph is still loading -- before the IGNIS application boots, so
11
- no log line, no lifecycle hook, and no error handler of yours ever runs.
13
+ - **A compiled binary crashes on startup** if the application imports any Kafka helper and the build did not register the plugin:
12
14
 
13
- ## Why it happens
15
+ ```
16
+ ENOENT: no such file or directory, open '/$bunfs/dist/native.wasm'
17
+ ```
14
18
 
15
- `@platformatic/kafka` computes Kafka's CRC32C checksums and lz4/snappy compression in WebAssembly,
16
- through `@platformatic/wasm-utils`. The default entrypoint of that package reads the wasm payload
17
- from disk at module load time:
19
+ - **The crash happens before your code runs.** It fires while the module graph is still loading - before the IGNIS application boots, so no log line, no lifecycle hook, and no error handler of yours ever executes.
18
20
 
19
- ```javascript
20
- // @platformatic/wasm-utils/dist/index.js
21
- const wasm = readFileSync(new URL('../dist/native.wasm', import.meta.url));
22
- ```
21
+ ## Why it happens
23
22
 
24
- `bun build --compile` embeds JavaScript modules only -- assets such as `native.wasm` are not carried
25
- into the executable. Inside the binary, `import.meta.url` resolves against the virtual `/$bunfs`
26
- filesystem, the file is not there, and the read throws.
23
+ - **The codecs are WebAssembly, not native bindings.** `@platformatic/kafka` computes Kafka's CRC32C checksums and lz4/snappy compression in WebAssembly, through `@platformatic/wasm-utils`.
24
+ - **The default entrypoint reads the wasm payload from disk** at module load time:
27
25
 
28
- Running from source (`bun run`, `bun .`) is unaffected: `node_modules` is on disk, so the read
29
- succeeds. The bug only exists in compiled binaries.
26
+ ```javascript
27
+ // @platformatic/wasm-utils/dist/index.js
28
+ const wasm = readFileSync(new URL('../dist/native.wasm', import.meta.url));
29
+ ```
30
30
 
31
- ## The fix
31
+ - **`bun build --compile` embeds JavaScript modules only.** Assets such as `native.wasm` are never carried into the executable. Inside the binary, `import.meta.url` resolves against the virtual `/$bunfs` filesystem, the file isn't there, and the read throws.
32
+ - **Running from source is unaffected.** `bun run` / `bun .` keep `node_modules` on disk, so the read succeeds - the bug only exists in compiled binaries.
32
33
 
33
- `@platformatic/wasm-utils` ships a second entrypoint, `@platformatic/wasm-utils/bundled`, exposing
34
- the same API with the wasm payload inlined as base64 -- no filesystem read. `platformaticWasmPlugin`
35
- swaps one entrypoint for the other at bundle time.
34
+ ## The fix
36
35
 
37
- Compile through a Bun build script instead of the `bun build --compile` CLI, which cannot register
38
- plugins:
36
+ - **A second entrypoint ships the payload inline.** `@platformatic/wasm-utils/bundled` exposes the same API with the wasm payload inlined as base64 - no filesystem read.
37
+ - **`platformaticWasmPlugin()` swaps one entrypoint for the other** at bundle time, so the rest of your code and `@platformatic/kafka` itself need no changes.
38
+ - **Compile through a Bun build script, not the CLI.** `bun build --compile` on the command line cannot register plugins:
39
39
 
40
40
  ```typescript
41
41
  // scripts/compile.ts
@@ -67,8 +67,7 @@ if (!built.success) {
67
67
  }
68
68
  ```
69
69
 
70
- The plugin resolves `@platformatic/wasm-utils/bundled` from the importing module's own directory, so
71
- it works with hoisted and isolated `node_modules` layouts alike, and pins no package version.
70
+ - **The plugin resolves relative to the importing module's own directory** (`Bun.resolveSync` from `dirname(args.importer)`), so it works with hoisted and isolated `node_modules` layouts alike, and pins no package version.
72
71
 
73
72
  ## Verifying
74
73
 
@@ -83,10 +82,17 @@ The binary grows by roughly 76 KB, the base64 form of the 57 KB wasm module.
83
82
 
84
83
  ## Notes
85
84
 
86
- - Upgrading `@platformatic/kafka` does not remove the need for the plugin: every release to date,
87
- including 2.6.1, imports the default `@platformatic/wasm-utils` entrypoint.
88
- - Applications that never import a Kafka helper need no plugin -- nothing pulls in
89
- `@platformatic/wasm-utils`, and the plugin's resolver never fires.
90
- - Patching `node_modules` during the build achieves the same result, but mutates a dependency in
91
- place, pins the store path to one version, and leaves the tree dirty when a build fails. The
92
- plugin needs neither.
85
+ - **Upgrading `@platformatic/kafka` does not remove the need for the plugin.** Every release to date imports the default `@platformatic/wasm-utils` entrypoint.
86
+ - **Apps that never import a Kafka helper need no plugin.** Nothing pulls in `@platformatic/wasm-utils`, and the plugin's resolver never fires.
87
+ - **Patching `node_modules` during the build achieves the same result**, but mutates a dependency in place, pins the store path to one version, and leaves the tree dirty when a build fails. The plugin needs neither.
88
+
89
+ ## See also
90
+
91
+ - [Kafka Overview](./) - the four helpers this plugin protects
92
+ - [Producer](./producer) / [Consumer](./consumer) / [Admin](./admin) - any of these importing into a compiled binary triggers this caveat
93
+ - [Examples & Troubleshooting](./examples) - other Kafka connection and configuration errors
94
+
95
+ **Files:**
96
+
97
+ - [`packages/helpers/src/modules/queue/kafka/bundler/platformatic-wasm.plugin.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/helpers/src/modules/queue/kafka/bundler/platformatic-wasm.plugin.ts) - `platformaticWasmPlugin`
98
+ - [`packages/helpers/src/modules/queue/kafka/bundler/common/constants.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/helpers/src/modules/queue/kafka/bundler/common/constants.ts) - `KafkaBundlerPluginNames`, `PlatformaticWasmSpecifiers`
@@ -1,6 +1,12 @@
1
+ ---
2
+ title: Kafka Consumer
3
+ description: KafkaConsumerHelper - message callbacks, automatic reconnect, and lag monitoring
4
+ difficulty: intermediate
5
+ ---
6
+
1
7
  # Consumer
2
8
 
3
- The `KafkaConsumerHelper` wraps `@platformatic/kafka`'s `Consumer` with health tracking, graceful shutdown, message callbacks, consumer group event callbacks, and lag monitoring.
9
+ The `KafkaConsumerHelper` wraps `@platformatic/kafka`'s `Consumer` with health tracking, graceful shutdown, message callbacks, consumer group event callbacks, automatic reconnect, and lag monitoring.
4
10
 
5
11
  ```typescript
6
12
  class KafkaConsumerHelper<
@@ -18,7 +24,7 @@ class KafkaConsumerHelper<
18
24
  | `newInstance(opts)` | `static newInstance<K,V,HK,HV>(opts): KafkaConsumerHelper<K,V,HK,HV>` | Factory method |
19
25
  | `getConsumer()` | `(): Consumer<K,V,HK,HV>` | Access the underlying `Consumer` |
20
26
  | `getStream()` | `(): MessagesStream \| null` | Get the active stream (after `start()`) |
21
- | `start(opts)` | `(opts: IKafkaConsumeStartOptions): Promise<void>` | Start consuming (creates stream, wires callbacks) |
27
+ | `start(opts)` | `(opts: IKafkaConsumeStartOptions): Promise<void>` | Start consuming (creates stream, wires callbacks, drives automatic reconnect) |
22
28
  | `startLagMonitoring(opts)` | `(opts: { topics: string[]; interval?: number }): void` | Start periodic lag monitoring |
23
29
  | `stopLagMonitoring()` | `(): void` | Stop lag monitoring |
24
30
  | `isHealthy()` | `(): boolean` | `true` when at least one broker connected |
@@ -34,6 +40,8 @@ interface IKafkaConsumerOptions<KeyType, ValueType, HeaderKeyType, HeaderValueTy
34
40
  extends IKafkaConnectionOptions
35
41
  ```
36
42
 
43
+ Plus the shared [Connection & Authentication](./producer#connection--authentication) options (`bootstrapBrokers`, `clientId`, `retries`, `sasl`, `tls`, ...), documented once on the Producer page.
44
+
37
45
  ### Consumer Configuration
38
46
 
39
47
  | Option | Type | Default | Description |
@@ -47,8 +55,8 @@ interface IKafkaConsumerOptions<KeyType, ValueType, HeaderKeyType, HeaderValueTy
47
55
  | `rebalanceTimeout` | `number` | `sessionTimeout` | Max time for rebalance. Defaults to the value of `sessionTimeout` |
48
56
  | `highWaterMark` | `number` | `1024` | Stream buffer size (messages) |
49
57
  | `minBytes` | `number` | `1` | Min bytes per fetch response |
50
- | `maxBytes` | `number` | -- | Max bytes per fetch response per partition |
51
- | `maxWaitTime` | `number` | -- | Max time (ms) broker waits for `minBytes` |
58
+ | `maxBytes` | `number` | `10485760` (10 MB) | Max bytes per fetch response per partition |
59
+ | `maxWaitTime` | `number` | `5000` | Max time (ms) broker waits for `minBytes` |
52
60
  | `metadataMaxAge` | `number` | `300000` | Metadata cache TTL (ms) |
53
61
  | `groupProtocol` | `'classic' \| 'consumer'` | `'classic'` | Consumer group protocol. `'consumer'` = KIP-848 (Kafka 3.7+) |
54
62
  | `groupInstanceId` | `string` | -- | Static group membership ID -- prevents rebalance on restart |
@@ -86,8 +94,6 @@ interface IKafkaConsumerOptions<KeyType, ValueType, HeaderKeyType, HeaderValueTy
86
94
  | `onLag` | `TKafkaLagCallback` | Receives `{ lag }` (Offsets map) |
87
95
  | `onLagError` | `TKafkaLagErrorCallback` | Receives `{ error }` |
88
96
 
89
- Plus all [Connection Options](./#connection-options).
90
-
91
97
  ## Basic Example
92
98
 
93
99
  ```typescript
@@ -163,36 +169,43 @@ Stream 'error' event
163
169
  -> onMessageError({ error }) (no message available)
164
170
  ```
165
171
 
166
- - `onMessage` is the main processing callback -- do your business logic here
167
- - `onMessageDone` fires only after `onMessage` resolves successfully -- use for logging, metrics, etc.
168
- - `onMessageError` fires if `onMessage` throws -- use for error tracking. Note that errors from `onMessageDone` also trigger `onMessageError`
169
- - The stream `'error'` event also calls `onMessageError` (without `message` since it's a stream-level error), but only if `onMessageError` was provided
172
+ - **`onMessage` is the main processing callback** -- do your business logic here.
173
+ - **`onMessageDone` fires only after `onMessage` resolves successfully** -- use it for logging, metrics, and similar side effects. Note that errors thrown from `onMessageDone` also trigger `onMessageError`.
174
+ - **`onMessageError` fires if `onMessage` throws**, and also for the stream's own `'error'` event (without a `message`, since it's a stream-level error).
175
+ - **The stream `'error'` listener is always attached**, whether or not you pass `onMessageError`. An `EventEmitter` `'error'` event with zero listeners is rethrown as an uncaught exception -- without this listener, a pull-style consumer (`start()` + `getStream()`, no `onMessage`) would take the whole process down on the first broker drop.
170
176
 
171
177
  ## start()
172
178
 
173
- `start()` creates the consume stream and wires all message callbacks. It must be called explicitly after construction.
179
+ `start()` creates the consume stream and wires all message callbacks. It must be called explicitly after construction, and it guards against duplicate starts -- calling it twice logs a warning and returns immediately.
174
180
 
175
181
  ```typescript
176
182
  interface IKafkaConsumeStartOptions {
177
183
  topics: string[];
178
- mode?: MessagesStreamModeValue; // Default: 'committed'
179
- fallbackMode?: MessagesStreamFallbackModeValue; // Default: 'latest'
184
+ mode?: MessagesStreamModeValue;
185
+ fallbackMode?: MessagesStreamFallbackModeValue;
186
+ reconnectDelayMs?: number;
187
+ maxReconnectAttempts?: number;
180
188
  }
181
189
  ```
182
190
 
183
191
  | Mode | Description |
184
192
  |------|-------------|
185
- | `'committed'` | Resume from last committed offset. **Recommended for production** |
193
+ | `'committed'` (default) | Resume from last committed offset. **Recommended for production** |
186
194
  | `'latest'` | Start from the latest offset (skip existing messages) |
187
195
  | `'earliest'` | Start from the beginning of the topic |
188
196
  | `'manual'` | Start from explicitly provided offsets |
189
197
 
190
198
  | Fallback | Description |
191
199
  |----------|-------------|
192
- | `'latest'` | Start from latest (default) -- ignore historical messages |
200
+ | `'latest'` (default) | Start from latest -- ignore historical messages |
193
201
  | `'earliest'` | Start from beginning -- process all historical messages |
194
202
  | `'fail'` | Throw an error |
195
203
 
204
+ | Reconnect option | Default | Description |
205
+ |-------------------|---------|-------------|
206
+ | `reconnectDelayMs` | `2000` | Delay before each automatic reconnect attempt |
207
+ | `maxReconnectAttempts` | `5` | Consecutive reconnect attempts before the consume loop gives up |
208
+
196
209
  ```typescript
197
210
  // Production pattern
198
211
  await helper.start({ topics: ['orders'] });
@@ -200,15 +213,25 @@ await helper.start({ topics: ['orders'] });
200
213
  // Replay all historical messages
201
214
  await helper.start({ topics: ['orders'], mode: 'earliest' });
202
215
 
203
- // Custom mode
216
+ // Custom mode and reconnect budget
204
217
  await helper.start({
205
218
  topics: ['orders'],
206
219
  mode: 'committed',
207
220
  fallbackMode: 'earliest',
221
+ reconnectDelayMs: 5_000,
222
+ maxReconnectAttempts: 10,
208
223
  });
209
224
  ```
210
225
 
211
- Guards against duplicate starts -- calling `start()` twice logs a warning and returns immediately.
226
+ ## Automatic reconnect
227
+
228
+ When `onMessage` is provided, `start()` drives a background consume loop on top of the stream. That loop reconnects on its own:
229
+
230
+ - **Only the callback-driven loop reconnects.** A pull-style consumer using `getStream()` or `consumer.consume()` directly owns its own retry logic -- the helper's automatic reconnect only runs inside `startConsumeLoop`, which is wired exclusively when `onMessage` is set.
231
+ - **A full broker outage marks the session stale.** When every broker disconnects (`getConnectedBrokerCount()` drops to `0`, via `client:broker:disconnect` or `client:broker:failed`), the helper destroys the current stream immediately instead of waiting for it to error out on its own.
232
+ - **Reconnect rebuilds the client after a stale session.** The next attempt, after `reconnectDelayMs`, constructs a brand-new `@platformatic/kafka` `Consumer` with the original constructor options and swaps it in -- a fresh client forces a clean group rejoin rather than reusing session state Kafka has likely already expired. Active lag monitoring is re-armed on the new client automatically.
233
+ - **Attempts are capped.** After `maxReconnectAttempts` consecutive failures, the consume loop exits and logs an error. Message processing stops until you call `start()` again with a new set of options.
234
+ - **Every retry is logged**, including the attempt number, delay, and current connected-broker count, so a stuck reconnect loop is visible in application logs without extra instrumentation.
212
235
 
213
236
  ## Lag Monitoring
214
237
 
@@ -220,9 +243,7 @@ helper.startLagMonitoring({ topics: ['orders'], interval: 10_000 });
220
243
  helper.stopLagMonitoring();
221
244
  ```
222
245
 
223
- Lag data is delivered via the `onLag` callback. Errors via `onLagError`.
224
-
225
- Guards against duplicate starts -- calling `startLagMonitoring()` twice logs a warning.
246
+ Lag data is delivered via the `onLag` callback. Errors via `onLagError`. `interval` defaults to `30000` ms. Guards against duplicate starts -- calling `startLagMonitoring()` twice logs a warning.
226
247
 
227
248
  For one-time lag checks, use the underlying consumer directly:
228
249
 
@@ -383,3 +404,16 @@ Topic "orders" (3 partitions)
383
404
 
384
405
  > [!TIP]
385
406
  > Create topics with enough partitions for your expected parallelism. You can increase partitions later with `admin.createPartitions()`, but you cannot decrease them.
407
+
408
+ ## See also
409
+
410
+ - [Kafka Overview](./) - the four helpers, shared health/close API, and the compile-binary caveat
411
+ - [Producer](./producer) - the sending side, plus the shared Connection & Authentication options
412
+ - [Admin](./admin) - create topics and inspect consumer groups from outside the running consumer
413
+ - [Examples & Troubleshooting](./examples) - lag monitoring, exactly-once, and common connection errors
414
+
415
+ **Files:**
416
+
417
+ - [`packages/helpers/src/modules/queue/kafka/consumer.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/helpers/src/modules/queue/kafka/consumer.ts) - `KafkaConsumerHelper`, consume loop, automatic reconnect
418
+ - [`packages/helpers/src/modules/queue/kafka/base.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/helpers/src/modules/queue/kafka/base.ts) - `BaseKafkaHelper`, shared health tracking and shutdown
419
+ - [`packages/helpers/src/modules/queue/kafka/common/types.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/helpers/src/modules/queue/kafka/common/types.ts) - `IKafkaConsumerOptions`, `IKafkaConsumeStartOptions`
@@ -1,3 +1,9 @@
1
+ ---
2
+ title: Kafka Examples & Troubleshooting
3
+ description: End-to-end producer, consumer, admin, and IoC examples, plus a common-error lookup table
4
+ difficulty: intermediate
5
+ ---
6
+
1
7
  # Examples & Troubleshooting
2
8
 
3
9
  Complete examples and common issue resolution for the Kafka helpers.
@@ -260,7 +266,7 @@ import {
260
266
  KafkaAdminHelper,
261
267
  } from '@venizia/ignis-helpers/kafka';
262
268
  import { stringSerializers, stringDeserializers } from '@platformatic/kafka';
263
- import { inject, injectable } from '@venizia/ignis-inversion';
269
+ import { inject } from '@venizia/ignis-inversion';
264
270
 
265
271
  // Register helpers in the IoC container
266
272
  app.bind('kafka.producer').to(
@@ -286,7 +292,6 @@ app.bind('kafka.consumer').to(
286
292
  );
287
293
 
288
294
  // Inject into services
289
- @injectable()
290
295
  export class OrderEventService {
291
296
  constructor(
292
297
  @inject({ key: 'kafka.producer' }) private producer: KafkaProducerHelper,
@@ -342,20 +347,20 @@ environment:
342
347
  - `EXTERNAL` -- used for client connections from outside Docker
343
348
  - `CONTROLLER` -- used for KRaft controller communication
344
349
 
345
- ## See Also
350
+ ## See also
346
351
 
347
- - **Kafka Pages:**
348
- - [Overview & Fundamentals](./) -- Connection, serialization, constants, compression
349
- - [Producer](./producer) -- Producer helper, transactions, API reference
350
- - [Consumer](./consumer) -- Consumer helper, callbacks, lag monitoring, API reference
351
- - [Admin](./admin) -- Admin helper & API reference
352
- - [Schema Registry](./schema-registry) -- Schema registry helper
352
+ - [Kafka Overview](./) - the four helpers, shared health/close API, and the compile-binary caveat
353
+ - [Producer](./producer) - connection & SASL setup, serialization, compression, transactions
354
+ - [Consumer](./consumer) - message callbacks, automatic reconnect, lag monitoring
355
+ - [Admin](./admin) - topic, group, offset, ACL, and quota management
356
+ - [Schema Registry](./schema-registry) - schema-validated serialization
357
+ - [Compiling to a Single Binary](./compile-binary) - required if any example on this page ships inside a `bun build --compile` binary
358
+ - [Queue Helpers](../queue/) - BullMQ, MQTT, and the in-memory queue
359
+ - [Redis Helper](../redis/) - Redis connection management
353
360
 
354
- - **Other Helpers:**
355
- - [Queue Helper](../queue/) -- BullMQ, MQTT, and in-memory queues
356
- - [Redis Helper](../redis/) -- Redis connection management
361
+ **Files:**
357
362
 
358
- - **External Resources:**
359
- - [@platformatic/kafka](https://github.com/platformatic/kafka) -- Underlying Kafka client library
360
- - [Apache Kafka Documentation](https://kafka.apache.org/documentation/) -- Official Kafka docs
361
- - [KIP-848](https://cwiki.apache.org/confluence/display/KAFKA/KIP-848) -- New consumer group protocol
363
+ - [`packages/helpers/src/modules/queue/kafka/producer.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/helpers/src/modules/queue/kafka/producer.ts) - `KafkaProducerHelper`
364
+ - [`packages/helpers/src/modules/queue/kafka/consumer.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/helpers/src/modules/queue/kafka/consumer.ts) - `KafkaConsumerHelper`
365
+ - [`packages/helpers/src/modules/queue/kafka/admin.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/helpers/src/modules/queue/kafka/admin.ts) - `KafkaAdminHelper`
366
+ - [`packages/helpers/src/modules/queue/kafka/index.ts`](https://github.com/VENIZIA-AI/ignis/blob/main/packages/helpers/src/modules/queue/kafka/index.ts) - the `/kafka` sub-path barrel