deimos-ruby 1.8.0.pre.beta1 → 1.8.1.pre.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -4
  3. data/CHANGELOG.md +42 -0
  4. data/Gemfile.lock +101 -73
  5. data/README.md +78 -1
  6. data/deimos-ruby.gemspec +2 -2
  7. data/lib/deimos.rb +4 -3
  8. data/lib/deimos/consume/batch_consumption.rb +2 -0
  9. data/lib/deimos/consume/message_consumption.rb +1 -0
  10. data/lib/deimos/instrumentation.rb +10 -5
  11. data/lib/deimos/kafka_topic_info.rb +21 -2
  12. data/lib/deimos/schema_backends/avro_base.rb +33 -1
  13. data/lib/deimos/schema_backends/avro_schema_coercer.rb +30 -9
  14. data/lib/deimos/schema_backends/base.rb +21 -2
  15. data/lib/deimos/utils/db_producer.rb +57 -19
  16. data/lib/deimos/utils/schema_controller_mixin.rb +111 -0
  17. data/lib/deimos/version.rb +1 -1
  18. data/lib/generators/deimos/active_record/templates/migration.rb.tt +28 -0
  19. data/lib/generators/deimos/active_record/templates/model.rb.tt +5 -0
  20. data/lib/generators/deimos/active_record_generator.rb +79 -0
  21. data/lib/generators/deimos/db_backend/templates/migration +1 -0
  22. data/lib/generators/deimos/db_backend/templates/rails3_migration +1 -0
  23. data/spec/batch_consumer_spec.rb +1 -0
  24. data/spec/generators/active_record_generator_spec.rb +56 -0
  25. data/spec/kafka_listener_spec.rb +54 -0
  26. data/spec/kafka_topic_info_spec.rb +39 -16
  27. data/spec/producer_spec.rb +36 -0
  28. data/spec/schemas/com/my-namespace/Generated.avsc +71 -0
  29. data/spec/schemas/com/my-namespace/MyNestedSchema.avsc +62 -0
  30. data/spec/schemas/com/my-namespace/request/Index.avsc +11 -0
  31. data/spec/schemas/com/my-namespace/request/UpdateRequest.avsc +11 -0
  32. data/spec/schemas/com/my-namespace/response/Index.avsc +11 -0
  33. data/spec/schemas/com/my-namespace/response/UpdateResponse.avsc +11 -0
  34. data/spec/spec_helper.rb +7 -0
  35. data/spec/utils/db_producer_spec.rb +84 -10
  36. data/spec/utils/schema_controller_mixin_spec.rb +68 -0
  37. metadata +40 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82c1b89b49622cb0d47a7a7aa56e076d908785906581f9f0772f09679acd6895
4
- data.tar.gz: eeadf1d1a63db1407a81ef1f993be1b8d421e8e2624b9f42c324a2dad776bd1c
3
+ metadata.gz: bb7b72866d42e8a74dfe9e441b5e1436c81cb16684d2985840980c010416e8af
4
+ data.tar.gz: 97b806b1b52807ea487a0da20099450d005bf71ac4cd88fbc5eb50aae66726bb
5
5
  SHA512:
6
- metadata.gz: 6a85cd1d407c11d4becb6d6d11636623b96c706325f8bbca52caf4bf0cdce079df65432cb076d01503a4d4d977c8a662c22622e27193aeafc87ffbdc8d934045
7
- data.tar.gz: '08f9b75f3057071f41effaf870f8d0927dca85d647726ba833371001c470a7a062ee74ac63b5acc2f284493d3a32373ffb6c3ca96f9428ffb762c83cfd804c42'
6
+ metadata.gz: 0d98923fd57076e391a9e8e1c2a6afb83fbde7769d646fc88d599921d9b0d55a6b1c7bd0df7f3344c71c66915766484bd0c9c19cfa72fef7f9299ab41cf66232
7
+ data.tar.gz: c537564c70e3d297ca76000cd683f6c0891c18dc3b54d95b9aa6f3ea4b390a59fd2992d070112afc1e562c0bc59e0a4b523cb7bd4d71efafe2b03083df5273a6
@@ -5,6 +5,7 @@ AllCops:
5
5
  Exclude:
