@drarzter/kafka-client 0.10.0 → 0.11.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 +70 -2
- package/dist/{chunk-CMO7SMVK.mjs → chunk-OR7TPAAE.mjs} +110 -164
- package/dist/chunk-OR7TPAAE.mjs.map +1 -0
- package/dist/chunk-PQVBRDNV.mjs +149 -0
- package/dist/chunk-PQVBRDNV.mjs.map +1 -0
- package/dist/cli/index.js +115 -51
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +2 -1
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/kafka.client/consumer/features/delayed.d.ts.map +1 -1
- package/dist/client/kafka.client/consumer/features/dlq-replay.d.ts +1 -1
- package/dist/client/kafka.client/consumer/features/dlq-replay.d.ts.map +1 -1
- package/dist/client/kafka.client/consumer/features/snapshot.d.ts.map +1 -1
- package/dist/client/kafka.client/consumer/handler.d.ts +16 -2
- package/dist/client/kafka.client/consumer/handler.d.ts.map +1 -1
- package/dist/client/kafka.client/consumer/ops.d.ts +13 -0
- package/dist/client/kafka.client/consumer/ops.d.ts.map +1 -1
- package/dist/client/kafka.client/consumer/pipeline.d.ts +14 -13
- package/dist/client/kafka.client/consumer/pipeline.d.ts.map +1 -1
- package/dist/client/kafka.client/consumer/retry-topic.d.ts +4 -1
- package/dist/client/kafka.client/consumer/retry-topic.d.ts.map +1 -1
- package/dist/client/kafka.client/consumer/setup.d.ts +3 -0
- package/dist/client/kafka.client/consumer/setup.d.ts.map +1 -1
- package/dist/client/kafka.client/consumer/start.d.ts.map +1 -1
- package/dist/client/kafka.client/context.d.ts +3 -0
- package/dist/client/kafka.client/context.d.ts.map +1 -1
- package/dist/client/kafka.client/index.d.ts.map +1 -1
- package/dist/client/kafka.client/producer/ops.d.ts +12 -3
- package/dist/client/kafka.client/producer/ops.d.ts.map +1 -1
- package/dist/client/kafka.client/producer/send.d.ts +1 -1
- package/dist/client/message/schema-registry.d.ts +23 -4
- package/dist/client/message/schema-registry.d.ts.map +1 -1
- package/dist/client/message/serde.d.ts +68 -0
- package/dist/client/message/serde.d.ts.map +1 -0
- package/dist/client/message/topic.d.ts +25 -4
- package/dist/client/message/topic.d.ts.map +1 -1
- package/dist/client/transport/transport.interface.d.ts +6 -1
- package/dist/client/transport/transport.interface.d.ts.map +1 -1
- package/dist/client/types/config.types.d.ts +17 -0
- package/dist/client/types/config.types.d.ts.map +1 -1
- package/dist/core.d.ts +3 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +146 -55
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +9 -3
- package/dist/index.js +146 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -3
- package/dist/index.mjs.map +1 -1
- package/dist/serde.d.ts +157 -0
- package/dist/serde.d.ts.map +1 -0
- package/dist/serde.js +308 -0
- package/dist/serde.js.map +1 -0
- package/dist/serde.mjs +158 -0
- package/dist/serde.mjs.map +1 -0
- package/package.json +20 -1
- package/dist/chunk-CMO7SMVK.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ Type-safe Kafka client for Node.js. Framework-agnostic core with a first-class N
|
|
|
62
62
|
- [Lag-based producer throttling](#lag-based-producer-throttling)
|
|
63
63
|
- [Transactional consumer](#transactional-consumer)
|
|
64
64
|
- [Transactional outbox](#transactional-outbox)
|
|
65
|
+
- [Serialization: JSON, Avro, Protobuf](#serialization-json-avro-protobuf)
|
|
65
66
|
- [Schema Registry client](#schema-registry-client)
|
|
66
67
|
- [Admin API](#admin-api)
|
|
67
68
|
- [DLQ CLI](#dlq-cli)
|
|
@@ -139,7 +140,8 @@ Safe by default. Configurable when you need it. Escape hatches for when you know
|
|
|
139
140
|
- **ACL requirements helper** — `describeRequiredAcls()` enumerates every derived topic, companion group, ephemeral group, and transactional id a service needs; render them as `kafka-acls.sh` commands or an MSK IAM policy
|
|
140
141
|
- **Environment configuration** — `kafkaClientConfigFromEnv()`, `consumerOptionsFromEnv()`, and `mergeConsumerOptions()` build config from env vars with `code > env > defaults` precedence
|
|
141
142
|
- **Transactional outbox** — `startOutboxRelay()` publishes rows from a DB outbox table to Kafka inside a transaction; at-least-once with stable `eventId` for downstream dedup
|
|
142
|
-
- **
|
|
143
|
+
- **Pluggable serialization** — JSON by default; drop in `avroSerde()` / `protobufSerde()` (`@drarzter/kafka-client/serde`) for **Confluent wire-format** Avro/Protobuf and interop with Java/Go via a Schema Registry, client-wide or per-topic
|
|
144
|
+
- **Schema Registry client** — `SchemaRegistryClient` + `registrySchema()` keep locally-defined schemas in lockstep with a Confluent-compatible registry
|
|
143
145
|
- **Static group membership** — `groupInstanceId` (`group.instance.id`) skips rebalance on k8s rolling restarts within `session.timeout.ms`
|
|
144
146
|
- **DLQ CLI** — `kafka-client-dlq ls | peek | replay` for inspecting and re-publishing dead letter queues from the terminal
|
|
145
147
|
|
|
@@ -1322,6 +1324,20 @@ Passed to `KafkaModule.register()` or returned from `registerAsync()` factory:
|
|
|
1322
1324
|
| `lagThrottle.maxWaitMs` | `30000` | Max time (ms) a send waits while throttled before proceeding anyway (best-effort, not hard back-pressure) |
|
|
1323
1325
|
| `transport` | `ConfluentTransport` | Custom `KafkaTransport` implementation — target an alternative broker library or inject a deterministic fake in tests |
|
|
1324
1326
|
|
|
1327
|
+
> **Advanced — direct transport access.** `ConfluentTransport` and the full
|
|
1328
|
+
> `KafkaTransport` interface family (`IProducer`, `IConsumer`, `IAdmin`, …) are
|
|
1329
|
+
> exported from `@drarzter/kafka-client/core`. When you need low-level admin
|
|
1330
|
+
> operations the facade does not expose (e.g. per-partition watermarks), build a
|
|
1331
|
+
> transport instead of deep-importing the raw driver:
|
|
1332
|
+
>
|
|
1333
|
+
> ```typescript
|
|
1334
|
+
> import { ConfluentTransport } from '@drarzter/kafka-client/core';
|
|
1335
|
+
>
|
|
1336
|
+
> const admin = new ConfluentTransport('ops-cli', brokers).admin();
|
|
1337
|
+
> await admin.connect();
|
|
1338
|
+
> const watermarks = await admin.fetchTopicOffsets('orders'); // [{ partition, low, high }]
|
|
1339
|
+
> ```
|
|
1340
|
+
|
|
1325
1341
|
**Module-scoped** (default) — import `KafkaModule` in each module that needs it:
|
|
1326
1342
|
|
|
1327
1343
|
```typescript
|
|
@@ -2135,9 +2151,61 @@ await tx.query(
|
|
|
2135
2151
|
|
|
2136
2152
|
An `InMemoryOutboxStore` (with `.add()`, `pendingCount`, `publishedCount`) ships for tests and as executable documentation — it is **not** durable, so it does not provide the "same DB transaction as the business write" guarantee that is the whole point of the pattern. A full Postgres reference implementation lives in [`src/integration/postgres-outbox.integration.spec.ts`](./src/integration/postgres-outbox.integration.spec.ts).
|
|
2137
2153
|
|
|
2154
|
+
## Serialization: JSON, Avro, Protobuf
|
|
2155
|
+
|
|
2156
|
+
By default every message value is serialized as JSON — no configuration needed.
|
|
2157
|
+
Serialization is a pluggable seam (`MessageSerde`): swap in Avro or Protobuf
|
|
2158
|
+
with **Confluent wire format** (`[magic 0x00][4-byte schema id][payload]`) to
|
|
2159
|
+
interoperate with Java/Go producers and consumers through a Schema Registry.
|
|
2160
|
+
|
|
2161
|
+
```typescript
|
|
2162
|
+
import { KafkaClient, topic } from '@drarzter/kafka-client/core';
|
|
2163
|
+
import { avroSerde } from '@drarzter/kafka-client/serde';
|
|
2164
|
+
import { SchemaRegistryClient } from '@drarzter/kafka-client/core';
|
|
2165
|
+
|
|
2166
|
+
const registry = new SchemaRegistryClient({ baseUrl: 'http://localhost:8081' });
|
|
2167
|
+
|
|
2168
|
+
const orderSchema = {
|
|
2169
|
+
type: 'record', name: 'Order',
|
|
2170
|
+
fields: [{ name: 'orderId', type: 'string' }, { name: 'amount', type: 'int' }],
|
|
2171
|
+
};
|
|
2172
|
+
|
|
2173
|
+
// Client-wide: every value goes through Avro.
|
|
2174
|
+
const kafka = new KafkaClient('orders-svc', 'orders-grp', ['localhost:9092'], {
|
|
2175
|
+
serde: avroSerde({ registry, schema: orderSchema, autoRegister: true }),
|
|
2176
|
+
});
|
|
2177
|
+
|
|
2178
|
+
// …or per-topic (JSON elsewhere, Avro just here):
|
|
2179
|
+
const OrderCreated = topic('order.created')
|
|
2180
|
+
.serde(avroSerde({ registry, schema: orderSchema, autoRegister: true }))
|
|
2181
|
+
.type<{ orderId: string; amount: number }>();
|
|
2182
|
+
```
|
|
2183
|
+
|
|
2184
|
+
`protobufSerde({ registry, schema: protoSource, messageType: 'Order', autoRegister: true })`
|
|
2185
|
+
works the same way. `avsc` / `protobufjs` are **optional peer dependencies** —
|
|
2186
|
+
install only the one you use (`npm i avsc` or `npm i protobufjs`); a clear error
|
|
2187
|
+
tells you if it's missing.
|
|
2188
|
+
|
|
2189
|
+
**Serde options.** `registry` (required); `schema` (Avro JSON / `.proto` source —
|
|
2190
|
+
required to serialize); `subject?` (defaults to Confluent TopicNameStrategy
|
|
2191
|
+
`<topic>-value` / `<topic>-key`); `autoRegister?` (register the schema on first
|
|
2192
|
+
send to obtain its id — handy in dev; default `false` reads the latest registered
|
|
2193
|
+
schema instead). Parsed schemas and id→schema lookups are cached.
|
|
2194
|
+
|
|
2195
|
+
**Custom serde.** Implement `MessageSerde` (`serialize(value, ctx) → Buffer | string`,
|
|
2196
|
+
`deserialize(data, ctx) → value`) for MessagePack, CBOR, encryption, etc. `JsonSerde`
|
|
2197
|
+
is the default and is exported for composition.
|
|
2198
|
+
|
|
2199
|
+
**Notes & limits (v0.11):** the envelope headers (`x-event-id`, Lamport clock,
|
|
2200
|
+
`traceparent`, …) always travel as Kafka headers regardless of value serde. DLQ,
|
|
2201
|
+
retry-topic, duplicates, and delayed-relay forwarding preserve the original wire
|
|
2202
|
+
bytes losslessly, so binary formats survive every hop. Avro currently uses the
|
|
2203
|
+
writer schema as the reader schema (no reader-schema evolution yet); Protobuf
|
|
2204
|
+
supports the top-level message type only; `readSnapshot` remains JSON-only.
|
|
2205
|
+
|
|
2138
2206
|
## Schema Registry client
|
|
2139
2207
|
|
|
2140
|
-
`SchemaRegistryClient` is a minimal, dependency-free client for the Confluent Schema Registry REST API (works with Confluent Platform/Cloud, Redpanda, Karapace, and the AWS Glue SR proxy). Its scope is
|
|
2208
|
+
`SchemaRegistryClient` is a minimal, dependency-free client for the Confluent Schema Registry REST API (works with Confluent Platform/Cloud, Redpanda, Karapace, and the AWS Glue SR proxy). Its scope is **subject/version management, compatibility checks, and id→schema lookups** — used both to keep your locally-defined schemas in lockstep with a central registry and as the backing lookup for the Avro/Protobuf serdes (see [Serialization: JSON, Avro, Protobuf](#serialization-json-avro-protobuf)).
|
|
2141
2209
|
|
|
2142
2210
|
```typescript
|
|
2143
2211
|
import { SchemaRegistryClient } from '@drarzter/kafka-client/core';
|