waterdrop 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/lib/water_drop/pool.rb +1 -4
- data/lib/water_drop/producer_proxy.rb +72 -0
- data/lib/water_drop/version.rb +1 -1
- data/lib/waterdrop.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afd61e0c7e80a6ccd14002340ca460ca051f835e
|
4
|
+
data.tar.gz: 80072934389308b27aa255a7e8e9b223b906d10e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4653e4edb72c79ac015451e7fa9c5b62232262e63cd76420bb8aa7b02b3d64df87098d81a73b80867511b898e513ce9c88f28e132238d1cf54109b4dc598332
|
7
|
+
data.tar.gz: 17c30dc90a1bd130245ce9df5f586d97ff4fa70a007ef1f7ff21e5e55572a4eab94fcf8dc76c42d44f44b8cc7c2eecca6bb7085c7b3773a2f18d1bc2e5d9709d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# WaterDrop changelog
|
2
2
|
|
3
|
+
## 0.1.9
|
4
|
+
- Required acks and set to - (most secure but slower)
|
5
|
+
- Added a proxu layer to to producer so we could replate Kafka with other messaging systems
|
6
|
+
- Gem dump
|
7
|
+
|
3
8
|
## 0.1.8
|
4
9
|
- proper poseidon clients names (not duplicated)
|
5
10
|
|
data/Gemfile.lock
CHANGED
data/lib/water_drop/pool.rb
CHANGED
@@ -12,10 +12,7 @@ module WaterDrop
|
|
12
12
|
size: ::WaterDrop.config.connection_pool_size,
|
13
13
|
timeout: ::WaterDrop.config.connection_pool_timeout
|
14
14
|
) do
|
15
|
-
|
16
|
-
::WaterDrop.config.kafka_hosts,
|
17
|
-
object_id.to_s + rand.to_s + Time.now.to_f.to_s
|
18
|
-
)
|
15
|
+
WaterDrop::ProducerProxy.new
|
19
16
|
end
|
20
17
|
end
|
21
18
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module WaterDrop
|
2
|
+
# Proxy object for a producer (sender) objects that are inside pool
|
3
|
+
# We use it to provide additional timeout monitoring layer
|
4
|
+
# There seem to be some issues with Poseidon and usage of sockets that
|
5
|
+
# are old and not used - that's why we just reinitialize connection if
|
6
|
+
# the connection layer is not being used for too long
|
7
|
+
class ProducerProxy
|
8
|
+
# How long should be object considered alive if nothing is being
|
9
|
+
# send using it. After that time, we will recreate the connection
|
10
|
+
LIFE_TIME = 5 * 60 # 5 minute
|
11
|
+
|
12
|
+
# How often should we refresh meta data from Kafka
|
13
|
+
METADATA_REFRESH_INTERVAL = 5 * 60 # 5 minute
|
14
|
+
|
15
|
+
# @see https://kafka.apache.org/08/configuration.html
|
16
|
+
# Security level for producer
|
17
|
+
REQUIRED_ACKS = -1
|
18
|
+
|
19
|
+
# @return [WaterDrop::ProducerProxy] proxy object to Poseidon::Producer
|
20
|
+
# @note To ignore @last_usage nil case - we just assume that it is being
|
21
|
+
# first used when we create it
|
22
|
+
def initialize
|
23
|
+
touch
|
24
|
+
end
|
25
|
+
|
26
|
+
# Sends messages to Kafka
|
27
|
+
# @param messages [Array<Poseidon::MessageToSend>] array with messages that we want to send
|
28
|
+
# @return [Boolean] were the messages send
|
29
|
+
# @note Even if you send one message - it still needs to be in an array
|
30
|
+
# @example Send 1 message
|
31
|
+
# ProducerProxy.new.send_messages([Poseidon::MessageToSend.new(topic, message)])
|
32
|
+
def send_messages(messages)
|
33
|
+
touch
|
34
|
+
producer.send_messages(messages)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# Refreshes last usage value with current time
|
40
|
+
def touch
|
41
|
+
@last_usage = Time.now
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Poseidon::Producer] producer instance to which we can forward method requests
|
45
|
+
def producer
|
46
|
+
reload! if dead?
|
47
|
+
# Metadata refresh interval needs to be in miliseconds
|
48
|
+
@producer ||= Poseidon::Producer.new(
|
49
|
+
::WaterDrop.config.kafka_hosts,
|
50
|
+
producer_id,
|
51
|
+
metadata_refresh_interval_ms: METADATA_REFRESH_INTERVAL * 1000,
|
52
|
+
required_acks: REQUIRED_ACKS
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [String] random unique id for producer
|
57
|
+
def producer_id
|
58
|
+
object_id.to_s + Time.now.to_f.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Boolean] true if we cannot use producer anymore because it was not used for a
|
62
|
+
# long time
|
63
|
+
def dead?
|
64
|
+
@last_usage + LIFE_TIME < Time.now
|
65
|
+
end
|
66
|
+
|
67
|
+
# Resets a producer so a new one will be created once requested
|
68
|
+
def reload!
|
69
|
+
@producer = nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/water_drop/version.rb
CHANGED
data/lib/waterdrop.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waterdrop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Mensfeld
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-10-
|
12
|
+
date: 2015-10-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/water_drop/config.rb
|
122
122
|
- lib/water_drop/message.rb
|
123
123
|
- lib/water_drop/pool.rb
|
124
|
+
- lib/water_drop/producer_proxy.rb
|
124
125
|
- lib/water_drop/version.rb
|
125
126
|
- lib/waterdrop.rb
|
126
127
|
- waterdrop.gemspec
|