@djpfs/kafka-adonisjs
v1.1.1
Published
Kafka Provider for AdonisJs
Downloads
42
Maintainers
Readme
npm i @djpfs/kafka-adonisjs
node ace configure @djpfs/kafka-adonisjs
Edit the .env
file to match your Kafka configuration.
Edit the config/kafka.js
file to edit the default configuration.
// file: start/kafka.js
import Kafka from '@ioc:Message/Kafka'
Kafka.admin.listTopics().then((topics: any[]) => {
console.log('topics', topics);
});
// file: start/kafka.js
import Kafka from '@ioc:Message/Kafka'
Kafka.admin.createTopics({
topics: [
{
topic: 'messages',
numPartitions: 1,
replicationFactor: 1,
},
],
waitForLeaders: true,
}).then((result: any) => {
console.log('result', result);
});
import Kafka from '@ioc:Message/Kafka'
Kafka.on('messages', (data: any, commit: any) => {
console.log(data)
// commit(false) // For error transaction
commit() // For successful transaction
});
import Kafka from "@ioc:Message/Kafka";
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export default class UserController {
public async show({ params }: HttpContextContract) {
return Kafka.send('messages', { user_id: params.id })
}
}
import Kafka from '@ioc:Message/Kafka'
Kafka.admin.describeCluster().then((result: any) => {
console.log('result', result);
});
Demo
You can find a demo project here.