Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function setKafka(){
/// setting up kafka consummer
console.log("Setting up Kafka clients");
Consumer = kafka.Consumer;
client = new kafka.Client('zk:2181/');
consumer = new Consumer(
client,
// payloads
[{ topic: 'speedd-fraud-actions', partition: 0, offset: 0 },
{ topic: 'speedd-fraud-out-events', partition: 0, offset: 0 }
],
// options
{fromOffset: true} // true = read messages from beginning
);
//// Setting up Kafka Producer
Producer = kafka.Producer;
producer = new Producer(client);
producer.on('ready', function () {
function setKafka(){
/// setting up kafka consummer
console.log("Setting up Kafka clients");
Consumer = kafka.Consumer;
client = new kafka.Client('localhost:2181/');
consumer = new Consumer(
client,
// payloads
[{ topic: 'speedd-traffic-actions', partition: 0, offset: 0 },
{ topic: 'speedd-traffic-out-events', partition: 0, offset: 0 }
],
// options
{fromOffset: true} // true = read messages from beginning
);
//// Setting up Kafka Producer
Producer = kafka.Producer;
producer = new Producer(client);
payloads = [
{ topic: 'speedd-out-events', messages: 'THIS IS THE NEW APP', partition: 0 }
function setKafka(){
/// setting up kafka consummer
console.log("Setting up Kafka clients");
Consumer = kafka.Consumer;
client = new kafka.Client('localhost:2181/');
consumer = new Consumer(
client,
// payloads
[{ topic: 'speedd-fraud-actions', partition: 0, offset: 0 },
{ topic: 'speedd-fraud-out-events', partition: 0, offset: 0 },
{ topic: 'speedd-fraud-in-events', partition: 0, offset: 0 }
],
// options
{fromOffset: true} // true = read messages from beginning
);
//// Setting up Kafka Producer
Producer = kafka.Producer;
producer = new Producer(client);
payloads = [
function initializeKafkaConsumer(attempt) {
try {
console.log("Try to initialize Kafka Client and Consumer, attempt " + attempt);
var client = new kafka.Client(kafkaHost + ":"+zookeeperPort+"/")
console.log("created client for " + kafkaHost);
consumer = new Consumer(
client,
[],
{ fromOffset: true }
);
console.log("Kafka Client and Consumer initialized " + consumer);
// register the handler for any messages received by the consumer on any topic it is listening to.
consumer.on('message', function (message) {
console.log("event received");
handleEventBusMessage(message);
});
consumer.on('error', function (err) {
console.log("error in creation of Kafka consumer " + JSON.stringify(err));
console.log("Try again in 5 seconds");
setTimeout(initializeKafkaConsumer, 5000, attempt + 1);
constructor(config) {
super()
this.name = pckg.name
this.version = pckg.version
this.isReady = false
this._topics = []
this._validateConfig(config)
this._clientId = config.clientId || (Math.random() * 1e32).toString(36)
this._client = new kafka.Client(config.connectionString)
this._producer = new kafka.Producer(this._client)
this._producer.on('ready', () => {
this.isReady = true
this.emit('ready')
})
this._producer.on('error', this._onError.bind(this))
this._consumer = new kafka.Consumer(this._client, [])
this._consumer.on('message', this._onMessage.bind(this))
this._consumer.on('error', this._onError.bind(this))
this._consumer.on('offsetOutOfRange', this._onError.bind(this))
}
var kafka = require('kafka-node'),
HighLevelProducer = kafka.HighLevelProducer,
client = new kafka.Client(),
producer = new HighLevelProducer(client);
module.exports = function(chatServer) {
producer.on('ready', function () {
chatServer.on('sendMessage', function (message) {
var messageString = JSON.stringify(message);
console.log('Sending message ' + messageString );
var kafkaMessage = {
topic: 'chatmessages',
messages : messageString
};
producer.send([kafkaMessage], function (err, data) {
var kafka = require("kafka-node");
import envVariables from "../envVariables";
const Producer = kafka.Producer;
let client;
if (process.env.NODE_ENV === "development") {
client = new kafka.Client();
console.log("local Producer- ");
} else {
client = new kafka.KafkaClient({ kafkaHost: envVariables.KAFKA_BROKER_HOST });
console.log("cloud Producer- ");
}
const producer = new Producer(client);
producer.on("ready", function() {
console.log("Producer is ready");
});
producer.on("error", function(err) {
console.log("Producer is in error state");
console.log(err);
});
function createProducer (next) {
var opts = yaktor.kafka.client
client = new kafka.Client(opts.connectionString, opts.clientId, opts.zkOptions, opts.noAckBatchOptions, opts.sslOptions)
producer = new kafka.Producer(client, yaktor.kafka.producer)
producer.once('ready', next)
producer.once('error', next)
},
function resetErrorListeners (next) {
getClient(): any {
return new kafka.Client(this.config.connString, this.config.clientId);
}
var KafkaClient = function(name, config){
MessagingClient.call(this, name, config);
this.connectionClient = kafka.Client(config.host+':'+config.port+'/', name);
this.kafkaConsumer = new kafka.HighLevelConsumer(this.connectionClient, [{topic: config.topic}], {groupId: config.topic});
this.kafkaConsumer.on('error', function() {});
this.kafkaProducer = new kafka.HighLevelProducer(this.connectionClient);
this.kafkaProducer.on('error', function() {});
};