Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose javaInit method to futher extend functionality on client side #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sbansal6
Copy link

@sbansal6 sbansal6 commented Mar 7, 2018

I need access to kafka admin utils to do some admin work. Exposing javaInit method makes it much easier to extend functionality.

const javaInit = require('kafka-java-bridge').javaInit;
const java = javaInit.getJavaInstance()

Example:-
const adminUtils = java.import("kafka.admin.AdminUtils")
const ZKStringSerializer = java.import("kafka.utils.ZKStringSerializer$")
const ZKUtils = java.import("kafka.utils.ZkUtils")
const ZkClient = java.import("org.I0Itec.zkclient.ZkClient")
const zkClient = new ZkClient(${kafkaConf.host}:${kafkaConf.port}, 10 * 1000, 8 * 1000, ZKStringSerializer.MODULE$)
const topicProperties = java.newInstanceSync("java.util.Properties")

/**

  • Creates a topic with specified number of partitions and replication factor
  • It is a Synchronous method
  • @param name {string} - name of the topic
  • @param numPartitions {number}
  • @param replicationFactor {number}
  • @returns void
    */
    function createTopic(name, numPartitions, replicationFactor) {
    try {
    adminUtils.createTopicSync(zkClient, name, numPartitions, replicationFactor,topicProperties)
    } catch (ex) {
    throw ex
    }
    }

Saurabh Bansal and others added 2 commits March 7, 2018 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant