deimos-ruby 1.8.2.pre.beta1 → 1.8.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce4c0e112957a2a8983372b2eda22b139e1eadac18945d4cbd9945c31e181b9d
4
- data.tar.gz: 43df5dcfd68305868cc2ac19f33c070bfc2d6b3c3679fc85116d81939e3a5ce2
3
+ metadata.gz: b773de54759babb229e8f3bc6b42931dab7695b7197d601ad4ae08015c0b401f
4
+ data.tar.gz: 4af1aa98ffdfc013c4cac02fa316371ad138ec0d807ed58426a7ad57d6c1e719
5
5
  SHA512:
6
- metadata.gz: ffdbf97e2ad36eafd643cf958b44990a16315da4d346e8b5aaa8dacbdf8d0caecfd493063305b888e240091ab26f5a39bf044b8c3919419f2a6c35c460d774f8
7
- data.tar.gz: cb200f4a2d47519f2cb3f0f577a0295690842eb7a8367867749a3cc75236d7205eddb413cc22c28efba7b44b6c8d8a4a98744cd4d3adacedfbc2d64d690397d7
6
+ metadata.gz: 319d01a4c42c5efe72bd4959fb57548102c3f2b4305f3d94510747fd372d516ebad3e34ff74f9e6744641728efce9eb7a20f2d89c37d6bd90847253698a05238
7
+ data.tar.gz: 9e6999cca87ca448167a9e61a0bfa5914b36fd74c053f132bd02ab5200be840984546469affccfd07ce77d4d098a2096b13e42febd4ce7059ec882c436580cd8
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ ## 1.8.2-beta2 - 2020-09-15
11
+
12
+ ### Features :star:
13
+
14
+ - Add details on using schema backend directly in README.
15
+ - Default to the provided schema if topic is not provided when
16
+ encoding to `AvroSchemaRegistry`.
17
+ - Add mapping syntax for the `schema` call in `SchemaControllerMixin`.
18
+
10
19
  ## 1.8.2-beta1 - 2020-09-09
11
20
 
12
21
  ### Features :star:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deimos-ruby (1.8.2.pre.beta1)
4
+ deimos-ruby (1.8.2.pre.beta2)
5
5
  avro_turf (~> 0.11)
6
6
  phobos (~> 1.9)
7
7
  ruby-kafka (~> 0.7)
data/README.md CHANGED
@@ -11,6 +11,7 @@ a useful toolbox of goodies for Ruby-based Kafka development.
11
11
  Built on Phobos and hence Ruby-Kafka.
12
12
 
13
13
  <!--ts-->
