0.1.10 • Published 5 years ago

@frubana/adonis-kafka v0.1.10

Weekly downloads
23
License
-
Repository
-
Last release
5 years ago

Kafka Adonis Provider

Setup

Add kafka when your app start.

// server.js

new Ignitor(fold)
  .appRoot(__dirname)
  // Only add the next line
  .preLoad("start/kafka")
  .fireHttpServer()
  .catch(console.error);

Make sure to register the provider and make all of the following necessary changes inside the start/app.js file!

// Add the kafka provider
const providers = [
  // ...
  "@frubana/adonis-kafka/providers/Provider"
];

Config

Please update configuration before use. The configuration file is config/kafka.js.

Adding topics

// start/kafka.js

const Kafka = use("Kafka");

// Callback function
Kafka.on("topic_name", (data, commit) => {
  commit();
});

// Multiples topics with one controller.

Kafka.on("topic_name_1,topic_name_2,topic_name_3", (data, commit) => {
  commit();
});


// Controller function
Kafka.on("topic_name", "TestController.index");

Define your controller

// app/Controllers/Kafka/TestController.js

/** @type {import('@adonisjs/framework/src/Logger')} */
const Logger = use("Logger");

class TestController {
  index(data, commit) {
    Logger.info("kafka data", data);

    commit();
  }
}

module.exports = TestController;

Produce events

// app/Controllers/Http/TestController.js

const Kafka = use("Kafka");

class TestController {
  somefunction() {
    // data is a json object

    const data = {};
    Kafka.send("topicname", data);
  }
}
0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago