avromatic 0.15.1 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +8 -1
- data/lib/avromatic/messaging.rb +2 -0
- data/lib/avromatic/model/messaging_serialization.rb +15 -0
- data/lib/avromatic/schema_registry_patch.rb +13 -11
- data/lib/avromatic/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1816133bc4491f2c36e0e08cb02aa0fa5e98cd89
|
4
|
+
data.tar.gz: fb5374520ceb8b248546719cc212c2c155aa6d56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/avromatic/messaging.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/avromatic/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro
|