sentinel-kafka-manager 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -83
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,6 +48,64 @@ 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
|
+
## Full Service Example
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { KafkaManager } from 'sentinel-kafka-manager'
|
|
55
|
+
|
|
56
|
+
const kafkaManager = KafkaManager.fromEnv({
|
|
57
|
+
clientId: 'claims-api',
|
|
58
|
+
mode: 'external',
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
async function bootstrap(): Promise<void> {
|
|
62
|
+
await kafkaManager.provisionTopics([
|
|
63
|
+
{
|
|
64
|
+
topic: 'claims.created',
|
|
65
|
+
numPartitions: 6,
|
|
66
|
+
replicationFactor: 3,
|
|
67
|
+
},
|
|
68
|
+
])
|
|
69
|
+
|
|
70
|
+
await kafkaManager.publish({
|
|
71
|
+
topic: 'claims.created',
|
|
72
|
+
key: 'claim-1001',
|
|
73
|
+
payload: {
|
|
74
|
+
claimId: 'claim-1001',
|
|
75
|
+
source: 'claims-api',
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
await kafkaManager.runConsumer({
|
|
80
|
+
groupId: 'claims-api-group',
|
|
81
|
+
topic: 'claims.created',
|
|
82
|
+
dlqTopic: 'claims.created.dlq',
|
|
83
|
+
onMessage: async ({ message, headers }) => {
|
|
84
|
+
console.log('Received event:', {
|
|
85
|
+
traceId: headers['x-trace-id'],
|
|
86
|
+
payload: message,
|
|
87
|
+
})
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
bootstrap().catch(async (error) => {
|
|
93
|
+
console.error('Kafka bootstrap failed:', error)
|
|
94
|
+
await kafkaManager.disconnect()
|
|
95
|
+
process.exit(1)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
process.on('SIGINT', async () => {
|
|
99
|
+
await kafkaManager.disconnect()
|
|
100
|
+
process.exit(0)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
process.on('SIGTERM', async () => {
|
|
104
|
+
await kafkaManager.disconnect()
|
|
105
|
+
process.exit(0)
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
51
109
|
## Create A Kafka Server With This Repo
|
|
52
110
|
|
|
53
111
|
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).
|
|
@@ -830,64 +888,6 @@ const kafkaManager = KafkaManager.fromEnv({
|
|
|
830
888
|
|
|
831
889
|
This package is designed to work with that exact broker layout.
|
|
832
890
|
|
|
833
|
-
## Full Service Example
|
|
834
|
-
|
|
835
|
-
```ts
|
|
836
|
-
import { KafkaManager } from 'sentinel-kafka-manager'
|
|
837
|
-
|
|
838
|
-
const kafkaManager = KafkaManager.fromEnv({
|
|
839
|
-
clientId: 'claims-api',
|
|
840
|
-
mode: 'external',
|
|
841
|
-
})
|
|
842
|
-
|
|
843
|
-
async function bootstrap(): Promise<void> {
|
|
844
|
-
await kafkaManager.provisionTopics([
|
|
845
|
-
{
|
|
846
|
-
topic: 'claims.created',
|
|
847
|
-
numPartitions: 6,
|
|
848
|
-
replicationFactor: 3,
|
|
849
|
-
},
|
|
850
|
-
])
|
|
851
|
-
|
|
852
|
-
await kafkaManager.publish({
|
|
853
|
-
topic: 'claims.created',
|
|
854
|
-
key: 'claim-1001',
|
|
855
|
-
payload: {
|
|
856
|
-
claimId: 'claim-1001',
|
|
857
|
-
source: 'claims-api',
|
|
858
|
-
},
|
|
859
|
-
})
|
|
860
|
-
|
|
861
|
-
await kafkaManager.runConsumer({
|
|
862
|
-
groupId: 'claims-api-group',
|
|
863
|
-
topic: 'claims.created',
|
|
864
|
-
dlqTopic: 'claims.created.dlq',
|
|
865
|
-
onMessage: async ({ message, headers }) => {
|
|
866
|
-
console.log('Received event:', {
|
|
867
|
-
traceId: headers['x-trace-id'],
|
|
868
|
-
payload: message,
|
|
869
|
-
})
|
|
870
|
-
},
|
|
871
|
-
})
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
bootstrap().catch(async (error) => {
|
|
875
|
-
console.error('Kafka bootstrap failed:', error)
|
|
876
|
-
await kafkaManager.disconnect()
|
|
877
|
-
process.exit(1)
|
|
878
|
-
})
|
|
879
|
-
|
|
880
|
-
process.on('SIGINT', async () => {
|
|
881
|
-
await kafkaManager.disconnect()
|
|
882
|
-
process.exit(0)
|
|
883
|
-
})
|
|
884
|
-
|
|
885
|
-
process.on('SIGTERM', async () => {
|
|
886
|
-
await kafkaManager.disconnect()
|
|
887
|
-
process.exit(0)
|
|
888
|
-
})
|
|
889
|
-
```
|
|
890
|
-
|
|
891
891
|
## API Summary
|
|
892
892
|
|
|
893
893
|
### `new KafkaManager(options)`
|
|
@@ -1160,31 +1160,6 @@ For most SaaS services, the cleanest pattern is:
|
|
|
1160
1160
|
5. Catch `KafkaManagerError` and branch on `error.code`.
|
|
1161
1161
|
6. Wrap service outcomes in `OperationResponse<T>` where useful.
|
|
1162
1162
|
|
|
1163
|
-
## Publishing This Package
|
|
1164
|
-
|
|
1165
|
-
Build:
|
|
1166
|
-
|
|
1167
|
-
```bash
|
|
1168
|
-
npm run build
|
|
1169
|
-
```
|
|
1170
|
-
|
|
1171
|
-
Publish:
|
|
1172
|
-
|
|
1173
|
-
```bash
|
|
1174
|
-
npm publish
|
|
1175
|
-
```
|
|
1176
|
-
|
|
1177
|
-
If npm rejects the publish:
|
|
1178
|
-
|
|
1179
|
-
- `403` usually means authentication, 2FA, or token permission issues
|
|
1180
|
-
- `404` usually means the package name is unavailable or not publishable by your account
|
|
1181
|
-
|
|
1182
|
-
Useful check:
|
|
1183
|
-
|
|
1184
|
-
```bash
|
|
1185
|
-
npm whoami
|
|
1186
|
-
```
|
|
1187
|
-
|
|
1188
1163
|
## Notes
|
|
1189
1164
|
|
|
1190
1165
|
- Your current Kafka cluster works fine with PLAINTEXT, so SSL and SASL are optional unless your environment changes
|