0

I am using Confluent Platform for a MongoDB Sink Connector and I need to define an Avro schema in the Schema Registry so that data would be written in a structured manner to MongoDB Collection.

I have saved the following schema in a .avsc file:

{
    "type": "record",
    "name": "Transaction",
    "namespace": "com.prxm",
    "fields": [
        {"name": "Timestamp", "type": "Date"},
        {"name": "Price", "type": "double"},
        {"name": "Qty", "type": "int"},
        {"name": "Name", "type": "string"}
    ] 
}

I tried to post this schema to Kafka Schema Registry using the following cURL command:

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data @transaction-schema.json http://localhost:8081/subjects/transaction-value/versions

And got the following error: {"error_code":42201,"message":"Empty schema"}. I Googled it and searched across Stackoverflow but didn't find a proper solution.

Confluent version: 7.3.2 Connect is UP and so is Schema Registry Running on Ubuntu 22 VM.

Any help would be appreciated.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Guy_g23
  • 316
  • 2
  • 7
  • 1
    What documentation are you using for that request? schemaType is a required field in the payload ever since around version 6.x of the registry. Plus, the registry doesn't accept avsc files as API payloads, so what's your json file look like? – OneCricketeer May 03 '23 at 13:47
  • @OneCricketeer you are right, I was looking at somebody's example not at the documentation. I will post my answer soon. – Guy_g23 May 03 '23 at 14:17

1 Answers1

1

My bad, the correct way to post this schema to Confluent Schema Registry is this:

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "{\"type\":\"record\",\"name\":\"Transaction\",\"namespace\":\"com.prxm\",\"fields\":[{\"name\":\"Timestamp\",\"type\":\"string\", \"logicalType\": \"Date\"},{\"name\":\"Price\",\"type\":\"double\"},{\"name\":\"Qty\", \"type\": \"int\"},{\"name\": \"Name\", \"type\": \"string\"}]}"}' http://localhost:8081/subjects/transaction-value/versions

Note that --data argument should include the whole schema in JSON format and not a reference to a file.

Another important thing I noticed is that the Kafka Topic (named "transaction" in this example) should be created via the Confluent Platform, don't rely on older Topics which were created by Apache Kafka CLI as an according Subject wouldn't be created in the Schema Registry.

Guy_g23
  • 316
  • 2
  • 7