riferrei / srclient

Golang Client for Schema Registry
Apache License 2.0
235 stars 70 forks source link

Can't create schema with .avsc file #70

Closed breeze7086 closed 2 years ago

breeze7086 commented 2 years ago

Follow the example codes to create a schema when the Schema Registry doesn't contain it. The codes look like

if schema == nil {
    src := srclient.CreateSchemaRegistryClient("http://127.0.0.1")
    schema, err := src.GetLatestSchema(topic)
    if schema == nil {
        schemaBytes, _ := ioutil.ReadFile("test.avsc")
        schema, err = src.CreateSchema(topic, string(schemaBytes), srclient.Avro)
        if err != nil {
            logger.FatalPrintf("Error creating the schema %s", err)
        }
    }
}

The test.avsc file

{
  "type": "record",
  "namespace": "customer",
  "name": "customer_v1",
  "doc": "Test schema",
  "fields": [
    { "name": "first_name", "type": "string", "doc": "First Name of Customer" },
    { "name": "last_name", "type": "string", "doc": "Last Name of Customer" },
    { "name": "age", "type": "int", "doc": "Age at the time of registration" },
    { "name": "height", "type": "float", "doc": "Height at the time of registration in cm" },
    { "name": "weight", "type": "float", "doc": "Weight at the time of registration in kg" },
    { "name": "automated_email", "type": "boolean", "default": true, "doc": "Field indicating if the user is enrolled in marketing emails" }
  ]
}

By using these codes, I got an error from Schema Registry server

INFO   [2022-02-21 10:35:12.886] [dw-36955] c.h.r.s.w.ConfluentSchemaRegistryCompatibleResource -  registerSchema for [test-go] is [{}]
ERROR  [2022-02-21 10:35:12.892] [dw-36955] c.h.r.s.w.ConfluentSchemaRegistryCompatibleResource -  Encountered error while adding subject [test-go]
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "schemaType" (class com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource$SchemaString), n
ot marked as ignorable (one known property: "schema"])
 at [Source: (String)"{"schema":"{   \"type\": \"record\",   \"namespace\": \"customer\",   \"name\": \"customer_v1\",   \"fields\": [     {\"name\": \"first_name\", \"type\": \"string\"},     {\"name\": \"last_name\
", \"type\": \"string\"},     {\"name\": \"age\", \"type\": \"int\"},     {\"name\": \"height\", \"type\": \"float\"},     {\"name\": \"weight\", \"type\": \"float\"},     {\"name\": \"automated_email\", \"type\": \"
boolean\", \"default\": true}   ] }","schemaType":"AVRO","references":[]}"; line: 1, column: 462] (through reference chain: com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResour
ce$SchemaString["schemaType"])
        at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61)
        at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:843)
        at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1206)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1597)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1575)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:294)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4218)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3214)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3182)
        at com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.schemaStringFromJson(ConfluentSchemaRegistryCompatibleResource.java:425)
        at com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.lambda$registerSchemaVersion$1(ConfluentSchemaRegistryCompatibleResource.java:361)
        at com.hortonworks.registries.schemaregistry.webservice.BaseRegistryResource.handleLeaderAction(BaseRegistryResource.java:76)
        at com.hortonworks.registries.schemaregistry.webservice.ConfluentSchemaRegistryCompatibleResource.registerSchemaVersion(ConfluentSchemaRegistryCompatibleResource.java:342)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
        at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)
        at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
        at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
        at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
        at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
        at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
        at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
        at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
AtakanColak commented 2 years ago

From the logs it doesn't seem like you are using Confluent Schema Registry. schemaType is part of the API. We are not supporting any schema registries that are not compatible with Confluent Schema Registry, therefore closing this.