@ccci/micro-server 1.0.189 → 1.0.191
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/dist/index.js +8 -2
- package/dist/utils/BaseConsumer.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -304122,19 +304122,25 @@ class BaseConsumer {
|
|
|
304122
304122
|
this.consumer = null;
|
|
304123
304123
|
}
|
|
304124
304124
|
}
|
|
304125
|
-
async subscribe(topic, messageHandler) {
|
|
304125
|
+
async subscribe(topic, messageHandler, consumerRunConfig) {
|
|
304126
304126
|
if (!this.consumer) {
|
|
304127
304127
|
throw new Error("Consumer not connected");
|
|
304128
304128
|
}
|
|
304129
304129
|
await this.consumer.subscribe({ topic, fromBeginning: true });
|
|
304130
304130
|
await this.consumer.run({
|
|
304131
|
+
autoCommit: consumerRunConfig?.autoCommit,
|
|
304132
|
+
autoCommitInterval: consumerRunConfig?.autoCommitInterval,
|
|
304133
|
+
autoCommitThreshold: consumerRunConfig?.autoCommitThreshold,
|
|
304134
|
+
eachBatchAutoResolve: consumerRunConfig?.eachBatchAutoResolve,
|
|
304135
|
+
partitionsConsumedConcurrently: consumerRunConfig?.partitionsConsumedConcurrently,
|
|
304131
304136
|
eachMessage: async ({ topic: topic2, partition, message }) => {
|
|
304132
304137
|
const parsedMessage = {
|
|
304133
304138
|
headers: message.headers,
|
|
304134
304139
|
event: message.key?.toString() || "",
|
|
304135
304140
|
data: message.value ? JSON.parse(message.value.toString()) : null
|
|
304136
304141
|
};
|
|
304137
|
-
|
|
304142
|
+
if (messageHandler)
|
|
304143
|
+
await messageHandler(parsedMessage);
|
|
304138
304144
|
await this.consumer?.commitOffsets([
|
|
304139
304145
|
{ topic: topic2, partition, offset: (Number(message.offset) + 1).toString() }
|
|
304140
304146
|
]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Consumer, type ConsumerConfig } from "kafkajs";
|
|
1
|
+
import { ConsumerRunConfig, type Consumer, type ConsumerConfig } from "kafkajs";
|
|
2
2
|
import { BaseKafka } from "./BaseKafka";
|
|
3
3
|
import type { MessageHandler } from "../types/BrokerType";
|
|
4
4
|
/**
|
|
@@ -39,6 +39,6 @@ export declare class BaseConsumer {
|
|
|
39
39
|
* @returns {Promise<void>} - A promise that resolves once the consumer has successfully subscribed and started processing messages.
|
|
40
40
|
* @throws {Error} - Throws an error if the consumer is not connected before subscribing.
|
|
41
41
|
*/
|
|
42
|
-
subscribe(topic: string, messageHandler: MessageHandler): Promise<void>;
|
|
42
|
+
subscribe(topic: string, messageHandler: MessageHandler, consumerRunConfig?: ConsumerRunConfig): Promise<void>;
|
|
43
43
|
}
|
|
44
44
|
//# sourceMappingURL=BaseConsumer.d.ts.map
|