6
6
  - lib/deimos/monkey_patches/*.rb
7
7
  - vendor/**/*
8
+ - Guardfile
8
9
  NewCops: enable
9
10
 
10
11
  # class Plumbus
@@ -36,7 +37,7 @@ Layout/EmptyLinesAroundBlockBody:
36
37
  Enabled: false
37
38
 
38
39
  Layout/LineLength:
39
- Max: 100
40
+ Max: 120
40
41
  Severity: refactor
41
42
  Exclude:
42
43
  - 'spec/**/*'
@@ -77,13 +78,14 @@ Lint/UnusedMethodArgument:
77
78
 
78
79
  Metrics/AbcSize:
79
80
  Severity: refactor
80
- Max: 20
81
+ Max: 25
81
82
 
82
83
  Metrics/BlockLength:
83
- Severity: refactor
84
+ Enabled: false
84
85
 
85
86
  Metrics/ClassLength:
86
87
  Severity: refactor
88
+ Max: 500
87
89
 
88
90
  Metrics/CyclomaticComplexity:
89
91
  Severity: refactor
@@ -91,10 +93,11 @@ Metrics/CyclomaticComplexity:
91
93
 
92
94
  Metrics/MethodLength:
93
95
  Severity: refactor
94
- Max: 30
96
+ Max: 50
95
97
 
96
98
  Metrics/ModuleLength:
97
99
  Severity: refactor
100
+ Max: 200
98
101
 
99
102
  Metrics/ParameterLists:
100
103
  Max: 5
@@ -102,6 +105,7 @@ Metrics/ParameterLists:
102
105
 
103
106
  Metrics/PerceivedComplexity:
104
107
  Severity: refactor
108
+ Max: 10
105
109
 
106
110
  # Use alias_method instead of alias
107
111
  Style/Alias:
