avromatic 0.15.1 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46512fd49a1b53c39202a90d03214b23303a7775
4
- data.tar.gz: e63c9f9f1dd812b6627f3e06c93283d3ce095ad4
3
+ metadata.gz: 1816133bc4491f2c36e0e08cb02aa0fa5e98cd89
4
+ data.tar.gz: fb5374520ceb8b248546719cc212c2c155aa6d56
5
5
  SHA512:
6
- metadata.gz: 6619307c3c04ad60f7072f1ab019ee20ae718464cfac13f74be82d3556bfe51a9ef6c4fa9ca9eb566535e7c24d74577e4e67a50deab2505e362285e9d3e1e713
7
- data.tar.gz: ef6be3d67985f24e3b1f7ff3836a28945e769f4b8878ba9973ba0a9ecf4919c1f4788f7f1587af8847d31ea7a1f3a0e1166bac4d1e361e823fd274104ed11921
6
+ metadata.gz: c2f58bb5ad013c717fcf4f423baf5377327337fc3a93dd0c0e152a8fa4a3c6f00d7563f3f49b6b0d9748c4339c0d61d07ee64d2975d6ace2463bb137b2c30c7d
7
+ data.tar.gz: da1f9b1b50cbf8d022a7f58ab6ed4b11d9530af1b3c4f06991499380c1dea2855527916a83f1eb58ef2f25167ca115b9f183e369b46f95e951adb12a63420b51
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # avromatic changelog
2
2
 
3
+ ## v0.17.0
4
+ - Add `.register_schemas!` method to generated models to register the associated
5
+ schemas in a schema registry.
6
+
7
+ ## v0.16.0
8
+ - Add `#lookup_subject_schema` method to `AvroTurf::SchemaRegistry` patch to
9
+ directly support looking up existing schema ids by fingerprint.
10
+
3
11
  ## v0.15.1
4
12
  - Add `Avromatic.use_cacheable_schema_registration` option to control the lookup
5
13
  of existing schema ids by fingerprint.
data/README.md CHANGED
@@ -65,7 +65,7 @@ and the [Messaging API](#messaging-api).
65
65
  The use of this additional endpoint can be disabled by setting this option to
66
66
  `false` and this is recommended if using a Schema Registry that does not support
67
67
  the endpoint.
68
- * **messaging**: An `AvroTurf::Messaging` object to be shared by all generated models.
68
+ * **messaging**: An `AvroTurf::Messaging` object to be shared by all generated models
69
69
  The `build_messaging!` method may be used to create a `Avromatic::Messaging`
70
70
  instance based on the other configuration values.
71
71
  * **logger**: The logger to use for the schema registry client.
@@ -319,6 +319,13 @@ Or just a value if only one schema is used:
319
319
  MyValue.avro_message_decode(message_value)
320
320
  ```
321
321
 
322
+ The schemas associated with a model can also be added to a schema registry without
323
+ encoding a message:
324
+
325
+ ```ruby
326
+ MyTopic.register_schemas!
327
+ ```
328
+
322
329
  #### Avromatic::Model::MessageDecoder
323
330
 
324
331
  A stream of messages encoded from various models using the messaging approach
@@ -4,6 +4,8 @@ require 'avromatic/io/datum_reader'
4
4
  module Avromatic
5
5
  # Subclass AvroTurf::Messaging to use a custom DatumReader for decode.
6
6
  class Messaging < AvroTurf::Messaging
7
+ attr_reader :registry
8
+
7
9
  def decode(data, schema_name: nil, namespace: @namespace)
8
10
  readers_schema = schema_name && @schema_store.find(schema_name, namespace)
9
11
  stream = StringIO.new(data)
@@ -50,6 +50,20 @@ module Avromatic
50
50
  end
51
51
  end
52
52
 
53
+ module Registration
54
+ def register_schemas!
55
+ register_schema(key_avro_schema) if key_avro_schema
56
+ register_schema(value_avro_schema)
57
+ nil
58
+ end
59
+
60
+ private
61
+
62
+ def register_schema(schema)
63
+ avro_messaging.registry.register(schema.fullname, schema)
64
+ end
65
+ end
66
+
53
67
  module ClassMethods
54
68
  # The messaging object acts as an intermediary talking to the schema
55
69
  # registry and using returned/specified schemas to decode/encode.
@@ -58,6 +72,7 @@ module Avromatic
58
72
  end
59
73
 
60
74
  include Decode
75
+ include Registration
61
76
  end
62
77
  end
63
78
  end
@@ -7,24 +7,26 @@ module Avromatic
7
7
  def register(subject, schema)
8
8
  return super unless Avromatic.use_cacheable_schema_registration
9
9
 
10
+ begin
11
+ lookup_subject_schema(subject, schema)
12
+ rescue Excon::Errors::NotFound
13
+ data = post("/subjects/#{subject}/versions", body: { schema: schema.to_s }.to_json)
14
+ id = data.fetch('id')
15
+ @logger.info("Registered schema for subject `#{subject}`; id = #{id}")
16
+ id
17
+ end
18
+ end
19
+
20
+ def lookup_subject_schema(subject, schema)
10
21
  schema_object = if schema.is_a?(String)
11
22
  Avro::Schema.parse(schema)
12
23
  else
13
24
  schema
14
25
  end
15
26
 
16
- registered = false
17
- data = begin
18
- get("/subjects/#{subject}/fingerprints/#{schema_object.sha256_fingerprint.to_s(16)}")
19
- rescue
20
- registered = true
21
- post("/subjects/#{subject}/versions", body: { schema: schema.to_s }.to_json)
22
- end
23
-
27
+ data = get("/subjects/#{subject}/fingerprints/#{schema_object.sha256_fingerprint.to_s(16)}")
24
28
  id = data.fetch('id')
25
-
26
- @logger.info("#{registered ? 'Registered' : 'Found'} schema for subject `#{subject}`; id = #{id}")
27
-
29
+ @logger.info("Found schema for subject `#{subject}`; id = #{id}")
28
30
  id
29
31
  end
30
32
  end
@@ -1,3 +1,3 @@
1
1
  module Avromatic
2
- VERSION = '0.15.1'.freeze
2
+ VERSION = '0.17.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avromatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salsify Engineering
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-01 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro