kafkajs | A modern Apache Kafka client for node.js | Pub Sub library
kandi X-RAY | kafkajs Summary
kandi X-RAY | kafkajs Summary
A modern Apache Kafka client for Node.js Get Started » Read the Docs · Report Bug · Request Feature.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- initiate the producer .
- Create an overview page for changes .
- Help helper .
- Format extensions .
- Checks that a Kafka lock token is not met
- Create an OAuth provider provider .
kafkajs Key Features
kafkajs Examples and Code Snippets
/* eslint-disable no-console */
import { FailFast } from 'kafka-penguin';
const exampleClient = require('./clientConfig.ts');
// Set up the preferred strategy with a configured KafkaJS client
const exampleStrategy = new FailFast(2, exampleClient);
const { CompressionTypes, CompressionCodecs } = require('kafkajs')
const ZstdCodec = require('@kafkajs/zstd')
// Both compressionParams and decompressionParams are optional
const compressionParams = { level: 1 }
const decompressionParams = {}
Compr
// Add event
func addEvent(ctx context.Context, requestBody RequestBodyType) (bool, error) {
// Prepare dialer
dialer := &kafka.Dialer{
Timeout: 2 * time.Second,
DualStack: true,
}
brokers := []strin
export const waitForKafkaMessages = async (
kafka: Kafka,
messagesAmount: number,
topic: string,
fromBeginning: boolean,
groupId: string,
): Promise => {
const consumer: Consumer = kafka.consumer({ groupId })
await consume
const { Kafka } = require('kafkajs')
const kafka = new Kafka({
clientId: 'my-app',
brokers: ['192.168.1.172:9092', '192.168.1.172:9093', '192.168.1.172:9094']
})
const consumer = kafka.consumer({ groupId: 'test-group' })
const run =
Community Discussions
Trending Discussions on kafkajs
QUESTION
This app worked for a long time in docker container and recently it even doesn't launch.
In docker container I've this error:
...ANSWER
Answered 2022-Apr-07 at 18:09The @nestjs/cli
dev dependency should be up on version 8 with the rest of the @nestjs/
dependencies. @nestjs/cli
v5 doesn't have a start
command
QUESTION
I am quite new to NestJS, but really like how powerful it is so far, so I wanted to see how far I could get with using Kafka, gRPC and NestJS together.
My end goal is to have the following design, since I want to replicate my Kafka Producers:
...ANSWER
Answered 2022-Mar-13 at 22:30So, I found the answer. It seems that it is impossible to start a single microservice as a gRPC server. Indeed, whenever I turn the microservice into a hybrid application as follows:
QUESTION
I'm planning to use Kafkajs
https://kafka.js.org/ and implement it in a NodeJs server.
I would like to know what is the expected behavior in case I have 2 (or more) instances of the server running, each of them having a consumer which is configured with the same group id and topic?
Does this mean that they might read the same messages? Should I specify a unique consumer group per each server instance ?
I read this - Multiple consumers consuming from same topic but not sure it applies for Kafkajs
ANSWER
Answered 2022-Feb-10 at 15:26It's not possible for a single consumer group to have multiple consumers reading from overlapping partitions in any Kafka library. If your topic only has one partition, only one instance of your application will be consuming it, and if that instance dies, the group will rebalance and the other instance will take over (potentially reading some of the same data, due to the nature of at-least-once delivery, but it's not at the same time as the other instance)
QUESTION
When I am trying to upgrade the dependency of a sub microservice component in my own micro service component, its giving me this errror as:
...ANSWER
Answered 2022-Jan-10 at 10:35The node version I am using is 14.17.5 and in the travis the build is passing but failing while deployment. The version that they are using for travis configuration for node is 10.24.1. Will version difference cause a problem?
Yes, Node.js didn't have¹ BigInt
until version v10.4, so v10.24.1 doesn't have BigInt
.
What is the real cause?
A really out of date Node.js installation. BigInt
is relatively new in JavaScript, and older versions of JavaScript engines (like the V8 in Node.js v10.24.1) don't have it. Node.js v10.24.1 is quite old. The current versions of Node.js are v16.13.1 (LTS) and v17.3.0 (non LTS).
¹ Which is to say, didn't upgrade to a version of V8 (its JavaScript engine) that had BigInt
until v10.4.
QUESTION
I'm looking for consuming messages per batch with nestjs/microservices by using the decorator @MessagePattern('topic') or something equivalent. I would like to fetch multiple records together, process them and then, send the commit of the latest record when all the batch has been processed. I used before batch listeners in Spring Kafka to do this.
Should I use kafkajs or is there a way with nestjs/microservices ?
...ANSWER
Answered 2021-Oct-23 at 14:00I think nestJs is using kafkaJs under the hood, which does batching even if you're processing with eachMessage
. However if you need more direct control over the batch you'd use https://kafka.js.org/docs/consuming#a-name-each-batch-a-eachbatch.
QUESTION
im new to Kafka and KafkaJS.
Im trying to find a way to get the last n messages sent to a topic, instead of getting all non-consumed messages of that topic.
For example, I have a producer that produces 1 message per second and let it wait for 5 seconds.
Then, when I start the consumer, the consumer gets all 5 messages. ( Only 1 consumer running, 1 group, 1 partition, same topic as producer ).
Is there a configuration on KafkaJS to get only the last n produced messages?
...ANSWER
Answered 2021-Oct-04 at 19:14You could poll a single record, or otherwise list the offsets of the topic beforehand.
Then you can seek
a consumer to high_offset - N
and start polling from there
QUESTION
i have a js file which i want to test.
...ANSWER
Answered 2021-Oct-01 at 08:11please help me understand why i cannot mock getEnvironment function properly ?
In the test file, replace getEnvironment.mockResolvedValue('testBrokers')
with getEnvironment.mockReturnValue('testBrokers')
as the former is used to mock async functions.
Refer official documentation for more details
Make sure you mock kafkaBrokers look up for "testBrokers" as well for expected results
brokers: kafkaBrokers[getEnvironment()]
is there any difference in mocking a default imported function and mocking a named imported function ?
Ideally there are no difference in mocking them. Refer this interesting jest feature for more insights.
QUESTION
In our nest.js
application we use kafkajs client for kafka.
We need to get chance monitor statistic.
One of metrics is lag
.
Trying to figure out if kafkajs provides any and nothing interesting. (The most interesting thing in payload are: timestamp
, offset
, batchContext.firstOffset
, batchContext.firstTimestamp
, batchContext.maxTimestamp
)
Is there any ideas how to log lag
value and other statistic provided by kafkajs
?
Should I think about implementing my own statistic monitor to collect required information in node application which uses kafka.js
client?
Following documentation I can get batch.highWatermark
, where
batch.highWatermark
is the last committed offset within the topic partition. It can be useful for calculating lag.
Trying
...ANSWER
Answered 2021-Aug-28 at 08:33In general described configuration works correctly. The work corrupted by additional configuration, using eachMessage
property like:
QUESTION
I'm working in TypeScript with the KafkaJS library locally, with a single kafka broker. I've connected a producer successfully, have verified that my topic was created, and am generating messages with:
...ANSWER
Answered 2021-Aug-17 at 19:27I had failed to define log.responseFragment()
, and when I changed it to a simple log.info()
the problem was resolved.
QUESTION
We are trying to write a consumer that would subscribe to a particular topic and do some processing when a couple conditions in the data are met. One operation in the processing however can be done only once, and for the purpose of simplicity let us consider that to be a POST http request that is not idempotent.
Following are some other considerations:-
- The consumer would need to be coded in node.js and use the kafkajs library,
- The consumer would need to run on Kubernetes,
- The number of replicas would be equal to the number of producer replicas
- We will use a consumer group for our consumers
We were thinking that to make this Consumer Idempotent, we can perhaps do something like:-
...ANSWER
Answered 2021-Aug-07 at 07:00- Does the above look good for making the Consumer Idempotent?
Yes, from the POV of Idempotency, your code looks good. Since you're working with Kafka consumers, you don't need an exclusive for loop for message processing. Consumers are invoked on each message arrival. Your psuedo-code should look like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install kafkajs
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page