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 = <some-int-value>;
int connectionTimeoutMs = <some-int-value>;
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.