glass_octopus 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -1
- data/example/avro.rb +26 -0
- data/glass_octopus.gemspec +4 -0
- data/lib/glass_octopus/middleware/avro_parser.rb +35 -0
- data/lib/glass_octopus/middleware.rb +1 -0
- data/lib/glass_octopus/version.rb +1 -1
- metadata +61 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fbc955a7cddf1c08e93db127bd2ccf5a3fb025a2a03e95bfc6ab7de54e50914
|
4
|
+
data.tar.gz: 85085902b9c8c4c38e2c8813f68934f9a54ccab436c21f7519de633eff4eeb83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe14d5ee99f0fb900b4d4b7e9454409d462c399086e30a61dfab61b7ee4a0d69ec4ef06a2d8c88d3c1d13f72e1ff65f17d1334bbe4cfb2e92448af0135b5dfc7
|
7
|
+
data.tar.gz: 1e7e850864f9455a64524c09d48fa9d552e9ab6a4ae91f6244ef343a6dda1d76d5a414b7daee68a0e127c0191391253b4000004f11235a653188a618a8cb032e
|
data/README.md
CHANGED
@@ -63,7 +63,27 @@ end
|
|
63
63
|
|
64
64
|
Run it with `bundle exec ruby app.rb`
|
65
65
|
|
66
|
-
|
66
|
+
### Handling Avro messages with Schema Registry
|
67
|
+
|
68
|
+
Glass Octopus can be used with Avro messages validated against a schema. For this, you need a running [Schema Registry](https://docs.confluent.io/current/schema-registry/docs/index.html) service.
|
69
|
+
You also need to have the `avro_turf` gem installed.
|
70
|
+
|
71
|
+
```
|
72
|
+
# in your Gemfile
|
73
|
+
gem "avro_turf"
|
74
|
+
```
|
75
|
+
|
76
|
+
Add the `AvroParser` middleware with the Schema Registry URL to your app.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
# in app.rb
|
80
|
+
app = GlassOctopus.build do
|
81
|
+
use GlassOctopus::Middleware::AvroParser, "http://schema_registry_url:8081"
|
82
|
+
...
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
For more examples look into the [example](example) directory.
|
67
87
|
|
68
88
|
For the API documentation please see the [documentation site][rubydoc]
|
69
89
|
|
data/example/avro.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "glass_octopus"
|
3
|
+
|
4
|
+
app = GlassOctopus.build do
|
5
|
+
use GlassOctopus::Middleware::CommonLogger
|
6
|
+
use GlassOctopus::Middleware::AvroParser, "http://schema_registry_url:8081"
|
7
|
+
|
8
|
+
run Proc.new { |ctx|
|
9
|
+
puts "Got message: #{ctx.message.key} => #{ctx.message.value}"
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def array_from_env(key, default:)
|
14
|
+
return default unless ENV.key?(key)
|
15
|
+
ENV.fetch(key).split(",").map(&:strip)
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
GlassOctopus.run(app) do |config|
|
20
|
+
config.adapter :ruby_kafka do |kafka|
|
21
|
+
kafka.broker_list = array_from_env("KAFKA_BROKER_LIST", default: %w[localhost:9092])
|
22
|
+
kafka.topic = ENV.fetch("KAFKA_TOPIC", "mytopic")
|
23
|
+
kafka.group = ENV.fetch("KAFKA_GROUP", "mygroup")
|
24
|
+
kafka.client = { logger: config.logger }
|
25
|
+
end
|
26
|
+
end
|
data/glass_octopus.gemspec
CHANGED
@@ -31,4 +31,8 @@ EOF
|
|
31
31
|
spec.add_development_dependency "guard", "~> 2.14"
|
32
32
|
spec.add_development_dependency "guard-minitest", "~> 2.4"
|
33
33
|
spec.add_development_dependency "terminal-notifier-guard", "~> 1.7"
|
34
|
+
spec.add_development_dependency "ruby-kafka", "~> 0.5.2"
|
35
|
+
spec.add_development_dependency "avro_turf", "~> 0.8.0"
|
36
|
+
spec.add_development_dependency "sinatra", "~> 2.0.0"
|
37
|
+
spec.add_development_dependency "webmock", "~> 3.3.0"
|
34
38
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "delegate"
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "avro_turf/messaging"
|
5
|
+
rescue LoadError
|
6
|
+
raise "Can't find 'avro_turf' gem. Please add it to your Gemfile or install it."
|
7
|
+
end
|
8
|
+
|
9
|
+
module GlassOctopus
|
10
|
+
module Middleware
|
11
|
+
class AvroParser
|
12
|
+
def initialize(app, schema_registry_url, options={})
|
13
|
+
@app = app
|
14
|
+
@decoder = AvroTurf::Messaging.new(registry_url: schema_registry_url, logger: options[:logger])
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(ctx)
|
18
|
+
message = @decoder.decode(ctx.message.value)
|
19
|
+
ctx = ContextWithAvroParsedMessage.new(ctx, message)
|
20
|
+
@app.call(ctx)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
class ContextWithAvroParsedMessage < SimpleDelegator
|
26
|
+
attr_reader :params
|
27
|
+
|
28
|
+
def initialize(wrapped_ctx, params)
|
29
|
+
super(wrapped_ctx)
|
30
|
+
@params = params
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -3,6 +3,7 @@ module GlassOctopus
|
|
3
3
|
autoload :ActiveRecord, "glass_octopus/middleware/active_record"
|
4
4
|
autoload :CommonLogger, "glass_octopus/middleware/common_logger"
|
5
5
|
autoload :JsonParser, "glass_octopus/middleware/json_parser"
|
6
|
+
autoload :AvroParser, "glass_octopus/middleware/avro_parser"
|
6
7
|
autoload :Mongoid, "glass_octopus/middleware/mongoid"
|
7
8
|
autoload :NewRelic, "glass_octopus/middleware/new_relic"
|
8
9
|
autoload :Sentry, "glass_octopus/middleware/sentry"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glass_octopus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tamás Michelberger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -114,6 +114,62 @@ dependencies:
|
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '1.7'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: ruby-kafka
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 0.5.2
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.5.2
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: avro_turf
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 0.8.0
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 0.8.0
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: sinatra
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 2.0.0
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 2.0.0
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: webmock
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 3.3.0
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - "~>"
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 3.3.0
|
117
173
|
description: |
|
118
174
|
GlassOctopus provides a minimal, modular and adaptable interface for developing
|
119
175
|
Kafka consumers in Ruby. In its philosophy it is very close to Rack.
|
@@ -135,6 +191,7 @@ files:
|
|
135
191
|
- bin/rake
|
136
192
|
- docker-compose.yml
|
137
193
|
- example/advanced.rb
|
194
|
+
- example/avro.rb
|
138
195
|
- example/basic.rb
|
139
196
|
- example/ruby_kafka.rb
|
140
197
|
- glass_octopus.gemspec
|
@@ -152,6 +209,7 @@ files:
|
|
152
209
|
- lib/glass_octopus/message.rb
|
153
210
|
- lib/glass_octopus/middleware.rb
|
154
211
|
- lib/glass_octopus/middleware/active_record.rb
|
212
|
+
- lib/glass_octopus/middleware/avro_parser.rb
|
155
213
|
- lib/glass_octopus/middleware/common_logger.rb
|
156
214
|
- lib/glass_octopus/middleware/json_parser.rb
|
157
215
|
- lib/glass_octopus/middleware/mongoid.rb
|
@@ -180,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
238
|
version: '0'
|
181
239
|
requirements: []
|
182
240
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.7.
|
241
|
+
rubygems_version: 2.7.4
|
184
242
|
signing_key:
|
185
243
|
specification_version: 4
|
186
244
|
summary: A Kafka consumer framework. Like Rack but for Kafka.
|