waterdrop 1.0.0 → 1.0.1
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/CHANGELOG.md +3 -0
- data/Gemfile.lock +3 -3
- data/README.md +1 -3
- data/lib/water_drop/async_producer.rb +23 -2
- data/lib/water_drop/base_producer.rb +0 -14
- data/lib/water_drop/sync_producer.rb +23 -2
- data/lib/water_drop/version.rb +1 -1
- 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: 4c194065166002b613a559ba2818edc33edea127
|
4
|
+
data.tar.gz: ca654d85779ccefd488269360a977db8e3406f54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dee9f25037979516a0f5d62591e4cce4706a2f54b10862e63bc0ea757664f6dc7b442efb501f70e9eafe0b1ec9d6389be0f9b74968369faeefa69ad1adf864d4
|
7
|
+
data.tar.gz: da09ca5c22c4553e0c6f82fb16a7761bf97453c8f6ac8a3713ac350f09ffe69f47150912a48f4c2574b9bdacc6197d9ad445dff2ee4c030a082035e5c8ef33b1
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
waterdrop (1.0.
|
4
|
+
waterdrop (1.0.1)
|
5
5
|
delivery_boy (>= 0.2.2)
|
6
6
|
dry-configurable (~> 0.7)
|
7
7
|
dry-validation (~> 0.11)
|
@@ -22,14 +22,14 @@ GEM
|
|
22
22
|
dry-container (0.6.0)
|
23
23
|
concurrent-ruby (~> 1.0)
|
24
24
|
dry-configurable (~> 0.1, >= 0.1.3)
|
25
|
-
dry-core (0.4.
|
25
|
+
dry-core (0.4.1)
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
27
|
dry-equalizer (0.2.0)
|
28
28
|
dry-logic (0.4.2)
|
29
29
|
dry-container (~> 0.2, >= 0.2.6)
|
30
30
|
dry-core (~> 0.2)
|
31
31
|
dry-equalizer (~> 0.2)
|
32
|
-
dry-types (0.12.
|
32
|
+
dry-types (0.12.2)
|
33
33
|
concurrent-ruby (~> 1.0)
|
34
34
|
dry-configurable (~> 0.1)
|
35
35
|
dry-container (~> 0.3)
|
data/README.md
CHANGED
@@ -89,9 +89,7 @@ To send Kafka messages, just use one of the producers:
|
|
89
89
|
|
90
90
|
```ruby
|
91
91
|
WaterDrop::SyncProducer.call('message', topic: 'my-topic')
|
92
|
-
|
93
92
|
# or for async
|
94
|
-
|
95
93
|
WaterDrop::AsyncProducer.call('message', topic: 'my-topic')
|
96
94
|
```
|
97
95
|
|
@@ -99,7 +97,7 @@ Both ```SyncProducer``` and ```AsyncProducer``` accept following options:
|
|
99
97
|
|
100
98
|
| Option | Required | Value type | Description |
|
101
99
|
|-------------------- |----------|----------------|---------------------------------------------------------------------|
|
102
|
-
| ```topic``` | true | String
|
100
|
+
| ```topic``` | true | String | The Kafka topic that should be written to |
|
103
101
|
| ```key``` | false | String | The key that should be set on the Kafka message |
|
104
102
|
| ```partition``` | false | Integer | A specific partition number that should be written to |
|
105
103
|
| ```partition_key``` | false | String | A string that can be used to deterministically select the partition |
|
@@ -3,6 +3,27 @@
|
|
3
3
|
# WaterDrop library
|
4
4
|
module WaterDrop
|
5
5
|
# Async producer for messages
|
6
|
-
AsyncProducer
|
7
|
-
|
6
|
+
class AsyncProducer < BaseProducer
|
7
|
+
# Performs message delivery using deliver_async method
|
8
|
+
# @param message [String] message that we want to send to Kafka
|
9
|
+
# @param options [Hash] options (including topic) for producer
|
10
|
+
# @raise [WaterDrop::Errors::InvalidMessageOptions] raised when message options are
|
11
|
+
# somehow invalid and we cannot perform delivery because of that
|
12
|
+
def self.call(message, options)
|
13
|
+
attempts ||= 0
|
14
|
+
attempts += 1
|
15
|
+
|
16
|
+
validate!(options)
|
17
|
+
return unless WaterDrop.config.deliver
|
18
|
+
DeliveryBoy.deliver_async(message, options)
|
19
|
+
rescue Kafka::Error => e
|
20
|
+
if attempts > WaterDrop.config.kafka.max_retries
|
21
|
+
WaterDrop.logger.error e
|
22
|
+
raise e
|
23
|
+
else
|
24
|
+
WaterDrop.logger.warn "Retrying delivery after: #{e}"
|
25
|
+
retry
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
8
29
|
end
|
@@ -5,20 +5,6 @@ module WaterDrop
|
|
5
5
|
# sync and async producers
|
6
6
|
class BaseProducer
|
7
7
|
class << self
|
8
|
-
# Delivery boy method name that we use to invoke producer action
|
9
|
-
attr_accessor :method_name
|
10
|
-
|
11
|
-
# Performs message delivery using method_name method
|
12
|
-
# @param message [String] message that we want to send to Kafka
|
13
|
-
# @param options [Hash] options (including topic) for producer
|
14
|
-
# @raise [WaterDrop::Errors::InvalidMessageOptions] raised when message options are
|
15
|
-
# somehow invalid and we cannot perform delivery because of that
|
16
|
-
def call(message, options)
|
17
|
-
validate!(options)
|
18
|
-
return unless WaterDrop.config.deliver
|
19
|
-
DeliveryBoy.public_send(method_name, message, options)
|
20
|
-
end
|
21
|
-
|
22
8
|
private
|
23
9
|
|
24
10
|
# Runs the message options validations and raises an error if anything is invalid
|
@@ -3,6 +3,27 @@
|
|
3
3
|
# WaterDrop library
|
4
4
|
module WaterDrop
|
5
5
|
# Sync producer for messages
|
6
|
-
SyncProducer
|
7
|
-
|
6
|
+
class SyncProducer < BaseProducer
|
7
|
+
# Performs message delivery using deliver_async method
|
8
|
+
# @param message [String] message that we want to send to Kafka
|
9
|
+
# @param options [Hash] options (including topic) for producer
|
10
|
+
# @raise [WaterDrop::Errors::InvalidMessageOptions] raised when message options are
|
11
|
+
# somehow invalid and we cannot perform delivery because of that
|
12
|
+
def self.call(message, options)
|
13
|
+
attempts ||= 0
|
14
|
+
attempts += 1
|
15
|
+
|
16
|
+
validate!(options)
|
17
|
+
return unless WaterDrop.config.deliver
|
18
|
+
DeliveryBoy.deliver(message, options)
|
19
|
+
rescue Kafka::Error => e
|
20
|
+
if attempts > WaterDrop.config.kafka.max_retries
|
21
|
+
WaterDrop.logger.error e
|
22
|
+
raise e
|
23
|
+
else
|
24
|
+
WaterDrop.logger.warn "Retrying delivery after: #{e}"
|
25
|
+
retry
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
8
29
|
end
|
data/lib/water_drop/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waterdrop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Mensfeld
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: delivery_boy
|