deimos-ruby 2.4.0.pre.beta8 → 2.4.0.pre.beta9
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 +6 -0
- data/lib/deimos/ext/producer_route.rb +2 -1
- data/lib/deimos/schema_backends/proto_schema_registry.rb +23 -0
- data/lib/deimos/version.rb +1 -1
- data/lib/deimos.rb +10 -1
- data/lib/tasks/deimos.rake +14 -0
- 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: 63128b3ded679a1adf4a45cf2ba2cd18e5734f493d707a60d720df1d2112b249
|
|
4
|
+
data.tar.gz: 829675d8502e3229f79ea5a57f417f181e825c15f0d87f60ff4d1779580b458e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6fe15786e0c5ec7bc173354ace9763ae911b922b4e3f6312e09e5cdf56071076a72d0cb561658826a98ac1214bf58c97ae3124d690408a42a6530d6fe33d7eb
|
|
7
|
+
data.tar.gz: fa6ff30280e567c252c7d763d25c2726669ce2809efcd52bf76ac8f5d8d93538bd93f5d98ba5858e97d57217c794eccb2f8983338db9cd8259218ed1f87715e4
|
data/README.md
CHANGED
|
@@ -281,9 +281,15 @@ MyProducer.publish({
|
|
|
281
281
|
})
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
+
### Protobuf and Key Schemas
|
|
285
|
+
|
|
284
286
|
> [!IMPORTANT]
|
|
285
287
|
> 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.
|
|
286
288
|
|
|
289
|
+
To enable integration with [buf](https://buf.build/), Deimos provides a Rake task that will auto-generate `.proto` files. This task can be run in CI before running `buf push`. This way, downstream systems that want to use the generated key schemas can do so using their own tech stack.
|
|
290
|
+
|
|
291
|
+
bundle exec rake deimos:generate_key_protos
|
|
292
|
+
|
|
287
293
|
## Instrumentation
|
|
288
294
|
|
|
289
295
|
Deimos will send events through the [Karafka instrumentation monitor](https://karafka.io/docs/Monitoring-and-Logging/#subscribing-to-the-instrumentation-events).
|
|
@@ -56,6 +56,29 @@ module Deimos
|
|
|
56
56
|
)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
+
# @param file [String]
|
|
60
|
+
# @param field_name [String]
|
|
61
|
+
def write_key_proto(file, field_name)
|
|
62
|
+
return if field_name.nil?
|
|
63
|
+
|
|
64
|
+
proto = proto_schema
|
|
65
|
+
package = proto.file_descriptor.to_proto.package
|
|
66
|
+
writer = SchemaRegistry::Output::ProtoText::Writer.new
|
|
67
|
+
info = SchemaRegistry::Output::ProtoText::ParseInfo.new(writer, package)
|
|
68
|
+
writer.write_line(%(syntax = "proto3";))
|
|
69
|
+
writer.write_line("package #{package};")
|
|
70
|
+
writer.writenl
|
|
71
|
+
|
|
72
|
+
field = proto.to_proto.field.find { |f| f.name == field_name.to_s }
|
|
73
|
+
writer.write_line("message #{proto.to_proto.name}Key {")
|
|
74
|
+
writer.indent
|
|
75
|
+
SchemaRegistry::Output::ProtoText.write_field(info, field)
|
|
76
|
+
writer.dedent
|
|
77
|
+
writer.write_line("}")
|
|
78
|
+
path = "#{file}/#{package.gsub('.', '/')}/#{proto.to_proto.name.underscore}_key.proto"
|
|
79
|
+
File.write(path, writer.string)
|
|
80
|
+
end
|
|
81
|
+
|
|
59
82
|
end
|
|
60
83
|
end
|
|
61
84
|
end
|
data/lib/deimos/version.rb
CHANGED
data/lib/deimos.rb
CHANGED
|
@@ -72,9 +72,18 @@ module Deimos
|
|
|
72
72
|
klass
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
# @param topic_name [String]
|
|
76
|
+
# @return [SchemaBackends::Base]
|
|
77
|
+
def schema_backend_for(topic_name)
|
|
78
|
+
config = Deimos.karafka_config_for(topic: topic_name)
|
|
79
|
+
self.schema_backend(schema: config.schema,
|
|
80
|
+
namespace: config.namespace,
|
|
81
|
+
backend: config.schema_backend || Deimos.config.schema.backend)
|
|
82
|
+
end
|
|
83
|
+
|
|
75
84
|
# @param schema [String, Symbol]
|
|
76
85
|
# @param namespace [String]
|
|
77
|
-
# @return [
|
|
86
|
+
# @return [Deimos::SchemaBackends::Base]
|
|
78
87
|
def schema_backend(schema:, namespace:, backend: Deimos.config.schema.backend)
|
|
79
88
|
if config.schema.use_schema_classes
|
|
80
89
|
# Initialize an instance of the provided schema
|
data/lib/tasks/deimos.rake
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'generators/deimos/schema_class_generator'
|
|
4
4
|
require 'optparse'
|
|
5
|
+
require 'deimos/schema_backends/proto_schema_registry'
|
|
5
6
|
|
|
6
7
|
namespace :deimos do
|
|
7
8
|
desc 'Starts Deimos in the rails environment'
|
|
@@ -40,4 +41,17 @@ namespace :deimos do
|
|
|
40
41
|
Deimos::Generators::SchemaClassGenerator.start
|
|
41
42
|
end
|
|
42
43
|
|
|
44
|
+
desc 'Output Protobuf key schemas'
|
|
45
|
+
task generate_key_protos: :environment do
|
|
46
|
+
puts "Generating Protobuf key schemas"
|
|
47
|
+
Deimos.karafka_configs.each do |config|
|
|
48
|
+
next if config.try(:producer_class).blank? ||
|
|
49
|
+
!Deimos.schema_backend_for(config.name).is_a?(Deimos::SchemaBackends::ProtoSchemaRegistry) ||
|
|
50
|
+
config.deserializers[:key].try(:key_field).blank?
|
|
51
|
+
|
|
52
|
+
puts "Writing key proto for #{config.name}"
|
|
53
|
+
backend = Deimos.schema_backend_for(config.name)
|
|
54
|
+
backend.write_key_proto('protos', config.deserializers[:key].key_field)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
43
57
|
end
|