Search code examples
serializationf#apache-kafkaavroconfluent-schema-registry

How to set schema.registry.URL?


I'm testing sending GenericRecord. But the following code

let fullName = "Test k"
let uniEncoding = new UnicodeEncoding()
let str = uniEncoding.GetBytes("abcdefg")

use ms = new MemoryStream()
ms.Write(str, 0, str.Length)
let content = ms.ToArray()

let config = new Dictionary<string, Object>()
config.Add("bootstrap.servers", "10.0.0.2:9092")
config.Add("schema.registry.url", "http://bing.com")
let s = Schema.Parse(
            """{
                "namespace": "nnnnnnnn",
                "type": "record",
                "name": "fffffnnnnnn",
                "fields": [
                    {"name": "file_name", "type": "string"},
                    {"name": "time",  "type": "string"},
                    {"name": "content", "type": "bytes"}
                ]
                }""") :?> RecordSchema
use producer = new Producer<string, GenericRecord>(
                 config, new AvroSerializer<string>(), new AvroSerializer<GenericRecord>())
let record = new GenericRecord(s)
record.Add("file_name", fullName)
record.Add("time", DateTimeOffset.Now.ToString())
record.Add("content", content)
let dr = producer.ProduceAsync("Topic1", fullName, record).Result // error

0 // return an integer exit code

returns this error

HttpRequestException: [http://bing.com/] ServiceUnavailable[http://bing.com/] ServiceUnavailable -1

What value should I set?


Solution

  • Well, bing.com is not a Schema Registry

    You need to download Confluent OSS Distribution and configure and run (assuming Linux, but bin\windows\ works otherwise)

    <confluent_home>/bin/schema-registry-start <confluent_home>/etc/schema-registry/schema-registry.properties
    

    Then you would use something like http://schema-registry.server.name:8081/

    Refer to documentation for more information