14
+ * [Additional Documentation](#additional-documentation)
14
15
  * [Installation](#installation)
15
16
  * [Versioning](#versioning)
16
17
  * [Configuration](#configuration)
@@ -29,9 +30,19 @@ Built on Phobos and hence Ruby-Kafka.
29
30
  * [Metrics](#metrics)
30
31
  * [Testing](#testing)
31
32
  * [Integration Test Helpers](#integration-test-helpers)
33
+ * [Utilities](#utilities)
32
34
  * [Contributing](#contributing)
33
35
  <!--te-->
34
36
 
37
+ # Additional Documentation
38
+
39
+ Please see the following for further information not covered by this readme:
40
+
41
+ * [Architecture Design](docs/ARCHITECTURE.md)
42
+ * [Configuration Reference](docs/CONFIGURATION.md)
43
+ * [Database Backend Feature](docs/DATABASE_BACKEND.md)
44
+ * [Upgrading Deimos](docs/UPGRADING.md)
45
+
35
46
  # Installation
36
47
 
37
48
  Add this line to your application's Gemfile:
@@ -482,6 +493,12 @@ class WhateverController < ApplicationController
482
493
  # will look for: my.namespace.requests.Index.avsc
483
494
  # my.namespace.responses.Index.avsc
484
495
 
496
+ # Can use mapping to change the schema but keep the namespaces,
497
+ # i.e. use the same schema name across the two namespaces
498
+ schemas create: 'CreateTopic'
499
+ # will look for: my.namespace.requests.CreateTopic.avsc
500
+ # my.namespace.responses.CreateTopic.avsc
501
+
485
502
  # If all routes use the default, you can add them all at once
486
503
  schemas :index, :show, :update
487
504
 
@@ -989,13 +1006,24 @@ Deimos::Utils::InlineConsumer.get_messages_for(
989
1006
  )
990
1007
  ```
991
1008
 
1009
+ ## Utilities
1010
+
1011
+ You can use your configured schema backend directly if you want to
1012
+ encode and decode payloads outside of the context of sending messages.
1013
+
1014
+ ```ruby
1015
+ backend = Deimos.schema_backend(schema: 'MySchema', namespace: 'com.my-namespace')
1016
+ encoded = backend.encode(my_payload)
1017
+ decoded = backend.decode(my_encoded_payload)
1018
+ coerced = backend.coerce(my_payload) # coerce to correct types
1019
+ backend.validate(my_payload) # throws an error if not valid
1020
+ fields = backend.schema_fields # list of fields defined in the schema
1021
+ ```
1022
+
992
1023
  ## Contributing
993
1024
 
994
1025
  Bug reports and pull requests are welcome on GitHub at https://github.com/flipp-oss/deimos .
995
1026
 
996
- We have more information on the [internal architecture](docs/ARCHITECTURE.md) of Deimos
997
- for contributors!
998
-
999
1027
  ### Linting
1000
1028
 
1001
1029
  Deimos uses Rubocop to lint the code. Please run Rubocop on your code
@@ -0,0 +1,128 @@
1
+ # Upgrading Deimos
2
+
3
+ ## Upgrading from < 1.5.0 to >= 1.5.0
4
+
5
+ If you are using Confluent's schema registry to Avro-encode your
6
+ messages, you will need to manually include the `avro_turf` gem
7
+ in your Gemfile now.
8
+
9
+ This update changes how to interact with Deimos's schema classes.
10
+ Although these are meant to be internal, they are still "public"
11
+ and can be used by calling code.
12
+
13
+ Before 1.5.0:
14
+
15
+ ```ruby
16
+ encoder = Deimos::AvroDataEncoder.new(schema: 'MySchema',
17
+ namespace: 'com.my-namespace')
18
+ encoder.encode(my_payload)
19
+
20
+ decoder = Deimos::AvroDataDecoder.new(schema: 'MySchema',
21
+ namespace: 'com.my-namespace')
22
+ decoder.decode(my_payload)
23
+ ```
24
+
25
+ After 1.5.0:
26
+ ```ruby
27
+ backend = Deimos.schema_backend(schema: 'MySchema', namespace: 'com.my-namespace')
28
+ backend.encode(my_payload)
29
+ backend.decode(my_payload)
30
+ ```
31
+
32
+ The two classes are different and if you are using them to e.g.
33
+ inspect Avro schema fields, please look at the source code for the following:
34
+ * `Deimos::SchemaBackends::Base`
35
+ * `Deimos::SchemaBackends::AvroBase`
36
+ * `Deimos::SchemaBackends::AvroSchemaRegistry`
37
+
38
+ Deprecated `Deimos::TestHelpers.sent_messages` in favor of
39
+ `Deimos::Backends::Test.sent_messages`.
40
+
41
+ ## Upgrading from < 1.4.0 to >= 1.4.0
42
+
43
+ Previously, configuration was handled as follows:
44
+ * Kafka configuration, including listeners, lived in `phobos.yml`
45
+ * Additional Deimos configuration would live in an initializer, e.g. `kafka.rb`
46
+ * Producer and consumer configuration lived in each individual producer and consumer
47
+
48
+ As of 1.4.0, all configuration is centralized in one initializer
49
+ file, using default configuration.
50
+
51
+ Before 1.4.0:
52
+ ```yaml
53
+ # config/phobos.yml
54
+ logger:
55
+ file: log/phobos.log
56
+ level: debug
57
+ ruby_kafka:
58
+ level: debug
59
+
60
+ kafka:
61
+ client_id: phobos
62
+ connect_timeout: 15
63
+ socket_timeout: 15
64
+
65
+ producer:
66
+ ack_timeout: 5
67
+ required_acks: :all
68
+ ...
69
+
70
+ listeners:
71
+ - handler: ConsumerTest::MyConsumer
72
+ topic: my_consume_topic
73
+ group_id: my_group_id
74
+ - handler: ConsumerTest::MyBatchConsumer
75
+ topic: my_batch_consume_topic
76
+ group_id: my_batch_group_id
77
+ delivery: inline_batch
78
+ ```
79
+
80
+ ```ruby
81
+ # kafka.rb
82
+ Deimos.configure do |config|
83
+ config.reraise_consumer_errors = true
84
+ config.logger = Rails.logger
85
+ ...
86
+ end
87
+
88
+ # my_consumer.rb
89
+ class ConsumerTest::MyConsumer < Deimos::Producer
90
+ namespace 'com.my-namespace'
91
+ schema 'MySchema'
92
+ topic 'MyTopic'
93
+ key_config field: :id
94
+ end
95
+ ```
96
+
97
+ After 1.4.0:
98
+ ```ruby
99
+ kafka.rb
100
+ Deimos.configure do
101
+ logger Rails.logger
102
+ kafka do
103
+ client_id 'phobos'
104
+ connect_timeout 15
105
+ socket_timeout 15
106
+ end
107
+ producers.ack_timeout 5
108
+ producers.required_acks :all
109
+ ...
110
+ consumer do
111
+ class_name 'ConsumerTest::MyConsumer'
112
+ topic 'my_consume_topic'
113
+ group_id 'my_group_id'
114
+ namespace 'com.my-namespace'
115
+ schema 'MySchema'
116
+ topic 'MyTopic'
117
+ key_config field: :id
118
+ end
119
+ ...
120
+ end
121
+ ```
122
+
123
+ Note that the old configuration way *will* work if you set
124
+ `config.phobos_config_file = "config/phobos.yml"`. You will
125
+ get a number of deprecation notices, however. You can also still
126
+ set the topic, namespace, etc. on the producer/consumer class,
127
+ but it's much more convenient to centralize these configs
128
+ in one place to see what your app does.
@@ -15,7 +15,7 @@ module Deimos
15
15
 
16
16
  # @override
17
17
  def encode_payload(payload, schema: nil, topic: nil)
18
- avro_turf_messaging.encode(payload, schema_name: schema, subject: topic)
18
+ avro_turf_messaging.encode(payload, schema_name: schema, subject: topic || schema)
19
19
  end
20
20
 
21
21
  private
@@ -19,7 +19,7 @@ module Deimos
19
19
  offset = last_offset - num_messages
20
20
  if offset.positive?
21
21
  Deimos.config.logger.info("Seeking to #{offset}")
22
- @consumer.seek(topic, 1, offset)
22
+ @consumer.seek(topic, 0, offset)
23
23
  end
24
24
  rescue StandardError => e
25
25
  "Could not seek to offset: #{e.message}"
@@ -28,14 +28,18 @@ module Deimos
28
28
 
29
29
  # Indicate which schemas should be assigned to actions.
30
30
  # @param actions [Symbol]
31
+ # @param kwactions [String]
31
32
  # @param request [String]
32
33
  # @param response [String]
33
- def schemas(*actions, request: nil, response: nil)
34
+ def schemas(*actions, request: nil, response: nil, **kwactions)
34
35
  actions.each do |action|
35
36
  request ||= action.to_s.titleize
36
37
  response ||= action.to_s.titleize
37
38
  schema_mapping[action.to_s] = { request: request, response: response }
38
39
  end
40
+ kwactions.each do |key, val|
41
+ schema_mapping[key.to_s] = { request: val, response: val }
42
+ end
39
43
  end
40
44
 
41
45
  # @return [Hash<Symbol, String>]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.8.2-beta1'
4
+ VERSION = '1.8.2-beta2'
5
5
  end
@@ -0,0 +1,11 @@
1
+ {
2
+ "namespace": "com.my-namespace.request",
3
+ "name": "CreateTopic",
4
+ "type": "record",
5
+ "fields": [
6
+ {
7
+ "name": "request_id",
8
+ "type": "string"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "namespace": "com.my-namespace.response",
3
+ "name": "CreateTopic",
4
+ "type": "record",
5
+ "fields": [
6
+ {
7
+ "name": "response_id",
8
+ "type": "string"
9
+ }
10
+ ]
11
+ }
@@ -17,6 +17,7 @@ RSpec.describe Deimos::Utils::SchemaControllerMixin, type: :controller do
17
17
  request_namespace 'com.my-namespace.request'
18
18
  response_namespace 'com.my-namespace.response'
19
19
  schemas :index, :show
20
+ schemas create: 'CreateTopic'
20
21
  schemas :update, request: 'UpdateRequest', response: 'UpdateResponse'
21
22
 
22
23
  # :nodoc:
@@ -29,6 +30,11 @@ RSpec.describe Deimos::Utils::SchemaControllerMixin, type: :controller do
29
30
  render_schema({ 'response_id' => payload[:request_id] + ' dad' })
30
31
  end
31
32
 
33
+ # :nodoc:
34
+ def create
35
+ render_schema({ 'response_id' => payload[:request_id] + ' bro' })
36
+ end
37
+
32
38
  # :nodoc:
33
39
  def update
34
40
  render_schema({ 'update_response_id' => payload[:update_request_id] + ' sis' })
@@ -65,4 +71,14 @@ RSpec.describe Deimos::Utils::SchemaControllerMixin, type: :controller do
65
71
  expect(response_backend.decode(response.body)).to eq({ 'update_response_id' => 'hi sis' })
66
72
  end
67
73
 
74
+ it 'should render the correct response for create' do
75
+ request_backend = Deimos.schema_backend(schema: 'CreateTopic',
76
+ namespace: 'com.my-namespace.request')
77
+ response_backend = Deimos.schema_backend(schema: 'CreateTopic',
78
+ namespace: 'com.my-namespace.response')
79
+ request.content_type = 'avro/binary'
80
+ post :create, params: { id: 1 }, body: request_backend.encode({ 'request_id' => 'hi' })
81
+ expect(response_backend.decode(response.body)).to eq({ 'response_id' => 'hi bro' })
82
+ end
83
+
68
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deimos-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2.pre.beta1
4
+ version: 1.8.2.pre.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-09 00:00:00.000000000 Z
11
+ date: 2020-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro_turf
@@ -349,6 +349,7 @@ files:
349
349
  - docs/CONFIGURATION.md
350
350
  - docs/DATABASE_BACKEND.md
351
351
  - docs/PULL_REQUEST_TEMPLATE.md
352
+ - docs/UPGRADING.md
352
353
  - lib/deimos.rb
353
354
  - lib/deimos/active_record_consume/batch_consumption.rb
354
355
  - lib/deimos/active_record_consume/batch_slicer.rb
@@ -453,8 +454,10 @@ files:
453
454
  - spec/schemas/com/my-namespace/Wibble.avsc
454
455
  - spec/schemas/com/my-namespace/Widget.avsc
455
456
  - spec/schemas/com/my-namespace/WidgetTheSecond.avsc
457
+ - spec/schemas/com/my-namespace/request/CreateTopic.avsc
456
458
  - spec/schemas/com/my-namespace/request/Index.avsc
457
459
  - spec/schemas/com/my-namespace/request/UpdateRequest.avsc
460
+ - spec/schemas/com/my-namespace/response/CreateTopic.avsc
458
461
  - spec/schemas/com/my-namespace/response/Index.avsc
459
462
  - spec/schemas/com/my-namespace/response/UpdateResponse.avsc
460
463
  - spec/spec_helper.rb
@@ -487,7 +490,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
487
490
  - !ruby/object:Gem::Version
488
491
  version: 1.3.1
489
492
  requirements: []
490
- rubygems_version: 3.1.3
493
+ rubygems_version: 3.1.2
491
494
  signing_key:
492
495
  specification_version: 4
493
496
  summary: Kafka libraries for Ruby.
@@ -534,8 +537,10 @@ test_files:
534
537
  - spec/schemas/com/my-namespace/Wibble.avsc
535
538
  - spec/schemas/com/my-namespace/Widget.avsc
536
539
  - spec/schemas/com/my-namespace/WidgetTheSecond.avsc
540
+ - spec/schemas/com/my-namespace/request/CreateTopic.avsc
537
541
  - spec/schemas/com/my-namespace/request/Index.avsc
538
542
  - spec/schemas/com/my-namespace/request/UpdateRequest.avsc
543
+ - spec/schemas/com/my-namespace/response/CreateTopic.avsc
539
544
  - spec/schemas/com/my-namespace/response/Index.avsc
540
545
  - spec/schemas/com/my-namespace/response/UpdateResponse.avsc
541
546
  - spec/spec_helper.rb