sentinel-kafka-manager 1.0.1 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +291 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -48,6 +48,292 @@ npm run build
48
48
  - Kafka cluster reachable from the service
49
49
  - `kafkajs` is included automatically as a dependency of this package
50
50
 
51
+ ## Create A Kafka Server With This Repo
52
+
53
+ This repository already includes a full local Kafka server setup in [docker-compose.yml](/var/www/html/matrix-project/sentinel-kafka-manager/docker-compose.yml) and sample environment values in [.env.local.example](/var/www/html/matrix-project/sentinel-kafka-manager/.env.local.example).
54
+
55
+ The stack includes:
56
+
57
+ - 3 KRaft controllers
58
+ - 3 Kafka brokers
59
+ - 1 Kafka UI instance
60
+
61
+ ### 1. Create your `.env`
62
+
63
+ Copy the example file:
64
+
65
+ ```bash
66
+ cp .env.local.example .env
67
+ ```
68
+
69
+ If you want a standard localhost setup, the example values are already suitable.
70
+
71
+ ### 2. Start the Kafka cluster
72
+
73
+ ```bash
74
+ docker compose --env-file .env up -d
75
+ ```
76
+
77
+ This creates:
78
+
79
+ - controller quorum on port `9093` inside Docker
80
+ - internal broker traffic on port `9092` inside Docker
81
+ - host-accessible broker ports `29092`, `39092`, and `49092`
82
+ - Kafka UI on `127.0.0.1:5001`
83
+
84
+ ### 3. Stop the Kafka cluster
85
+
86
+ ```bash
87
+ docker compose --env-file .env down
88
+ ```
89
+
90
+ To also remove persisted Kafka data volumes:
91
+
92
+ ```bash
93
+ docker compose --env-file .env down -v
94
+ ```
95
+
96
+ ### 4. Check container status
97
+
98
+ ```bash
99
+ docker compose --env-file .env ps
100
+ ```
101
+
102
+ ### 5. Current broker endpoints
103
+
104
+ For applications running on your host machine:
105
+
106
+ ```text
107
+ localhost:29092
108
+ localhost:39092
109
+ localhost:49092
110
+ ```
111
+
112
+ For applications running inside Docker on the same Compose network:
113
+
114
+ ```text
115
+ broker-1:9092
116
+ broker-2:9092
117
+ broker-3:9092
118
+ ```
119
+
120
+ Important:
121
+
122
+ - application clients must connect to brokers, not controllers
123
+ - controllers are internal cluster metadata nodes only
124
+ - `mode: 'external'` is for host-based apps
125
+ - `mode: 'internal'` is for Dockerized apps on the same network
126
+
127
+ ## Kafka UI Usage
128
+
129
+ The Docker stack also starts Kafka UI for cluster inspection.
130
+
131
+ ### Open the UI
132
+
133
+ Visit:
134
+
135
+ ```text
136
+ http://127.0.0.1:5001
137
+ ```
138
+
139
+ ### Login credentials
140
+
141
+ By default, the UI uses the credentials from `.env`:
142
+
143
+ ```env
144
+ KAFKA_UI_USERNAME=admin
145
+ KAFKA_UI_PASSWORD=Admin@007
146
+ ```
147
+
148
+ ### What the UI connects to
149
+
150
+ Kafka UI is preconfigured in `docker-compose.yml` to use all three brokers:
151
+
152
+ ```text
153
+ broker-1:9092,broker-2:9092,broker-3:9092
154
+ ```
155
+
156
+ The cluster name shown in the UI comes from:
157
+
158
+ ```env
159
+ KAFKA_UI_CLUSTER_NAME=Project Omni Enterprise Kafka
160
+ ```
161
+
162
+ ### What you can do in the UI
163
+
164
+ - view brokers and cluster health
165
+ - inspect topics and partitions
166
+ - browse messages
167
+ - inspect consumer groups
168
+ - check offsets and lag
169
+
170
+ ### Read-only mode
171
+
172
+ The example `.env` sets:
173
+
174
+ ```env
175
+ KAFKA_UI_READONLY=true
176
+ ```
177
+
178
+ That means the UI is intended for safe inspection only.
179
+
180
+ If you want to create topics or make changes from the UI, change it to:
181
+
182
+ ```env
183
+ KAFKA_UI_READONLY=false
184
+ ```
185
+
186
+ Then restart the stack:
187
+
188
+ ```bash
189
+ docker compose --env-file .env up -d
190
+ ```
191
+
192
+ ### Typical UI flow
193
+
194
+ 1. Start the Docker stack.
195
+ 2. Open `http://127.0.0.1:5001`.
196
+ 3. Log in with `KAFKA_UI_USERNAME` and `KAFKA_UI_PASSWORD`.
197
+ 4. Open the configured cluster.
198
+ 5. Go to Topics, Consumer Groups, or Brokers as needed.
199
+
200
+ ## Docker Compose And `.env` Reference
201
+
202
+ This project does not use a separate `Dockerfile` for Kafka. The Kafka server is created from `docker-compose.yml` and environment values from `.env`.
203
+
204
+ ### Core Kafka image and cluster identity
205
+
206
+ ```env
207
+ KAFKA_IMAGE=confluentinc/cp-kafka:7.6.6
208
+ KAFKA_CLUSTER_ID=MkU3OEVBNTcwNTJENDM2Qk
209
+ KAFKA_RESTART_POLICY=unless-stopped
210
+ KAFKA_STOP_GRACE_PERIOD=60s
211
+ KAFKA_NETWORK_NAME=kafka-network
212
+ ```
213
+
214
+ - `KAFKA_IMAGE`: Kafka container image used by controllers and brokers
215
+ - `KAFKA_CLUSTER_ID`: shared KRaft cluster id for all nodes
216
+ - `KAFKA_NETWORK_NAME`: Docker network name used by the full stack
217
+
218
+ ### Controller quorum settings
219
+
220
+ ```env
221
+ KAFKA_CONTROLLER_PORT=9093
222
+ KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER
223
+ KAFKA_CONTROLLER_QUORUM_VOTERS=1@controller-1:9093,2@controller-2:9093,3@controller-3:9093
224
+ ```
225
+
226
+ - controllers run only inside Docker
227
+ - apps should never use these controller addresses as Kafka client brokers
228
+
229
+ ### Broker listener settings
230
+
231
+ ```env
232
+ KAFKA_BROKER_BIND_ADDRESS=0.0.0.0
233
+ KAFKA_EXTERNAL_HOST=localhost
234
+ KAFKA_BROKER_INTERNAL_PORT=9092
235
+ KAFKA_BROKER_EXTERNAL_CONTAINER_PORT=19092
236
+ KAFKA_BROKER_1_EXTERNAL_PORT=29092
237
+ KAFKA_BROKER_2_EXTERNAL_PORT=39092
238
+ KAFKA_BROKER_3_EXTERNAL_PORT=49092
239
+ KAFKA_INTER_BROKER_LISTENER_NAME=INTERNAL
240
+ KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
241
+ ```
242
+
243
+ - `KAFKA_EXTERNAL_HOST=localhost` exposes brokers to your host machine
244
+ - `KAFKA_BROKER_1_EXTERNAL_PORT`, `KAFKA_BROKER_2_EXTERNAL_PORT`, and `KAFKA_BROKER_3_EXTERNAL_PORT` are the ports your local apps should use
245
+ - `KAFKA_BROKER_INTERNAL_PORT=9092` is used by containers on the Docker network
246
+
247
+ ### Replication and durability defaults
248
+
249
+ ```env
250
+ KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=3
251
+ KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=3
252
+ KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=2
253
+ KAFKA_DEFAULT_REPLICATION_FACTOR=3
254
+ KAFKA_MIN_INSYNC_REPLICAS=2
255
+ KAFKA_NUM_PARTITIONS=6
256
+ ```
257
+
258
+ These values are designed for the included three-broker cluster.
259
+
260
+ ### Broker behavior
261
+
262
+ ```env
263
+ KAFKA_AUTO_CREATE_TOPICS_ENABLE=false
264
+ KAFKA_DELETE_TOPIC_ENABLE=true
265
+ KAFKA_LOG_RETENTION_HOURS=168
266
+ KAFKA_LOG_SEGMENT_BYTES=1073741824
267
+ KAFKA_MESSAGE_MAX_BYTES=10485880
268
+ KAFKA_REPLICA_FETCH_MAX_BYTES=10485880
269
+ KAFKA_SOCKET_REQUEST_MAX_BYTES=104857600
270
+ ```
271
+
272
+ - topics are not auto-created by default
273
+ - deleting topics is allowed
274
+ - retention is 7 days by default
275
+
276
+ ### Storage and safety limits
277
+
278
+ ```env
279
+ KAFKA_LOG_DIRS=/var/lib/kafka/data
280
+ KAFKA_ULIMIT_NOFILE_SOFT=65536
281
+ KAFKA_ULIMIT_NOFILE_HARD=65536
282
+ KAFKA_LOG_MAX_SIZE=100m
283
+ KAFKA_LOG_MAX_FILE=5
284
+ ```
285
+
286
+ ### Kafka UI settings
287
+
288
+ ```env
289
+ KAFKA_UI_IMAGE=provectuslabs/kafka-ui:latest
290
+ KAFKA_UI_CONTAINER_NAME=kafka-ui
291
+ KAFKA_UI_HOSTNAME=kafka-ui
292
+ KAFKA_UI_RESTART_POLICY=unless-stopped
293
+ KAFKA_UI_BIND_ADDRESS=127.0.0.1
294
+ KAFKA_UI_PORT=5001
295
+ KAFKA_UI_DYNAMIC_CONFIG_ENABLED=false
296
+ KAFKA_UI_CLUSTER_NAME=Project Omni Enterprise Kafka
297
+ KAFKA_UI_READONLY=true
298
+ KAFKA_UI_AUTH_TYPE=LOGIN_FORM
299
+ KAFKA_UI_USERNAME=admin
300
+ KAFKA_UI_PASSWORD=Admin@007
301
+ ```
302
+
303
+ - `KAFKA_UI_BIND_ADDRESS=127.0.0.1` keeps the UI local-only
304
+ - `KAFKA_UI_PORT=5001` publishes the UI on your machine
305
+ - `KAFKA_UI_READONLY=true` prevents write actions from the UI
306
+
307
+ ### Healthcheck settings
308
+
309
+ ```env
310
+ KAFKA_HEALTHCHECK_INTERVAL=10s
311
+ KAFKA_HEALTHCHECK_TIMEOUT=5s
312
+ KAFKA_HEALTHCHECK_RETRIES=15
313
+ KAFKA_HEALTHCHECK_START_PERIOD=30s
314
+ ```
315
+
316
+ ## Creating Topics
317
+
318
+ Because `KAFKA_AUTO_CREATE_TOPICS_ENABLE=false`, topics should be created deliberately.
319
+
320
+ You have two good options:
321
+
322
+ - create topics from your service with `kafkaManager.provisionTopics()`
323
+ - allow UI-based creation by setting `KAFKA_UI_READONLY=false`
324
+
325
+ Example with this package:
326
+
327
+ ```ts
328
+ await kafkaManager.provisionTopics([
329
+ {
330
+ topic: 'claims.created',
331
+ numPartitions: 6,
332
+ replicationFactor: 3,
333
+ },
334
+ ])
335
+ ```
336
+
51
337
  ## Enterprise Features
52
338
 
53
339
  This version now includes a stronger production baseline:
@@ -907,6 +1193,11 @@ npm whoami
907
1193
 
908
1194
  ## Links
909
1195
 
1196
+ - npm deployment guide: [NPM_DEPLOYMENT.md](/var/www/html/matrix-project/sentinel-kafka-manager/NPM_DEPLOYMENT.md)
1197
+ - Example folder: [examples/service-module-usage/README.md](/var/www/html/matrix-project/sentinel-kafka-manager/examples/service-module-usage/README.md)
1198
+ - Service module guide: [SERVICE_MODULE_USAGE.md](/var/www/html/matrix-project/sentinel-kafka-manager/SERVICE_MODULE_USAGE.md)
1199
+ - GitHub: https://github.com/dilipshaw2024/sentinel-kafka-manager
1200
+ - npm: https://www.npmjs.com/package/sentinel-kafka-manager
910
1201
  - LinkedIn: https://www.linkedin.com/in/dilip-shaw-2740769/
911
1202
 
912
1203
  ## About Me
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sentinel-kafka-manager",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Reusable Kafka manager for Node.js microservices",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",