@platformatic/kafka 0.3.0 → 0.4.1
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.
|
@@ -85,7 +85,7 @@ export class MessagesStream extends Readable {
|
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
87
|
if (consumer[kPrometheus]) {
|
|
88
|
-
this.#metricsConsumedMessages = ensureMetric(consumer[kPrometheus], 'Counter', '
|
|
88
|
+
this.#metricsConsumedMessages = ensureMetric(consumer[kPrometheus], 'Counter', 'kafka_consumed_messages', 'Number of consumed Kafka messages');
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
close(callback) {
|
|
@@ -269,12 +269,12 @@ export class MessagesStream extends Readable {
|
|
|
269
269
|
const firstTimestamp = records.firstTimestamp;
|
|
270
270
|
const leaderEpoch = metadata.topics.get(topic).partitions[partition].leaderEpoch;
|
|
271
271
|
for (const record of records.records) {
|
|
272
|
-
const key = keyDeserializer(record.key);
|
|
273
|
-
const value = valueDeserializer(record.value);
|
|
274
272
|
const headers = new Map();
|
|
275
273
|
for (const [headerKey, headerValue] of record.headers) {
|
|
276
274
|
headers.set(headerKeyDeserializer(headerKey), headerValueDeserializer(headerValue));
|
|
277
275
|
}
|
|
276
|
+
const key = keyDeserializer(record.key, headers);
|
|
277
|
+
const value = valueDeserializer(record.value, headers);
|
|
278
278
|
this.#metricsConsumedMessages?.inc();
|
|
279
279
|
canPush = this.push({
|
|
280
280
|
key,
|
|
@@ -159,8 +159,19 @@ export class Producer extends Base {
|
|
|
159
159
|
const messages = [];
|
|
160
160
|
for (const message of options.messages) {
|
|
161
161
|
const topic = message.topic;
|
|
162
|
-
|
|
163
|
-
const
|
|
162
|
+
let headers = new Map();
|
|
163
|
+
const serializedHeaders = new Map();
|
|
164
|
+
if (message.headers) {
|
|
165
|
+
headers =
|
|
166
|
+
message.headers instanceof Map
|
|
167
|
+
? message.headers
|
|
168
|
+
: new Map(Object.entries(message.headers));
|
|
169
|
+
for (const [key, value] of headers) {
|
|
170
|
+
serializedHeaders.set(this.#headerKeySerializer(key), this.#headerValueSerializer(value));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const key = this.#keySerializer(message.key, headers);
|
|
174
|
+
const value = this.#valueSerializer(message.value, headers);
|
|
164
175
|
let partition = 0;
|
|
165
176
|
if (typeof message.partition !== 'number') {
|
|
166
177
|
if (partitioner) {
|
|
@@ -177,17 +188,11 @@ export class Producer extends Base {
|
|
|
177
188
|
else {
|
|
178
189
|
partition = message.partition;
|
|
179
190
|
}
|
|
180
|
-
if (message.headers) {
|
|
181
|
-
const entries = message.headers instanceof Map ? message.headers : Object.entries(message.headers);
|
|
182
|
-
for (const [key, value] of entries) {
|
|
183
|
-
headers.set(this.#headerKeySerializer(key), this.#headerValueSerializer(value));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
191
|
topics.add(topic);
|
|
187
192
|
messages.push({
|
|
188
193
|
key,
|
|
189
|
-
value
|
|
190
|
-
headers,
|
|
194
|
+
value,
|
|
195
|
+
headers: serializedHeaders,
|
|
191
196
|
topic,
|
|
192
197
|
partition,
|
|
193
198
|
timestamp: message.timestamp
|
package/dist/clients/serde.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
export type Serializer<InputType = unknown> = (data?: InputType) => Buffer | undefined;
|
|
2
2
|
export type Deserializer<OutputType = unknown> = (data?: Buffer) => OutputType | undefined;
|
|
3
|
+
export type SerializerWithHeaders<InputType = unknown, HeaderKey = unknown, HeaderValue = unknown> = (data?: InputType, headers?: Map<HeaderKey, HeaderValue>) => Buffer | undefined;
|
|
4
|
+
export type DeserializerWithHeaders<OutputType = unknown, HeaderKey = unknown, HeaderValue = unknown> = (data?: Buffer, headers?: Map<HeaderKey, HeaderValue>) => OutputType | undefined;
|
|
3
5
|
export interface Serializers<Key, Value, HeaderKey, HeaderValue> {
|
|
4
|
-
key:
|
|
5
|
-
value:
|
|
6
|
+
key: SerializerWithHeaders<Key, HeaderKey, HeaderValue>;
|
|
7
|
+
value: SerializerWithHeaders<Value, HeaderKey, HeaderValue>;
|
|
6
8
|
headerKey: Serializer<HeaderKey>;
|
|
7
9
|
headerValue: Serializer<HeaderValue>;
|
|
8
10
|
}
|
|
9
11
|
export interface Deserializers<Key, Value, HeaderKey, HeaderValue> {
|
|
10
|
-
key:
|
|
11
|
-
value:
|
|
12
|
+
key: DeserializerWithHeaders<Key>;
|
|
13
|
+
value: DeserializerWithHeaders<Value>;
|
|
12
14
|
headerKey: Deserializer<HeaderKey>;
|
|
13
15
|
headerValue: Deserializer<HeaderValue>;
|
|
14
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/kafka",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Modern and performant client for Apache Kafka",
|
|
5
5
|
"homepage": "https://github.com/platformatic/kafka",
|
|
6
6
|
"author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
|