Giriş
Docker free Kafka integration tests yazısında birim testi için kullanılabilecek bazı kütüphaneler belirtiliyor. Bu kütüphanelerin yaptığı işi kendimiz de yapabiliriz.
Şu satırı dahil ederiz
<dependency><groupId>io.confluent</groupId><artifactId>kafka-schema-registry</artifactId><version>7.4.0</version><scope>test</scope></dependency>
Örnek
Şöyle yaparız
org.eclipse.jetty.server.Server schemaRegistryServer;
KafkaSchemaRegistry schemaRegistry;
public void createSchemaRegistry(SchemaRegistryConfig config) throws Exception {
SchemaRegistryRestApplication schemaRegistryApplication =
new SchemaRegistryRestApplication(config);
schemaRegistryServer = schemaRegistryApplication.createServer();
schemaRegistryServer.start();
schemaRegistry = schemaRegistryApplication.schemaRegistry();
}
public void shutdownSchemaRegistry() throws Exception {
if (schemaRegistryServer != null) {
schemaRegistryServer.stop();
}
}
public URI getSchemaRegistryURI() {
return schemaRegistryServer.getURI();
}
public int registerSchema(String subject, org.apache.avro.Schema avroSchema)
throws SchemaRegistryException {
Schema schema = new Schema(subject, -1, -1, AvroSchema.TYPE, emptyList(),
avroSchema.toString());
Schema registeredSchema = schemaRegistry.register(subject, schema);
return registeredSchema.getId();
}
public int getLatestSchemaVersion(String subject) throws SchemaRegistryException {
return Optional.ofNullable(schemaRegistry.getLatestVersion(subject))
.map(Schema::getVersion)
.orElseThrow(() ->
new SchemaRegistryException("No schema found in subject '" + subject + "'"));
}
No comments:
Post a Comment