currently I am evaluating different Messaging Systems. There is a question related to Apache Kafka which I could not answer myself.
Is it possible for a Kafka producer t
From java you can create a topic, if needed. Whether it's recommended or not, depends on the use-case. E.g. if your topic name is a function of the incoming payload to the producer, it might be useful. Following is the code snippet that works in kafka 0.10.x
void createTopic(String zookeeperConnect, String topicName) throws InterruptedException {
int sessionTimeoutMs = ;
int connectionTimeoutMs = ;
ZkClient zkClient = new ZkClient(zookeeperConnect, sessionTimeoutMs, connectionTimeoutMs, ZKStringSerializer$.MODULE$);
boolean isSecureKafkaCluster = false;
ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect), isSecureKafkaCluster);
Properties topicConfig = new Properties();
try {
AdminUtils.createTopic(zkUtils, topicName, 1, 1, topicConfig,
RackAwareMode.Disabled$.MODULE$);
} catch (TopicExistsException ex) {
//log it
}
zkClient.close();
}
Note: It's only allowed to increase no. of partitions.