deimos-ruby 2.4.0.pre.beta1 → 2.4.0.pre.beta2
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/README.md +10 -3
- data/lib/deimos/message.rb +11 -2
- data/lib/deimos/schema_backends/proto_base.rb +1 -1
- data/lib/deimos/schema_backends/proto_schema_registry.rb +5 -0
- data/lib/deimos/test_helpers.rb +7 -0
- data/lib/deimos/version.rb +1 -1
- data/lib/deimos.rb +9 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bc23c10fe732ab1eb2b6c0e2daf5bdb943a939510624b821456d0d383224f579
|
|
4
|
+
data.tar.gz: 84fdb7e495d76bb27b0592572f13249a7c8e28c3d123c68d15ac5d30ff883421
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9b47d42b33e3c66ed3fd852570490e6a719d55c6709b706b38b58144a192b40a5edef6c6b5be516c89c3798069ea22f6be2134e1000f41ba3110f92b5face15d
|
|
7
|
+
data.tar.gz: 3fea215d836fbcc1e10df7971e7112194ada61a95dab4be1524cafc275d523b7ee186887298a0a89e162945aeaf2b83d5826031844e9b26dd25039d7797d6c75
|
data/README.md
CHANGED
|
@@ -91,10 +91,11 @@ Currently we have the following possible schema backends:
|
|
|
91
91
|
* Avro Schema Registry (use the Confluent Schema Registry)
|
|
92
92
|
* Avro Validation (validate using an Avro schema but leave decoded - this is useful
|
|
93
93
|
for unit testing and development)
|
|
94
|
+
* Protobuf Local (use pure Protobuf)
|
|
94
95
|
* Protobuf Schema Registry (use Protobuf with the Confluent Schema Registry)
|
|
95
96
|
* Mock (no actual encoding/decoding).
|
|
96
97
|
|
|
97
|
-
Other possible schemas could [JSONSchema](https://json-schema.org/), etc. Feel free to
|
|
98
|
+
Other possible schemas could include [JSONSchema](https://json-schema.org/), etc. Feel free to
|
|
98
99
|
contribute!
|
|
99
100
|
|
|
100
101
|
To create a new schema backend, please see the existing examples [here](lib/deimos/schema_backends).
|
|
@@ -281,7 +282,7 @@ MyProducer.publish({
|
|
|
281
282
|
```
|
|
282
283
|
|
|
283
284
|
> [!IMPORTANT]
|
|
284
|
-
> Protobuf should *not* be used as a key schema, since the binary encoding is [unstable](https://protobuf.dev/programming-guides/encoding/#implications) and may break partitioning. Deimos will automatically convert
|
|
285
|
+
> Protobuf should *not* be used as a key schema, since the binary encoding is [unstable](https://protobuf.dev/programming-guides/encoding/#implications) and may break partitioning. Deimos will automatically convert keys to sorted JSON, and will use JSON Schema in the schema registry.
|
|
285
286
|
|
|
286
287
|
## Instrumentation
|
|
287
288
|
|
|
@@ -1010,7 +1011,13 @@ end
|
|
|
1010
1011
|
# test can have the same settings every time it is run
|
|
1011
1012
|
after(:each) do
|
|
1012
1013
|
Deimos.config.reset!
|
|
1013
|
-
|
|
1014
|
+
# set specific settings here
|
|
1015
|
+
Deimos.config.schema.path = 'my/schema/path'
|
|
1016
|
+
end
|
|
1017
|
+
|
|
1018
|
+
around(:each) do |ex|
|
|
1019
|
+
# replace e.g. avro_schema_registry with avro_validation, proto_schema_registry with proto_local
|
|
1020
|
+
Deimos::TestHelpers.with_mock_backends { ex.run }
|
|
1014
1021
|
end
|
|
1015
1022
|
```
|
|
1016
1023
|
|
data/lib/deimos/message.rb
CHANGED
|
@@ -38,10 +38,19 @@ module Deimos
|
|
|
38
38
|
def add_fields(fields)
|
|
39
39
|
return if @payload.to_h.with_indifferent_access.except(:payload_key, :partition_key).blank?
|
|
40
40
|
|
|
41
|
-
if
|
|
41
|
+
if @payload.respond_to?(:message_id)
|
|
42
|
+
if fields.include?('message_id') && @payload.message_id.blank?
|
|
43
|
+
@payload.message_id = SecureRandom.uuid
|
|
44
|
+
end
|
|
45
|
+
elsif fields.include?('message_id')
|
|
42
46
|
@payload['message_id'] ||= SecureRandom.uuid
|
|
43
47
|
end
|
|
44
|
-
|
|
48
|
+
|
|
49
|
+
if @payload.respond_to?(:timestamp)
|
|
50
|
+
if fields.include?('timestamp') && @payload.timestamp.blank?
|
|
51
|
+
@payload.timestamp = Time.now.in_time_zone.to_s
|
|
52
|
+
end
|
|
53
|
+
elsif fields.include?('timestamp')
|
|
45
54
|
@payload['timestamp'] ||= Time.now.in_time_zone.to_s
|
|
46
55
|
end
|
|
47
56
|
end
|
|
@@ -8,6 +8,11 @@ module Deimos
|
|
|
8
8
|
# Encode / decode using the Protobuf schema registry.
|
|
9
9
|
class ProtoSchemaRegistry < ProtoBase
|
|
10
10
|
|
|
11
|
+
# @override
|
|
12
|
+
def self.mock_backend
|
|
13
|
+
:proto_local
|
|
14
|
+
end
|
|
15
|
+
|
|
11
16
|
# @override
|
|
12
17
|
def decode_payload(payload, schema:)
|
|
13
18
|
self.class.schema_registry.decode(payload)
|
data/lib/deimos/test_helpers.rb
CHANGED
|
@@ -50,6 +50,13 @@ module Deimos
|
|
|
50
50
|
warn("unit_test! is deprecated and can be replaced by setting Deimos's schema backend " \
|
|
51
51
|
'to `:avro_validation`. All other test behavior is provided by Karafka.')
|
|
52
52
|
end
|
|
53
|
+
|
|
54
|
+
def with_mock_backends
|
|
55
|
+
Deimos.mock_backends = true
|
|
56
|
+
yield
|
|
57
|
+
Deimos.mock_backends = false
|
|
58
|
+
end
|
|
59
|
+
|
|
53
60
|
end
|
|
54
61
|
|
|
55
62
|
# get the difference of 2 hashes.
|
data/lib/deimos/version.rb
CHANGED
data/lib/deimos.rb
CHANGED
|
@@ -54,6 +54,9 @@ module Deimos
|
|
|
54
54
|
|
|
55
55
|
class << self
|
|
56
56
|
|
|
57
|
+
# @return [Boolean] for use in unit tests
|
|
58
|
+
attr_accessor :mock_backends
|
|
59
|
+
|
|
57
60
|
# @param backend [Symbol, nil]
|
|
58
61
|
# @return [Class<Deimos::SchemaBackends::Base>]
|
|
59
62
|
def schema_backend_class(backend: nil)
|
|
@@ -61,7 +64,12 @@ module Deimos
|
|
|
61
64
|
|
|
62
65
|
require "deimos/schema_backends/#{backend}"
|
|
63
66
|
|
|
64
|
-
"Deimos::SchemaBackends::#{backend.to_s.classify}".constantize
|
|
67
|
+
klass = "Deimos::SchemaBackends::#{backend.to_s.classify}".constantize
|
|
68
|
+
if self.mock_backends
|
|
69
|
+
require "deimos/schema_backends/#{klass.mock_backend}"
|
|
70
|
+
klass = "Deimos::SchemaBackends::#{klass.mock_backend.to_s.classify}".constantize
|
|
71
|
+
end
|
|
72
|
+
klass
|
|
65
73
|
end
|
|
66
74
|
|
|
67
75
|
# @param schema [String, Symbol]
|