Class: AvroSchemaRegistry::Client

Inherits:
AvroTurf::ConfluentSchemaRegistry
  • Object
show all
Defined in:
lib/avro_schema_registry/client.rb

Instance Method Summary collapse

Instance Method Details

#compatible?(subject, schema, version = 'latest', **params) ⇒ Boolean

Override to add support for additional params

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/avro_schema_registry/client.rb', line 40

def compatible?(subject, schema, version = 'latest', **params)
  data = post("/compatibility/subjects/#{subject}/versions/#{version}",
              expects: [200, 404],
              body: { schema: schema.to_s }.merge!(params).to_json)
  data.fetch('is_compatible', false) unless data.key?('error_code')
end

#lookup_subject_schema(subject, schema) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/avro_schema_registry/client.rb', line 10

def lookup_subject_schema(subject, schema)
  schema_object = if schema.is_a?(String)
                    Avro::Schema.parse(schema)
                  else
                    schema
                  end

  data = get("/subjects/#{subject}/fingerprints/#{schema_object.sha256_resolution_fingerprint.to_s(16)}")
  id = data.fetch('id')
  @logger.info("Found schema for subject `#{subject}`; id = #{id}")
  id
end

#register(subject, schema, **params) ⇒ Object

Override register to first check if a schema is registered by fingerprint Also, allow additional params to be passed to register.



25
26
27
28
29
# File 'lib/avro_schema_registry/client.rb', line 25

def register(subject, schema, **params)
  lookup_subject_schema(subject, schema)
rescue Excon::Errors::NotFound
  register_without_lookup(subject, schema, **params)
end

#register_without_lookup(subject, schema, **params) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/avro_schema_registry/client.rb', line 31

def register_without_lookup(subject, schema, **params)
  data = post("/subjects/#{subject}/versions",
              body: { schema: schema.to_s }.merge!(params).to_json)
  id = data.fetch('id')
  @logger.info("Registered schema for subject `#{subject}`; id = #{id}")
  id
end