You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
``Describe the bug
i have tried to send a message on Kafka but unable to connect Kafka To Reproduce
Please provide either a link to a:
my code look like
`import { Kafka } from 'kafkajs';
import ip from 'ip';
// Get the host IP, defaulting to localhost
const host = process.env.HOST_IP || ip.address();
// Function to create and connect Kafka producer
const createAndConnectProducer = async () => {
const kafka = new Kafka({
clientId: 'my-app',
brokers: [`${host}:9092`], // Specify Kafka broker address
});
const producer = kafka.producer();
try {
await producer.connect();
console.log('Kafka producer connected successfully!');
} catch (error) {
console.error('Failed to connect to Kafka:', error);
}
console.log(producer , 'producer.event.CONNECTED')
return producer;
};
// Function to send a message to Kafka
const sendKafkaMessage = async (producer, topic, message) => {
try {
console.log(producer, topic, message,'producer, topic, message)')
await producer.send({
topic,
messages: [
{ value: 'Hello Kafka' }
]
});
console.log('Message sent successfully:', message);
} catch (error) {
console.error('Failed to send message to Kafka:', error);
}
};
// Function to produce a message dynamically
const produceKafkaMessages = async (topic, message) => {
const producer = await createAndConnectProducer();
await sendKafkaMessage(producer, topic, message);
await producer.disconnect();
};
export default produceKafkaMessages;
// To use the producer:
// produceKafkaMessages('my-topic', 'my-message');
`
but i always got error
`{"level":"ERROR","timestamp":"2024-10-24T19:30:35.110Z","logger":"kafkajs","message":"[BrokerPool] Failed to connect to seed broker, trying another broker from the list: Failed to connect: net.connect is not a function","retryCount":4,"retryTime":6874}`
and
`kafka-producer.js:20 Failed to connect to Kafka: KafkaJSNumberOfRetriesExceeded: Failed to connect: net.connect is not a function`
and
Failed to send message to Kafka: KafkaJSError: The producer is disconnected
at validateConnectionStatus (messageProducer.js:31:15)
at sendBatch (messageProducer.js:82:5)
at Object.send (messageProducer.js:120:12)
at sendKafkaMessage (kafka-producer.js:30:20)
at produceKafkaMessages (kafka-producer.js:46:9
The text was updated successfully, but these errors were encountered:
Adil7767
changed the title
un able to connect kafka in next js client side
unable to connect kafka in next js client side
Oct 24, 2024
``Describe the bug
i have tried to send a message on Kafka but unable to connect Kafka
To Reproduce
Please provide either a link to a:
my code look like
but i always got error
and
The text was updated successfully, but these errors were encountered: