yakc 0.1.1 → 0.1.2
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 +4 -4
- data/lib/yakc/configuration.rb +6 -6
- data/lib/yakc/fallthrough_instrumenter.rb +3 -5
- data/lib/yakc/message_broadcaster.rb +1 -1
- data/lib/yakc/reader.rb +13 -8
- data/lib/yakc/version.rb +1 -1
- data/lib/yakc.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44d8d2354964fbc66a258745f1e258c27bbc4365
|
4
|
+
data.tar.gz: 61b5be7b9f75f887a8b0e7a6a76802c3244dd0a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5f17b3bc8143c260747832d695f94335df0b84ee7cdf1f63ed89662d01bccbcb745fdd9bb014d3caa4ddedbc27f123c09b7599b9f72804ac2a68796a4915af6
|
7
|
+
data.tar.gz: 5c1a6955c2f3c4762cf085404f2997af70d628127e330e350fa032326255ccf8b598310d4a6f73ab190f8025b3ba15771b982d8dfd1ee212c0f24eb0129d5010
|
data/README.md
CHANGED
@@ -32,9 +32,9 @@ This is the bit of code that handles what to do with the messages once they are
|
|
32
32
|
To set it up:
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
handler = YAKC::MessageBroadcaster.new publisher: MyBroadcaster,
|
35
|
+
handler = YAKC::MessageBroadcaster.new publisher: MyBroadcaster, message_parser: MyMessageClass
|
36
36
|
# or, if you are okay with Yeller
|
37
|
-
handler = YAKC::MessageBroadcaster.new
|
37
|
+
handler = YAKC::MessageBroadcaster.new message_parser: MyMessageClass
|
38
38
|
```
|
39
39
|
|
40
40
|
And now you're ready to init the [reader](#reader)
|
@@ -103,7 +103,7 @@ It implements:
|
|
103
103
|
Here's how you would use it:
|
104
104
|
|
105
105
|
```ruby
|
106
|
-
handler = YAKC::MessageBroadcaster.new
|
106
|
+
handler = YAKC::MessageBroadcaster.new message_parser: AvroMessage
|
107
107
|
reader = YAKC::Reader.new message_handler: handler
|
108
108
|
|
109
109
|
reader.read
|
@@ -142,7 +142,7 @@ The reader would look like
|
|
142
142
|
In your reader job
|
143
143
|
|
144
144
|
```ruby
|
145
|
-
handler = YAKC::MessageBroadcaster.new
|
145
|
+
handler = YAKC::MessageBroadcaster.new message_parser: AvroMessage
|
146
146
|
reader = YAKC::Reader.new message_handler: handler
|
147
147
|
|
148
148
|
reader.read
|
data/lib/yakc/configuration.rb
CHANGED
@@ -3,12 +3,12 @@ module YAKC
|
|
3
3
|
attr_accessor :zookeepers, :brokers, :app, :suffix, :topics, :logger
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
logger = Logger.new(STDOUT)
|
7
|
-
brokers = ENV.fetch("BROKERS", "localhost:9092").split(",")
|
8
|
-
zookeepers = ENV.fetch("ZOOKEEPERS", "localhost:2181").split(",")
|
9
|
-
app = ENV["APP"]
|
10
|
-
suffix = ENV["SUFFIX"]
|
11
|
-
topics = ENV
|
6
|
+
@logger = Logger.new(STDOUT)
|
7
|
+
@brokers = ENV.fetch("BROKERS", "localhost:9092").split(",")
|
8
|
+
@zookeepers = ENV.fetch("ZOOKEEPERS", "localhost:2181").split(",")
|
9
|
+
@app = ENV["APP"]
|
10
|
+
@suffix = ENV["SUFFIX"]
|
11
|
+
@topics = ENV.fetch("TOPICS", "").split(",")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -15,7 +15,7 @@ module YAKC
|
|
15
15
|
@instrumenter.instrument( msg ) do
|
16
16
|
if msg.broadcastable?
|
17
17
|
# broadcast the specific topic event
|
18
|
-
@publisher.broadcast msg.payload, broadcast_key( topic, msg.event )
|
18
|
+
@publisher.broadcast msg.payload, broadcast_key( topic, msg.event )
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/yakc/reader.rb
CHANGED
@@ -1,31 +1,36 @@
|
|
1
1
|
module YAKC
|
2
2
|
class Reader
|
3
|
-
attr_reader :message_handler, :terminated
|
3
|
+
attr_reader :message_handler, :terminated, :config
|
4
|
+
delegate :topics, :brokers, :zookeepers, :logger, :app, :suffix, to: :config
|
4
5
|
|
5
6
|
def initialize( message_handler: )
|
6
7
|
@message_handler = message_handler
|
7
|
-
@config = YAKC.configuration
|
8
|
+
@config = YAKC.configuration
|
8
9
|
|
9
10
|
raise KeyError, "YAKC::Reader initialized without a message handler. Please specify one so that your receives messages don't end up on the floor. For more info, go to: https://github.com/gaorlov/yakc#message-handler" unless message_handler
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
%w(INT TERM).each do |signal|
|
13
|
+
Signal.trap(signal) do
|
14
|
+
@terminated = true
|
15
|
+
end
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
19
|
def read
|
20
|
+
logger.info "YAKC: Starting reading"
|
17
21
|
loop do
|
18
22
|
consumers.map do |consumer|
|
19
23
|
consumer.fetch do |partition, bulk|
|
20
24
|
bulk.each do |message|
|
21
|
-
message_handler.handle topic, message
|
25
|
+
message_handler.handle consumer.topic, message
|
22
26
|
end
|
23
27
|
end
|
24
28
|
return if terminated
|
25
29
|
end
|
30
|
+
return if terminated
|
26
31
|
end
|
27
32
|
rescue => e
|
28
|
-
|
33
|
+
logger.error e
|
29
34
|
retry
|
30
35
|
end
|
31
36
|
|
@@ -35,8 +40,8 @@ module YAKC
|
|
35
40
|
@consumers ||= topics.map do |topic|
|
36
41
|
Poseidon::ConsumerGroup.new(
|
37
42
|
"#{app}-#{topic}-consumer-#{suffix}",
|
38
|
-
|
39
|
-
|
43
|
+
brokers,
|
44
|
+
zookeepers,
|
40
45
|
topic,
|
41
46
|
{})
|
42
47
|
end
|
data/lib/yakc/version.rb
CHANGED
data/lib/yakc.rb
CHANGED
@@ -5,7 +5,7 @@ require 'yeller'
|
|
5
5
|
|
6
6
|
module YAKC
|
7
7
|
autoload :Configuration, 'yakc/configuration'
|
8
|
-
autoload :FallthroughInstrumenter, 'yakc/
|
8
|
+
autoload :FallthroughInstrumenter, 'yakc/fallthrough_instrumenter'
|
9
9
|
autoload :MessageBroadcaster, 'yakc/message_broadcaster'
|
10
10
|
autoload :Reader, 'yakc/reader'
|
11
11
|
autoload :Message, 'yakc/message'
|
@@ -14,13 +14,13 @@ module YAKC
|
|
14
14
|
attr_writer :configuration
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.configuration
|
18
|
-
@configuration ||= Configuration.new
|
19
|
-
end
|
20
|
-
|
21
17
|
def self.configure
|
22
18
|
yield configuration
|
23
19
|
end
|
20
|
+
|
21
|
+
def self.configuration
|
22
|
+
@configuration ||= YAKC::Configuration.new
|
23
|
+
end
|
24
24
|
|
25
25
|
delegate :logger, to: :configuration
|
26
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yakc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yeller
|