kril 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.rspec +2 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +79 -0
- data/README.md +21 -7
- data/bin/kril +83 -47
- data/lib/kril/consumer.rb +17 -11
- data/lib/kril/producer.rb +12 -3
- data/lib/kril/record_builder.rb +1 -1
- data/lib/kril/schema_extractor.rb +16 -13
- data/lib/kril/schema_handler.rb +54 -0
- data/lib/kril/version.rb +1 -1
- data/lib/kril.rb +6 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 273fc08c6713ec195cd1ccb84a067a58f0feeda9
|
4
|
+
data.tar.gz: be5b4f46adbc6202f85a6eb2a99f613654813998
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6149bb5ccb97c5c2052af671267703d90a91bc2c1604157213be09dea30035dd7ba3a29926b04c12fc6183d8b2527dbbc8afc5c6beb267291bda2e854a676ddf
|
7
|
+
data.tar.gz: 2ca0265144bcfda279602117da61876b9ed7d52061e316a89f49d8ab1d0906ead3f107849f173bd57f4750b32f5f780030393745ec5c406e8d3fa70644a30ec8
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kril (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.5.2)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
avro (1.8.2)
|
12
|
+
multi_json
|
13
|
+
avro_turf (0.8.0)
|
14
|
+
avro (>= 1.7.7, < 1.9)
|
15
|
+
excon (~> 0.45)
|
16
|
+
clamp (1.2.1)
|
17
|
+
crack (0.4.3)
|
18
|
+
safe_yaml (~> 1.0.0)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
excon (0.60.0)
|
21
|
+
hashdiff (0.3.7)
|
22
|
+
httparty (0.16.0)
|
23
|
+
multi_xml (>= 0.5.2)
|
24
|
+
multi_json (1.13.1)
|
25
|
+
multi_xml (0.6.0)
|
26
|
+
mustermann (1.0.2)
|
27
|
+
public_suffix (3.0.2)
|
28
|
+
rack (2.0.4)
|
29
|
+
rack-protection (2.0.1)
|
30
|
+
rack
|
31
|
+
rake (10.5.0)
|
32
|
+
rspec (3.7.0)
|
33
|
+
rspec-core (~> 3.7.0)
|
34
|
+
rspec-expectations (~> 3.7.0)
|
35
|
+
rspec-mocks (~> 3.7.0)
|
36
|
+
rspec-core (3.7.1)
|
37
|
+
rspec-support (~> 3.7.0)
|
38
|
+
rspec-expectations (3.7.0)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.7.0)
|
41
|
+
rspec-mocks (3.7.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.7.0)
|
44
|
+
rspec-nc (0.3.0)
|
45
|
+
rspec (>= 3)
|
46
|
+
terminal-notifier (>= 1.4)
|
47
|
+
rspec-support (3.7.1)
|
48
|
+
ruby-kafka (0.5.3)
|
49
|
+
safe_yaml (1.0.4)
|
50
|
+
sinatra (2.0.1)
|
51
|
+
mustermann (~> 1.0)
|
52
|
+
rack (~> 2.0)
|
53
|
+
rack-protection (= 2.0.1)
|
54
|
+
tilt (~> 2.0)
|
55
|
+
terminal-notifier (2.0.0)
|
56
|
+
tilt (2.0.8)
|
57
|
+
webmock (3.3.0)
|
58
|
+
addressable (>= 2.3.6)
|
59
|
+
crack (>= 0.3.2)
|
60
|
+
hashdiff
|
61
|
+
|
62
|
+
PLATFORMS
|
63
|
+
ruby
|
64
|
+
|
65
|
+
DEPENDENCIES
|
66
|
+
avro_turf (~> 0.8.0)
|
67
|
+
bundler (~> 1.16)
|
68
|
+
clamp (~> 1.2, >= 1.2.1)
|
69
|
+
httparty (~> 0.16.0)
|
70
|
+
kril!
|
71
|
+
rake (~> 10.0)
|
72
|
+
rspec (~> 3.7)
|
73
|
+
rspec-nc (~> 0.3.0)
|
74
|
+
ruby-kafka (~> 0.5.3)
|
75
|
+
sinatra (~> 2.0, >= 2.0.1)
|
76
|
+
webmock (~> 3.3)
|
77
|
+
|
78
|
+
BUNDLED WITH
|
79
|
+
1.16.0
|
data/README.md
CHANGED
@@ -26,12 +26,11 @@ Assuming your schema is not registered with the schema registry, and doesn't exi
|
|
26
26
|
```bash
|
27
27
|
$ kril --bootstrap-servers 'localhost:9092,localhost:9093,localhost:9094' \
|
28
28
|
--schema-registry 'http://localhost:8081' \
|
29
|
-
--
|
29
|
+
--schema '{"type":"record","name":"human","fields":[{"name":"age","type":"int"}]}' \
|
30
30
|
--record '{"age": 27}' \
|
31
31
|
human
|
32
32
|
```
|
33
33
|
```bash
|
34
|
-
🦐 saved human: {"type"=>"record", "name"=>"human", "fields"=>[{"name"=>"age", "type"=>"int"}]}
|
35
34
|
🦐 human: {"age"=>27}
|
36
35
|
```
|
37
36
|
|
@@ -53,7 +52,7 @@ $ kril --pretty-print human
|
|
53
52
|
}
|
54
53
|
```
|
55
54
|
---
|
56
|
-
|
55
|
+
Since the schema exists in our repository, we can produce records simply:
|
57
56
|
```bash
|
58
57
|
$ kril -r '{"age": 33}' human
|
59
58
|
```
|
@@ -73,16 +72,31 @@ $ kril --consume-all human
|
|
73
72
|
🦐 human: {:key=>nil, :value=>{"age"=>33}, :offset=>1, :create_time=>2018-03-04 00:34:07 -0700, :topic=>"human", :partition=>3}
|
74
73
|
🦐 human: {:key=>nil, :value=>{"age"=>27}, :offset=>0, :create_time=>2018-03-04 00:13:13 -0700, :topic=>"human", :partition=>0}
|
75
74
|
```
|
75
|
+
---
|
76
|
+
The `--schema` flag is flexible:
|
77
|
+
```bash
|
78
|
+
$ kril --schema /path/to/schema.avsc
|
79
|
+
$ kril --schema name_of_existing_schema
|
80
|
+
$ kril --schema '{"type":"record","name":"human","fields":[{"name":"age","type":"int"}]}'
|
81
|
+
```
|
82
|
+
---
|
83
|
+
If no topic is given, the topic will be inferred from the schema name:
|
84
|
+
```bash
|
85
|
+
$ kril -s human -r '{"age":99}'
|
86
|
+
```
|
87
|
+
```bash
|
88
|
+
🦐 human: {"age"=>99}
|
89
|
+
```
|
76
90
|
|
77
91
|
## Contributing
|
78
92
|
|
79
93
|
1. Fork it ( https://github.com/ChadBowman/kril/fork )
|
80
|
-
2. Create your feature branch (git checkout -b my-new-feature)
|
81
|
-
3. Commit your changes (git commit -am 'add some feature')
|
82
|
-
4. Push to the branch (git push origin my-new-feature)
|
94
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
95
|
+
3. Commit your changes (`git commit -am 'add some feature'`)
|
96
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
97
|
5. Create a new Pull Request
|
84
98
|
|
85
|
-
Please try to obey [Rubocop](https://github.com/bbatsov/rubocop) to the best of your abilities.
|
99
|
+
Please try to obey 👮[Rubocop](https://github.com/bbatsov/rubocop) to the best of your abilities.
|
86
100
|
|
87
101
|
## License
|
88
102
|
|
data/bin/kril
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
-
$VERBOSE =
|
3
|
+
$VERBOSE = nil
|
4
4
|
|
5
5
|
require 'avro_turf/messaging'
|
6
6
|
require 'kafka'
|
@@ -8,72 +8,108 @@ require 'clamp'
|
|
8
8
|
require 'kril'
|
9
9
|
|
10
10
|
Clamp do
|
11
|
-
|
11
|
+
$log = Logger.new($STDOUT)
|
12
|
+
$log.level = Logger::ERROR
|
13
|
+
|
14
|
+
option %w[--version], :flag, 'show version' do
|
15
|
+
puts Kril::VERSION
|
16
|
+
exit(0)
|
17
|
+
end
|
18
|
+
|
19
|
+
# configuration
|
20
|
+
option %w[-k --bootstrap-servers], '', 'address(es) of Kafka cluster',
|
12
21
|
default: %w[localhost:9092 localhost:9093 localhost:9094] do |address_string|
|
13
22
|
address_string.split(/,\s*/)
|
14
23
|
end
|
15
|
-
# configuration
|
16
24
|
option %w[-g --schema-registry], '', 'address of schema registry', default: 'http://localhost:8081'
|
17
|
-
option %w[-p --schemas-path], '', 'directory of
|
18
|
-
|
19
|
-
|
25
|
+
option %w[-p --schemas-path], '', 'directory of Avro schemas', default: 'schemas/' do |path|
|
26
|
+
raise ArgumentError, "Schema path: #{path} is not a directory" unless File.directory?(path)
|
27
|
+
end
|
28
|
+
option %w[-v --verbose], :flag, 'print logs, warnings' do
|
29
|
+
$log.level = Logger::DEBUG
|
30
|
+
$VERBOSE = true
|
31
|
+
end
|
32
|
+
option %w[-e --pretty-print], :flag, 'pretty print records'
|
20
33
|
|
21
34
|
# producing
|
22
35
|
option %w[-r --record], '', 'record to commit to topic'
|
23
|
-
option %w[-o --
|
24
|
-
option %w[-
|
36
|
+
option %w[-o --synchronous], :flag, 'commit records synchronously'
|
37
|
+
option %w[-s --schema], '', 'schema name, path to schema, or schema contents'
|
38
|
+
option %w[-j --extract-from-java-files], '', 'extract schemas from Avro generated java files'
|
25
39
|
|
26
40
|
# consuming
|
27
|
-
option %w[-
|
28
|
-
option %w[-a --consume-all], :flag, 'consume every record on topic', default: false
|
41
|
+
option %w[-a --consume-all], :flag, 'consume every record on topic'
|
29
42
|
|
30
|
-
parameter 'TOPIC', 'topic to produce to or consume from'
|
31
|
-
parameter '[NAME]', 'schema name'
|
43
|
+
parameter '[TOPIC]', 'topic to produce to or consume from'
|
32
44
|
|
33
45
|
def execute
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
kafka = Kafka.new(bootstrap_servers, logger: $log, client_id: 'kril')
|
47
|
+
registry = AvroTurf::CachedConfluentSchemaRegistry.new(
|
48
|
+
AvroTurf::ConfluentSchemaRegistry.new(schema_registry, logger: $log)
|
49
|
+
)
|
50
|
+
store = AvroTurf::SchemaStore.new(path: schemas_path)
|
51
|
+
avro = AvroTurf::Messaging.new(registry: registry,
|
52
|
+
schema_store: store,
|
53
|
+
logger: $log)
|
54
|
+
if extract_from_java_files
|
55
|
+
Kril::SchemaExtractor.extract(source_dir: extract_from_java_files,
|
56
|
+
output_dir: schemas_path)
|
57
|
+
end
|
58
|
+
begin
|
59
|
+
if record && (schema || topic)
|
60
|
+
begin
|
61
|
+
produce_record(kafka, avro, store)
|
62
|
+
rescue AvroTurf::SchemaNotFoundError => e
|
63
|
+
print_error(e.message)
|
64
|
+
end
|
65
|
+
elsif topic
|
66
|
+
consume_records(kafka, avro) do |record|
|
67
|
+
print_record(topic, record)
|
68
|
+
end
|
48
69
|
end
|
70
|
+
rescue Excon::Error::Socket
|
71
|
+
print_error('could not connect to schema registry')
|
72
|
+
rescue Kafka::ConnectionError => e
|
73
|
+
print_error(e.message)
|
74
|
+
end
|
75
|
+
end
|
49
76
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
print_record(topic, consumer.consume_one(topic))
|
70
|
-
end
|
77
|
+
private
|
78
|
+
|
79
|
+
def produce_record(kafka, avro, store)
|
80
|
+
producer = Kril::Producer.new(kafka: kafka, avro: avro)
|
81
|
+
schema_name = schema_name(store)
|
82
|
+
record_as_json = JSON.parse(record)
|
83
|
+
infered_topic = topic || schema_name
|
84
|
+
producer.send(record: record_as_json,
|
85
|
+
schema_name: schema_name,
|
86
|
+
topic: infered_topic,
|
87
|
+
syncronous: synchronous?)
|
88
|
+
print_record(infered_topic, record_as_json)
|
89
|
+
end
|
90
|
+
|
91
|
+
def consume_records(kafka, avro)
|
92
|
+
consumer = Kril::Consumer.new(kafka: kafka, avro: avro)
|
93
|
+
if consume_all?
|
94
|
+
consumer.consume_all(topic) do |message|
|
95
|
+
yield message
|
71
96
|
end
|
97
|
+
else
|
98
|
+
yield consumer.consume_one(topic)
|
72
99
|
end
|
73
100
|
end
|
74
101
|
|
102
|
+
def schema_name(schema_store)
|
103
|
+
handler = Kril::SchemaHandler.new(schema_store: schema_store)
|
104
|
+
handler.process(schema || topic)
|
105
|
+
end
|
106
|
+
|
75
107
|
def print_record(topic, record)
|
76
108
|
record = "\n#{JSON.pretty_generate(record)}" if pretty_print?
|
77
109
|
puts "🦐 #{topic}: #{record}"
|
78
110
|
end
|
111
|
+
|
112
|
+
def print_error(message)
|
113
|
+
puts "💥 #{message}"
|
114
|
+
end
|
79
115
|
end
|
data/lib/kril/consumer.rb
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Kril
|
4
|
-
#
|
4
|
+
# High level abstraction for consuming records from topics.
|
5
5
|
class Consumer
|
6
|
+
# avro - Avro instance for deserializing records [AvroTurf::Messaging]
|
7
|
+
# kafka - Kafka instance for creating consumers [Kafka]
|
8
|
+
# config - consumer configuration (optional) [Hash]
|
6
9
|
def initialize(avro: nil, kafka: nil, config: {})
|
7
|
-
config[:group_id] ||= '
|
10
|
+
config[:group_id] ||= 'kril-consumer'
|
8
11
|
@avro = avro
|
9
12
|
@kafka = kafka
|
10
13
|
@config = config
|
11
14
|
end
|
12
15
|
|
16
|
+
# Consume a single record from any partition.
|
17
|
+
# Will block indefinitely if no record present.
|
18
|
+
#
|
19
|
+
# topic - topic to consume from [String]
|
20
|
+
# return - deserialized record [String]
|
13
21
|
def consume_one(topic)
|
14
22
|
consumer = build_consumer(topic, true, @config)
|
15
23
|
msg = nil
|
@@ -24,6 +32,13 @@ module Kril
|
|
24
32
|
consumer.stop
|
25
33
|
end
|
26
34
|
|
35
|
+
# Consume all records from a topic. Each record will be yielded
|
36
|
+
# to block along with consumer instance. Will listen to topic
|
37
|
+
# after all records have been consumed.
|
38
|
+
#
|
39
|
+
# topic - topic to consume from [String]
|
40
|
+
# yields - record, consumer [String, Kafka::Consumer]
|
41
|
+
# return - [nil]
|
27
42
|
def consume_all(topic)
|
28
43
|
config = @config.clone
|
29
44
|
config[:group_id] = SecureRandom.uuid
|
@@ -35,15 +50,6 @@ module Kril
|
|
35
50
|
consumer.stop
|
36
51
|
end
|
37
52
|
|
38
|
-
def listen(topic)
|
39
|
-
consumer = build_consumer(topic, false, @config)
|
40
|
-
consumer.each_message do |message|
|
41
|
-
yield decode(message), consumer
|
42
|
-
end
|
43
|
-
ensure
|
44
|
-
consumer.stop
|
45
|
-
end
|
46
|
-
|
47
53
|
private
|
48
54
|
|
49
55
|
def build_consumer(topic, start_from_beginning, config)
|
data/lib/kril/producer.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Kril
|
4
|
-
#
|
4
|
+
# High level abstraction for producing records to topics.
|
5
5
|
class Producer
|
6
|
+
# avro - Avro instance for deserializing records [AvroTurf::Messaging]
|
7
|
+
# kafka - Kafka instance for creating producers [Kafka]
|
8
|
+
# config - producer configuration (optional) [Hash]
|
6
9
|
def initialize(avro: nil, kafka: nil, config: {})
|
7
10
|
config[:required_acks] ||= 1
|
8
11
|
config[:delivery_threshold] ||= 1
|
@@ -13,12 +16,18 @@ module Kril
|
|
13
16
|
@sync = kafka.producer(sync_config)
|
14
17
|
end
|
15
18
|
|
19
|
+
# Commit a record to a topic.
|
20
|
+
#
|
21
|
+
# record - record to serialize and commit [String]
|
22
|
+
# schema_name - name of schema to encode record from [String]
|
23
|
+
# topic - name of topic. Will be schema_name if nil (optional) [String]
|
24
|
+
# synchronous - blocks until commit if true (optional) [Boolean]
|
16
25
|
def send(record:, schema_name:, topic: nil, syncronous: false)
|
17
26
|
topic ||= schema_name
|
18
27
|
encoded = @avro.encode(record, schema_name: schema_name)
|
19
28
|
if syncronous
|
20
|
-
@
|
21
|
-
@
|
29
|
+
@sync.produce(encoded, topic: topic)
|
30
|
+
@sync.deliver_messages
|
22
31
|
else
|
23
32
|
@async.produce(encoded, topic: topic)
|
24
33
|
end
|
data/lib/kril/record_builder.rb
CHANGED
@@ -4,7 +4,7 @@ module Kril
|
|
4
4
|
# Creates and validates a record based from a defined schema.
|
5
5
|
class RecordBuilder
|
6
6
|
def initialize(schema_file_name: nil,
|
7
|
-
schemas_dir: 'schemas',
|
7
|
+
schemas_dir: 'schemas/',
|
8
8
|
schema_path: nil)
|
9
9
|
path = schema_path || File.join(schemas_dir, "#{schema_file_name}.avsc")
|
10
10
|
file = File.read(path)
|
@@ -1,21 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Kril
|
4
|
-
# Extracts
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
# Extracts schemas from avro generated java files.
|
5
|
+
module SchemaExtractor
|
6
|
+
# Parse schemas from avro generated java files and
|
7
|
+
# load them into the schema repository.
|
8
|
+
#
|
9
|
+
# source_dir - root directory of java files [String]
|
10
|
+
# output_dir - schema repository [String]
|
11
|
+
# returns - [nil]
|
12
|
+
def self.extract(source_dir:, output_dir:)
|
13
|
+
output_dir = File.join(Dir.pwd, output_dir)
|
14
|
+
find_java_files(source_dir) do |file|
|
13
15
|
schema = parse_avro_java_class(file)
|
14
|
-
write_avsc(schema,
|
16
|
+
write_avsc(schema, output_dir) if schema
|
15
17
|
end
|
18
|
+
nil
|
16
19
|
end
|
17
20
|
|
18
|
-
|
21
|
+
module_function
|
19
22
|
|
20
23
|
def find_java_files(root_dir)
|
21
24
|
old_dir = Dir.pwd
|
@@ -39,11 +42,11 @@ module Kril
|
|
39
42
|
end
|
40
43
|
|
41
44
|
def parse_avro_java_class(file)
|
42
|
-
file.each_line do |line|
|
45
|
+
result = file.each_line do |line|
|
43
46
|
extraction = line[/SCHEMA.*parse\("(.*)"\);/, 1]
|
44
47
|
break JSON.parse(dejavafy(extraction)) if extraction
|
45
|
-
nil
|
46
48
|
end
|
49
|
+
result.is_a?(File) ? nil : result
|
47
50
|
end
|
48
51
|
end
|
49
52
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kril
|
4
|
+
# Saves schemas to repository.
|
5
|
+
class SchemaHandler
|
6
|
+
# schemas_path - directory of schema repository [String]
|
7
|
+
# schema_store - schema store [AvroTurf::SchemaStore]
|
8
|
+
def initialize(schemas_path: 'schemas/',
|
9
|
+
schema_store: nil)
|
10
|
+
schema_store ||= AvroTurf::SchemaStore.new(path: schemas_path)
|
11
|
+
@schema_store = schema_store
|
12
|
+
@schemas_path = schemas_path
|
13
|
+
end
|
14
|
+
|
15
|
+
# Handles input to reference or create schema.
|
16
|
+
#
|
17
|
+
# input_string - schema name, schema file, or schema contents [String]
|
18
|
+
# returns - schema name [String]
|
19
|
+
def process(input_string)
|
20
|
+
if File.exist?(input_string)
|
21
|
+
copy_schema_to_store(input_string)
|
22
|
+
elsif schema?(input_string)
|
23
|
+
save_schema(input_string)
|
24
|
+
else
|
25
|
+
@schema_store.find(input_string).name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def schema?(input)
|
32
|
+
JSON.parse(input)['name']
|
33
|
+
rescue StandardError
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
def save_schema(schema)
|
38
|
+
schema = JSON.parse(schema)
|
39
|
+
schema_name = schema['name']
|
40
|
+
path = File.join(@schemas_path, "#{schema_name}.avsc")
|
41
|
+
File.open(path, 'w') { |file| file.write(JSON.pretty_generate(schema)) }
|
42
|
+
schema_name
|
43
|
+
end
|
44
|
+
|
45
|
+
def copy_schema_to_store(path)
|
46
|
+
schema = File.read(path)
|
47
|
+
raise ArgumentError.new, "Not a valid schema: #{path}" unless schema?(schema)
|
48
|
+
schema_name = JSON.parse(schema)['name']
|
49
|
+
new_path = File.join(@schemas_path, "#{schema_name}.avsc")
|
50
|
+
FileUtils.copy_file(path, new_path)
|
51
|
+
schema_name
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/kril/version.rb
CHANGED
data/lib/kril.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'kril/version'
|
4
4
|
require 'kril/record_builder'
|
5
5
|
require 'kril/schema_extractor'
|
6
|
+
require 'kril/schema_handler'
|
6
7
|
require 'kril/producer'
|
7
8
|
require 'kril/consumer'
|
8
9
|
require 'json'
|
@@ -11,7 +12,11 @@ require 'logger'
|
|
11
12
|
require 'avro_turf/messaging'
|
12
13
|
require 'kafka'
|
13
14
|
require 'securerandom'
|
15
|
+
require 'fileutils'
|
14
16
|
|
15
|
-
#
|
17
|
+
# Simple, easy to use API for interacting with
|
18
|
+
# Apache Kafka with Apache Avro. Intended for
|
19
|
+
# experimentation in development, as nothing here
|
20
|
+
# is optimized for performance.
|
16
21
|
module Kril
|
17
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kril
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Bowman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro_turf
|
@@ -175,8 +175,10 @@ files:
|
|
175
175
|
- ".idea/modules.xml"
|
176
176
|
- ".idea/vcs.xml"
|
177
177
|
- ".idea/workspace.xml"
|
178
|
+
- ".rspec"
|
178
179
|
- ".travis.yml"
|
179
180
|
- Gemfile
|
181
|
+
- Gemfile.lock
|
180
182
|
- LICENSE.txt
|
181
183
|
- README.md
|
182
184
|
- Rakefile
|
@@ -187,6 +189,7 @@ files:
|
|
187
189
|
- lib/kril/producer.rb
|
188
190
|
- lib/kril/record_builder.rb
|
189
191
|
- lib/kril/schema_extractor.rb
|
192
|
+
- lib/kril/schema_handler.rb
|
190
193
|
- lib/kril/version.rb
|
191
194
|
homepage: https://github.com/ChadBowman/kril
|
192
195
|
licenses:
|