@@ -7,11 +7,53 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ ## 1.8.1-beta4 - 2020-08-12
11
+
12
+ ### Fixes :wrench:
13
+ - Fix regression bug where arrays were not being encoded
14
+
15
+ ## 1.8.1-beta3 - 2020-08-05
16
+
17
+ ### Fixes :wrench:
18
+ - Simplify decoding messages and handle producer not found
19
+ - Consolidate types in sub-records recursively
20
+ (fixes [#72](https://github.com/flipp-oss/deimos/issues/72))
21
+
22
+ ## 1.8.1-beta2 - 2020-07-28
23
+
24
+ ### Features :star:
25
+ - Add `SchemaControllerMixin` to encode and decode schema-encoded
26
+ payloads in Rails controllers.
27
+
28
+ ## 1.8.1-beta1 - 2020-07-22
29
+
30
+ ### Fixes :wrench:
31
+ - Retry deleting messages without resending the batch if the
32
+ delete fails (fixes [#34](https://github.com/flipp-oss/deimos/issues/34))
33
+ - Delete messages in batches rather than all at once to
34
+ cut down on the chance of a deadlock.
35
+
36
+ ### Features :star:
37
+ - Add `last_processed_at` to `kafka_topic_info` to ensure
38
+ that wait metrics are accurate in cases where records
39
+ get created with an old `created_at` time (e.g. for
40
+ long-running transactions).
41
+ - Add generator for ActiveRecord models and migrations (fixes [#6](https://github.com/flipp-oss/deimos/issues/6))
42
+
43
+ ## 1.8.0-beta2 - 2020-07-08
44
+
45
+ ### Fixes :wrench:
46
+ - Fix crash with batch consumption due to not having ActiveSupport::Concern
47
+
48
+ ### Features :star:
49
+ - Add `first_offset` to the metadata sent via the batch
50
+
10
51
  ## 1.8.0-beta1 - 2020-07-06
11
52
  ### Features :star:
12
53
  - Added `ActiveRecordConsumer` batch mode
13
54
 
14
55
  ### Fixes :wrench:
56
+ - Fixes `send_produce_error` to decode `failed_messages` with built-in decoder.
15
57
  - Lag calculation can be incorrect if no messages are being consumed.
16
58
  - Fixed bug where printing messages on a MessageSizeTooLarge
17
59
  error didn't work.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deimos-ruby (1.7.0.pre.beta1)
4
+ deimos-ruby (1.8.1.pre.beta3)
5
5
  avro_turf (~> 0.11)
6
6
  phobos (~> 1.9)
7
7
  ruby-kafka (~> 0.7)
@@ -10,72 +10,86 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actioncable (5.2.4.2)
14
- actionpack (= 5.2.4.2)
13
+ actioncable (6.0.3.2)
14
+ actionpack (= 6.0.3.2)
15
15
  nio4r (~> 2.0)
16
16
  websocket-driver (>= 0.6.1)
17
- actionmailer (5.2.4.2)
18
- actionpack (= 5.2.4.2)
19
- actionview (= 5.2.4.2)
20
- activejob (= 5.2.4.2)
17
+ actionmailbox (6.0.3.2)
18
+ actionpack (= 6.0.3.2)
19
+ activejob (= 6.0.3.2)
20
+ activerecord (= 6.0.3.2)
21
+ activestorage (= 6.0.3.2)
22
+ activesupport (= 6.0.3.2)
23
+ mail (>= 2.7.1)
24
+ actionmailer (6.0.3.2)
25
+ actionpack (= 6.0.3.2)
26
+ actionview (= 6.0.3.2)
27
+ activejob (= 6.0.3.2)
21
28
  mail (~> 2.5, >= 2.5.4)
22
29
  rails-dom-testing (~> 2.0)
23
- actionpack (5.2.4.2)
24
- actionview (= 5.2.4.2)
25
- activesupport (= 5.2.4.2)
30
+ actionpack (6.0.3.2)
31
+ actionview (= 6.0.3.2)
32
+ activesupport (= 6.0.3.2)
26
33
  rack (~> 2.0, >= 2.0.8)
27
34
  rack-test (>= 0.6.3)
28
35
  rails-dom-testing (~> 2.0)
29
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
- actionview (5.2.4.2)
31
- activesupport (= 5.2.4.2)
36
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
+ actiontext (6.0.3.2)
38
+ actionpack (= 6.0.3.2)
39
+ activerecord (= 6.0.3.2)
40
+ activestorage (= 6.0.3.2)
41
+ activesupport (= 6.0.3.2)
42
+ nokogiri (>= 1.8.5)
43
+ actionview (6.0.3.2)
44
+ activesupport (= 6.0.3.2)
32
45
  builder (~> 3.1)
33
46
  erubi (~> 1.4)
34
47
  rails-dom-testing (~> 2.0)
35
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
36
- activejob (5.2.4.2)
37
- activesupport (= 5.2.4.2)
48
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
49
+ activejob (6.0.3.2)
50
+ activesupport (= 6.0.3.2)
38
51
  globalid (>= 0.3.6)
39
- activemodel (5.2.4.2)
40
- activesupport (= 5.2.4.2)
41
- activerecord (5.2.4.2)
42
- activemodel (= 5.2.4.2)
43
- activesupport (= 5.2.4.2)
44
- arel (>= 9.0)
45
- activerecord-import (1.0.4)
52
+ activemodel (6.0.3.2)
53
+ activesupport (= 6.0.3.2)
54
+ activerecord (6.0.3.2)
55
+ activemodel (= 6.0.3.2)
56
+ activesupport (= 6.0.3.2)
57
+ activerecord-import (1.0.5)
46
58
  activerecord (>= 3.2)
47
- activestorage (5.2.4.2)
48
- actionpack (= 5.2.4.2)
49
- activerecord (= 5.2.4.2)
59
+ activestorage (6.0.3.2)
60
+ actionpack (= 6.0.3.2)
61
+ activejob (= 6.0.3.2)
62
+ activerecord (= 6.0.3.2)
50
63
  marcel (~> 0.3.1)
51
- activesupport (5.2.4.2)
64
+ activesupport (6.0.3.2)
52
65
  concurrent-ruby (~> 1.0, >= 1.0.2)
53
66
  i18n (>= 0.7, < 2)
54
67
  minitest (~> 5.1)
55
68
  tzinfo (~> 1.1)
56
- arel (9.0.0)
57
- ast (2.4.0)
69
+ zeitwerk (~> 2.2, >= 2.2.2)
70
+ ast (2.4.1)
58
71
  avro (1.9.2)
59
72
  multi_json
60
73
  avro_turf (0.11.0)
61
74
  avro (>= 1.7.7, < 1.10)
62
75
  excon (~> 0.45)
63
76
  builder (3.2.4)
64
- coderay (1.1.2)
77
+ coderay (1.1.3)
65
78
  concurrent-ruby (1.1.6)
66
79
  concurrent-ruby-ext (1.1.6)
67
80
  concurrent-ruby (= 1.1.6)
68
81
  crass (1.0.6)
69
82
  database_cleaner (1.8.5)
70
- ddtrace (0.35.1)
83
+ ddtrace (0.37.0)
71
84
  msgpack
72
- diff-lcs (1.3)
73
- digest-crc (0.5.1)
74
- dogstatsd-ruby (4.8.0)
85
+ diff-lcs (1.4.4)
86
+ digest-crc (0.6.1)
87
+ rake (~> 13.0)
88
+ dogstatsd-ruby (4.8.1)
75
89
  erubi (1.9.0)
76
- excon (0.73.0)
90
+ excon (0.76.0)
77
91
  exponential-backoff (0.0.4)
78
- ffi (1.12.2)
92
+ ffi (1.13.1)
79
93
  formatador (0.2.5)
80
94
  globalid (0.4.2)
81
95
  activesupport (>= 4.2.0)
@@ -96,20 +110,19 @@ GEM
96
110
  guard-rubocop (1.3.0)
97
111
  guard (~> 2.0)
98
112
  rubocop (~> 0.20)
99
- i18n (1.8.2)
113
+ i18n (1.8.4)
100
114
  concurrent-ruby (~> 1.0)
101
- jaro_winkler (1.5.4)
102
115
  listen (3.2.1)
103
116
  rb-fsevent (~> 0.10, >= 0.10.3)
104
117
  rb-inotify (~> 0.9, >= 0.9.10)
105
118
  little-plugger (1.1.4)
106
- logging (2.2.2)
119
+ logging (2.3.0)
107
120
  little-plugger (~> 1.1)
108
- multi_json (~> 1.10)
109
- loofah (2.5.0)
121
+ multi_json (~> 1.14)
122
+ loofah (2.6.0)
110
123
  crass (~> 1.0.2)
111
124
  nokogiri (>= 1.5.9)
112
- lumberjack (1.2.4)
125
+ lumberjack (1.2.6)
113
126
  mail (2.7.1)
114
127
  mini_mime (>= 0.1.1)
115
128
  marcel (0.3.3)
@@ -118,20 +131,20 @@ GEM
118
131
  mimemagic (0.3.5)
119
132
  mini_mime (1.0.2)
120
133
  mini_portile2 (2.4.0)
121
- minitest (5.14.0)
134
+ minitest (5.14.1)
122
135
  msgpack (1.3.3)
123
- multi_json (1.14.1)
136
+ multi_json (1.15.0)
124
137
  mysql2 (0.5.3)
125
138
  nenv (0.3.0)
126
139
  nio4r (2.5.2)
127
- nokogiri (1.10.9)
140
+ nokogiri (1.10.10)
128
141
  mini_portile2 (~> 2.4.0)
129
142
  notiffany (0.1.3)
130
143
  nenv (~> 0.1)
131
144
  shellany (~> 0.0)
132
- parallel (1.19.1)
133
- parser (2.7.1.2)
134
- ast (~> 2.4.0)
145
+ parallel (1.19.2)
146
+ parser (2.7.1.4)
147
+ ast (~> 2.4.1)
135
148
  pg (1.2.3)
136
149
  phobos (1.9.0)
137
150
  activesupport (>= 3.0.0)
@@ -147,35 +160,38 @@ GEM
147
160
  rack (2.2.3)
148
161
  rack-test (1.1.0)
149
162
  rack (>= 1.0, < 3)
150
- rails (5.2.4.2)
151
- actioncable (= 5.2.4.2)
152
- actionmailer (= 5.2.4.2)
153
- actionpack (= 5.2.4.2)
154
- actionview (= 5.2.4.2)
155
- activejob (= 5.2.4.2)
156
- activemodel (= 5.2.4.2)
157
- activerecord (= 5.2.4.2)
158
- activestorage (= 5.2.4.2)
159
- activesupport (= 5.2.4.2)
163
+ rails (6.0.3.2)
164
+ actioncable (= 6.0.3.2)
165
+ actionmailbox (= 6.0.3.2)
166
+ actionmailer (= 6.0.3.2)
167
+ actionpack (= 6.0.3.2)
168
+ actiontext (= 6.0.3.2)
169
+ actionview (= 6.0.3.2)
170
+ activejob (= 6.0.3.2)
171
+ activemodel (= 6.0.3.2)
172
+ activerecord (= 6.0.3.2)
173
+ activestorage (= 6.0.3.2)
174
+ activesupport (= 6.0.3.2)
160
175
  bundler (>= 1.3.0)
161
- railties (= 5.2.4.2)
176
+ railties (= 6.0.3.2)
162
177
  sprockets-rails (>= 2.0.0)
163
178
  rails-dom-testing (2.0.3)
164
179
  activesupport (>= 4.2.0)
165
180
  nokogiri (>= 1.6)
166
181
  rails-html-sanitizer (1.3.0)
167
182
  loofah (~> 2.3)
168
- railties (5.2.4.2)
169
- actionpack (= 5.2.4.2)
170
- activesupport (= 5.2.4.2)
183
+ railties (6.0.3.2)
184
+ actionpack (= 6.0.3.2)
185
+ activesupport (= 6.0.3.2)
171
186
  method_source
172
187
  rake (>= 0.8.7)
173
- thor (>= 0.19.0, < 2.0)
188
+ thor (>= 0.20.3, < 2.0)
174
189
  rainbow (3.0.0)
175
190
  rake (13.0.1)
176
191
  rb-fsevent (0.10.4)
177
192
  rb-inotify (0.10.1)
178
193
  ffi (~> 1.0)
194
+ regexp_parser (1.7.1)
179
195
  rexml (3.2.4)
180
196
  rspec (3.9.0)
181
197
  rspec-core (~> 3.9.0)
@@ -183,25 +199,36 @@ GEM
183
199
  rspec-mocks (~> 3.9.0)
184
200
  rspec-core (3.9.2)
185
201
  rspec-support (~> 3.9.3)
186
- rspec-expectations (3.9.1)
202
+ rspec-expectations (3.9.2)
187
203
  diff-lcs (>= 1.2.0, < 2.0)
188
204
  rspec-support (~> 3.9.0)
189
205
  rspec-mocks (3.9.1)
190
206
  diff-lcs (>= 1.2.0, < 2.0)
191
207
  rspec-support (~> 3.9.0)
208
+ rspec-rails (4.0.1)
209
+ actionpack (>= 4.2)
210
+ activesupport (>= 4.2)
211
+ railties (>= 4.2)
212
+ rspec-core (~> 3.9)
213
+ rspec-expectations (~> 3.9)
214
+ rspec-mocks (~> 3.9)
215
+ rspec-support (~> 3.9)
192
216
  rspec-support (3.9.3)
193
217
  rspec_junit_formatter (0.4.1)
194
218
  rspec-core (>= 2, < 4, != 2.12.0)
195
- rubocop (0.82.0)
196
- jaro_winkler (~> 1.5.1)
219
+ rubocop (0.88.0)
197
220
  parallel (~> 1.10)
198
- parser (>= 2.7.0.1)
221
+ parser (>= 2.7.1.1)
199
222
  rainbow (>= 2.2.2, < 4.0)
223
+ regexp_parser (>= 1.7)
200
224
  rexml
225
+ rubocop-ast (>= 0.1.0, < 1.0)
201
226
  ruby-progressbar (~> 1.7)
202
227
  unicode-display_width (>= 1.4.0, < 2.0)
203
- rubocop-rspec (1.39.0)
204
- rubocop (>= 0.68.1)
228
+ rubocop-ast (0.2.0)
229
+ parser (>= 2.7.0.1)
230
+ rubocop-rspec (1.42.0)
231
+ rubocop (>= 0.87.0)
205
232
  ruby-kafka (0.7.10)
206
233
  digest-crc
207
234
  ruby-progressbar (1.10.1)
@@ -209,7 +236,7 @@ GEM
209
236
  sigurd (0.0.1)
210
237
  concurrent-ruby (~> 1)
211
238
  exponential-backoff
212
- sprockets (4.0.0)
239
+ sprockets (4.0.2)
213
240
  concurrent-ruby (~> 1.0)
214
241
  rack (> 1, < 3)
215
242
  sprockets-rails (3.2.1)
@@ -222,15 +249,15 @@ GEM
222
249
  tzinfo (1.2.7)
223
250
  thread_safe (~> 0.1)
224
251
  unicode-display_width (1.7.0)
225
- websocket-driver (0.7.1)
252
+ websocket-driver (0.7.3)
226
253
  websocket-extensions (>= 0.1.0)
227
254
  websocket-extensions (0.1.5)
255
+ zeitwerk (2.4.0)
228
256
 
229
257
  PLATFORMS
230
258
  ruby
231
259
 
232
260
  DEPENDENCIES
233
- activerecord (~> 5.2)
234
261
  activerecord-import
235
262
  avro (~> 1.9)
236
263
  database_cleaner (~> 1.7)
@@ -242,9 +269,10 @@ DEPENDENCIES
242
269
  guard-rubocop (~> 1)
243
270
  mysql2 (~> 0.5)
244
271
  pg (~> 1.1)
245
- rails (~> 5.2, >= 5.2.4.2)
272
+ rails (~> 6)
246
273
  rake (~> 13)
247
274
  rspec (~> 3)
275
+ rspec-rails (~> 4)
248
276
  rspec_junit_formatter (~> 0.3)
249
277
  rubocop (~> 0.72)
250
278
  rubocop-rspec (~> 1.27)
data/README.md CHANGED
@@ -22,6 +22,7 @@ Built on Phobos and hence Ruby-Kafka.
22
22
  * [Kafka Message Keys](#kafka-message-keys)
23
23
  * [Consumers](#consumers)
24
24
  * [Rails Integration](#rails-integration)
25
+ * [Controller Mixin](#controller-mixin)
25
26
  * [Database Backend](#database-backend)
26
27
  * [Database Poller](#database-poller)
27
28
  * [Running Consumers](#running-consumers)
@@ -325,7 +326,8 @@ class MyBatchConsumer < Deimos::Consumer
325
326
 
326
327
  def consume_batch(payloads, metadata)
327
328
  # payloads is an array of schema-decoded hashes.
328
- # metadata is a hash that contains information like :keys and :topic.
329
+ # metadata is a hash that contains information like :keys, :topic,
330
+ # and :first_offset.
329
331
  # Keys are automatically decoded and available as an array with
330
332
  # the same cardinality as the payloads. If you need to iterate
331
333
  # over payloads and keys together, you can use something like this:
@@ -446,6 +448,58 @@ class Widget < ActiveRecord::Base
446
448
  end
447
449
  ```
448
450
 
451
+ ### Controller Mixin
452
+
453
+ Deimos comes with a mixin for `ActionController` which automatically encodes and decodes schema
454
+ payloads. There are some advantages to encoding your data in e.g. Avro rather than straight JSON,
455
+ particularly if your service is talking to another backend service rather than the front-end
456
+ browser:
457
+
458
+ * It enforces a contract between services. Solutions like [OpenAPI](https://swagger.io/specification/)
459
+ do this as well, but in order for the client to know the contract, usually some kind of code
460
+ generation has to happen. Using schemas ensures both sides know the contract without having to change code.
461
+ In addition, OpenAPI is now a huge and confusing format, and using simpler schema formats
462
+ can be beneficial.
463
+ * Using Avro or Protobuf ensures both forwards and backwards compatibility,
464
+ which reduces the need for versioning since both sides can simply ignore fields they aren't aware
465
+ of.
466
+ * Encoding and decoding using Avro or Protobuf is generally faster than straight JSON, and
467
+ results in smaller payloads and therefore less network traffic.
468
+
469
+ To use the mixin, add the following to your `WhateverController`:
470
+
471
+ ```ruby
472
+ class WhateverController < ApplicationController
473
+ include Deimos::Utils::SchemaControllerMixin
474
+
475
+ request_namespace 'my.namespace.requests'
476
+ response_namespace 'my.namespace.responses'
477
+
478
+ # Add a "schemas" line for all routes that should encode/decode schemas.
479
+ # Default is to match the schema name to the route name.
480
+ schemas :index
481
+ # will look for: my.namespace.requests.Index.avsc
482
+ # my.namespace.responses.Index.avsc
483
+
484
+ # If all routes use the default, you can add them all at once
485
+ schemas :index, :show, :update
486
+
487
+ # Different schemas can be specified as well
488
+ schemas :index, :show, request: 'IndexRequest', response: 'IndexResponse'
489
+
490
+ # To access the encoded data, use the `payload` helper method, and to render it back,
491
+ # use the `render_schema` method.
492
+
493
+ def index
494
+ response = { 'response_id' => payload['request_id'] + 'hi mom' }
495
+ render_schema(response)
496
+ end
497
+ end
498
+ ```
499
+
500
+ To make use of this feature, your requests and responses need to have the correct content type.
501
+ For Avro content, this is the `avro/binary` content type.
502
+
449
503
  # Database Backend
450
504
 
451
505
  Deimos provides a way to allow Kafka messages to be created inside a
@@ -556,6 +610,29 @@ class MyConsumer < Deimos::ActiveRecordConsumer
556
610
  end
557
611
  ```
558
612
 
613
+ #### Generating Tables and Models
614
+
615
+ Deimos provides a generator that takes an existing schema and generates a
616
+ database table based on its fields. By default, any complex sub-types (such as
617
+ records or arrays) are turned into JSON (if supported) or string columns.
618
+
619
+ Before running this migration, you must first copy the schema into your repo
620
+ in the correct path (in the example above, you would need to have a file
621
+ `{SCHEMA_ROOT}/com/my-namespace/MySchema.avsc`).
622
+
623
+ To generate a model and migration, run the following:
624
+
625
+ rails g deimos:active_record TABLE_NAME FULL_SCHEMA_NAME
626
+
627
+ Example:
628
+
629
+ rails g deimos:active_record my_table com.my-namespace.MySchema
630
+
631
+ ...would generate:
632
+
633
+ db/migrate/1234_create_my_table.rb
634
+ app/models/my_table.rb
635
+
559
636
  #### Batch Consumers
560
637
 
561
638
  Deimos also provides a batch consumption mode for `ActiveRecordConsumer` which