I tried to purge Kafka topic from Java as below by setting retention time to 1sec and then returning back to original value. But the the messages were not deleted from topic. What is wrong?
Map<ConfigResource,Collection<AlterConfigOp>> altConf = new HashMap<ConfigResource,Collection<AlterConfigOp>>();
Collection<AlterConfigOp> altConfOp = new ArrayList<AlterConfigOp>();
AlterConfigOp aco1 = new AlterConfigOp(new ConfigEntry(TopicConfig.RETENTION_MS_CONFIG, "1000"), AlterConfigOp.OpType.SET);
altConfOp.add(aco1);
altConf.put(new ConfigResource(ConfigResource.Type.TOPIC, topic), altConfOp);
ac.incrementalAlterConfigs(altConf);
Thread.sleep(5000);
altConf = new HashMap<ConfigResource,Collection<AlterConfigOp>>();
altConfOp = new ArrayList<AlterConfigOp>();
aco1 = new AlterConfigOp(new ConfigEntry(TopicConfig.RETENTION_MS_CONFIG, originalRetention), AlterConfigOp.OpType.SET);
altConfOp.add(aco1);
altConf.put(new ConfigResource(ConfigResource.Type.TOPIC, topic), altConfOp);
ac.incrementalAlterConfigs(altConf);