waterdrop 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +2 -2
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +6 -3
- data/README.md +28 -25
- data/lib/water_drop/aspects/after_aspect.rb +1 -0
- data/lib/water_drop/aspects/around_aspect.rb +1 -0
- data/lib/water_drop/aspects/base_aspect.rb +1 -1
- data/lib/water_drop/config.rb +4 -3
- data/lib/water_drop/message.rb +41 -0
- data/lib/water_drop/pool.rb +1 -1
- data/lib/water_drop/version.rb +1 -1
- data/lib/waterdrop.rb +1 -2
- data/waterdrop.gemspec +1 -1
- metadata +6 -6
- data/lib/water_drop/event.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e75b417b4e1702a407c03a3b09b414c778d22192
|
4
|
+
data.tar.gz: 960675222c4c7e002e3cbfab0803c70d007b7145
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1b90f0160aa014f312117a5d275fa3b1630b442693da25ccd807fe3f0f06e37a19ebb91f69ad0ee963370d6c08dca081de56f854f63880b3a9a8bd428cb690c
|
7
|
+
data.tar.gz: c0a933015c71f03b774243a16936dab5f0820578f5e00b1923b10c44dc294bc2e9413bc16b9c92d1cdd08b5e68d83aaf34ed7109315ff7bbfaf6302ecfa04bea
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.2.3
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
# WaterDrop changelog
|
2
2
|
|
3
|
+
## 0.1.5
|
4
|
+
- raise_on_failure flag to ignore (if false) that message was not sent
|
5
|
+
|
6
|
+
## 0.1.4
|
7
|
+
- Renamed WaterDrop::Event to WaterDrop::Message to follow Apache Kafka naming convention
|
8
|
+
|
3
9
|
## 0.1.3
|
4
10
|
- Gems cleanup
|
5
11
|
- Requirements fix
|
6
12
|
|
7
13
|
## 0.1.2
|
8
|
-
|
9
14
|
- Initial gem release
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
waterdrop (0.1.
|
4
|
+
waterdrop (0.1.5)
|
5
5
|
aspector
|
6
6
|
bundler
|
7
7
|
connection_pool
|
@@ -98,7 +98,7 @@ GEM
|
|
98
98
|
origin (2.1.1)
|
99
99
|
parser (2.2.2.6)
|
100
100
|
ast (>= 1.1, < 3.0)
|
101
|
-
polishgeeks-dev-tools (1.
|
101
|
+
polishgeeks-dev-tools (1.1.0)
|
102
102
|
brakeman
|
103
103
|
faker
|
104
104
|
haml-lint
|
@@ -156,7 +156,7 @@ GEM
|
|
156
156
|
reek (= 1.6.3)
|
157
157
|
ruby2ruby (>= 2.1.1, < 3.0)
|
158
158
|
virtus (~> 1.0)
|
159
|
-
sass (3.4.
|
159
|
+
sass (3.4.17)
|
160
160
|
sexp_processor (4.6.0)
|
161
161
|
shoulda (3.5.0)
|
162
162
|
shoulda-context (~> 1.0, >= 1.0.1)
|
@@ -198,3 +198,6 @@ PLATFORMS
|
|
198
198
|
DEPENDENCIES
|
199
199
|
polishgeeks-dev-tools
|
200
200
|
waterdrop!
|
201
|
+
|
202
|
+
BUNDLED WITH
|
203
|
+
1.10.6
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/karafka/waterdrop.png)](https://travis-ci.org/karafka/waterdrop)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/karafka/waterdrop/badges/gpa.svg)](https://codeclimate.com/github/karafka/waterdrop)
|
5
5
|
|
6
|
-
Gem used to send
|
6
|
+
Gem used to send messages to Kafka in a standard and in an aspect way.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -27,23 +27,25 @@ bundle install
|
|
27
27
|
|
28
28
|
WaterDrop has following configuration options:
|
29
29
|
|
30
|
-
| Option | Value type | Description
|
31
|
-
|
32
|
-
|
|
33
|
-
| kafka_host | String | Kafka server host
|
34
|
-
| kafka_ports | Array<String> | Kafka server ports
|
35
|
-
| connection_pool_size | Integer | Kafka connection pool size
|
36
|
-
| connection_pool_timeout | Integer | Kafka connection pool timeout
|
30
|
+
| Option | Value type | Description |
|
31
|
+
|-------------------------|---------------|----------------------------------|
|
32
|
+
| send_messages | Boolean | Should we send messages to Kafka |
|
33
|
+
| kafka_host | String | Kafka server host |
|
34
|
+
| kafka_ports | Array<String> | Kafka server ports |
|
35
|
+
| connection_pool_size | Integer | Kafka connection pool size |
|
36
|
+
| connection_pool_timeout | Integer | Kafka connection pool timeout |
|
37
|
+
| raise_on_failure | Boolean | Should we raise an exception when we cannot send message to Kafka - if false will silently ignore failures (will just ignore them) |
|
37
38
|
|
38
39
|
To apply this configuration, you need to use a *setup* method:
|
39
40
|
|
40
41
|
```ruby
|
41
42
|
WaterDrop.setup do |config|
|
42
|
-
config.
|
43
|
+
config.send_messages = true
|
43
44
|
config.connection_pool_size = 20
|
44
45
|
config.connection_pool_timeout = 1
|
45
46
|
config.kafka_ports = %w( 9092 )
|
46
47
|
config.kafka_host = 'localhost'
|
48
|
+
config.raise_on_failure = true
|
47
49
|
end
|
48
50
|
```
|
49
51
|
|
@@ -51,40 +53,41 @@ This configuration can be placed in *config/initializers* and can vary based on
|
|
51
53
|
|
52
54
|
```ruby
|
53
55
|
WaterDrop.setup do |config|
|
54
|
-
config.
|
56
|
+
config.send_messages = Rails.env.production?
|
55
57
|
config.connection_pool_size = 20
|
56
58
|
config.connection_pool_timeout = 1
|
57
59
|
config.kafka_ports = %w( 9092 )
|
58
60
|
config.kafka_host = Rails.env.production? ? 'prod-host' : 'localhost'
|
61
|
+
config.raise_on_failure = Rails.env.production?
|
59
62
|
end
|
60
63
|
```
|
61
64
|
|
62
65
|
## Usage
|
63
66
|
|
64
|
-
### Creating and sending standard
|
67
|
+
### Creating and sending standard messages
|
65
68
|
|
66
|
-
To send Kafka messages, you don't need to use aspects, you can create and send
|
69
|
+
To send Kafka messages, you don't need to use aspects, you can create and send messages directly:
|
67
70
|
|
68
71
|
```ruby
|
69
|
-
|
70
|
-
|
72
|
+
message = WaterDrop::Message.new('topic', 'message')
|
73
|
+
message.send!
|
71
74
|
```
|
72
75
|
|
73
76
|
message that you want to send should be either castable to string or to json. If it can be casted to both, it will be casted to json.
|
74
77
|
|
75
|
-
### Using aspects to handle
|
78
|
+
### Using aspects to handle messages
|
76
79
|
|
77
|
-
WaterDrop uses [Aspector](https://github.com/gcao/aspector) to allow aspect oriented
|
80
|
+
WaterDrop uses [Aspector](https://github.com/gcao/aspector) to allow aspect oriented messages hookup. If you need extensive details about aspector usage, please refer to the [examples](https://github.com/gcao/aspector/tree/master/examples) directory of this project.
|
78
81
|
|
79
|
-
In general aspects allows adding additional behavior to existing code without modifying the code itself. This way we can create and send
|
82
|
+
In general aspects allows adding additional behavior to existing code without modifying the code itself. This way we can create and send messages, without "polluting" the business logic with it.
|
80
83
|
|
81
84
|
All the WaterDrop aspects accept following parameters:
|
82
85
|
|
83
|
-
| Option | Value type | Description
|
84
|
-
|
85
|
-
| ClassName | Class | Class to which we want to hook
|
86
|
-
| method: :method_name | Symbol, Array<Symbol> | Method (or methods) to which we want to hook
|
87
|
-
| topic: 'karafka_topic' | String, Symbol | Kafka topic to which we will send the
|
86
|
+
| Option | Value type | Description |
|
87
|
+
|-------------------------|-----------------------|------------------------------------------------|
|
88
|
+
| ClassName | Class | Class to which we want to hook |
|
89
|
+
| method: :method_name | Symbol, Array<Symbol> | Method (or methods) to which we want to hook |
|
90
|
+
| topic: 'karafka_topic' | String, Symbol | Kafka topic to which we will send the message |
|
88
91
|
|
89
92
|
There also a *message*, *after_message* and *before_message* proc parameter that will be evaluated in the methods object context.
|
90
93
|
|
@@ -105,7 +108,7 @@ now each time before you run:
|
|
105
108
|
ClassName.new.run
|
106
109
|
```
|
107
110
|
|
108
|
-
|
111
|
+
a message with the given message will be send to Kafka.
|
109
112
|
|
110
113
|
#### After aspects hookup
|
111
114
|
|
@@ -124,7 +127,7 @@ now each time after you run:
|
|
124
127
|
ClassName.new.run
|
125
128
|
```
|
126
129
|
|
127
|
-
|
130
|
+
a message with the given message will be send to Kafka.
|
128
131
|
|
129
132
|
#### Around aspects hookup
|
130
133
|
|
@@ -144,7 +147,7 @@ now each time you run:
|
|
144
147
|
ClassName.new.run
|
145
148
|
```
|
146
149
|
|
147
|
-
|
150
|
+
a message with the given message will be send before and after the method execution.
|
148
151
|
|
149
152
|
## Note on Patches/Pull Requests
|
150
153
|
|
data/lib/water_drop/config.rb
CHANGED
@@ -11,14 +11,15 @@ module WaterDrop
|
|
11
11
|
# if none currently available.
|
12
12
|
# @option kafka_ports [Array] the ports of kafka brokers
|
13
13
|
# @option kafka_host [String] the host of kafka server
|
14
|
-
# @option
|
15
|
-
#
|
14
|
+
# @option send_messages [Boolean] boolean value to define whether messages should be sent
|
15
|
+
# @option raise_on_failure [Boolean] Should raise error when failed to deliver a message
|
16
16
|
OPTIONS = %i(
|
17
17
|
connection_pool_size
|
18
18
|
connection_pool_timeout
|
19
19
|
kafka_ports
|
20
20
|
kafka_host
|
21
|
-
|
21
|
+
send_messages
|
22
|
+
raise_on_failure
|
22
23
|
)
|
23
24
|
|
24
25
|
OPTIONS.each do |attr_name|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module WaterDrop
|
2
|
+
# Message class which encapsulate single Kafka message logic and its delivery
|
3
|
+
class Message
|
4
|
+
attr_reader :topic, :message
|
5
|
+
|
6
|
+
# we ignore this types of errors if ::WaterDrop.config.raise_on_failure?
|
7
|
+
# is set to false
|
8
|
+
CATCHED_ERRORS = [
|
9
|
+
Poseidon::Errors::UnableToFetchMetadata
|
10
|
+
]
|
11
|
+
|
12
|
+
# @param topic [String, Symbol] a topic to which we want to send a message
|
13
|
+
# @param message [Object] any object that can be serialized to a JSON string or
|
14
|
+
# that can be casted to a string
|
15
|
+
# @return [WaterDrop::Message] WaterDrop message instance
|
16
|
+
# @example Creating a new message
|
17
|
+
# WaterDrop::Message.new(topic, message)
|
18
|
+
def initialize(topic, message)
|
19
|
+
@topic = topic.to_s
|
20
|
+
@message = message.respond_to?(:to_json) ? message.to_json : message.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
# Sents a current message to Kafka
|
24
|
+
# @note Won't send any messages if send_messages config flag is set to false
|
25
|
+
# @example Set a message
|
26
|
+
# WaterDrop::Message.new(topic, message).send!
|
27
|
+
def send!
|
28
|
+
return true unless ::WaterDrop.config.send_messages?
|
29
|
+
|
30
|
+
Pool.with do |producer|
|
31
|
+
producer.send_messages([
|
32
|
+
Poseidon::MessageToSend.new(topic, message)
|
33
|
+
])
|
34
|
+
end
|
35
|
+
rescue *CATCHED_ERRORS => e
|
36
|
+
# Reraise if we want to raise on failure
|
37
|
+
# Ignore if we dont want to know that something went wrong
|
38
|
+
raise(e) if ::WaterDrop.config.raise_on_failure?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/water_drop/pool.rb
CHANGED
data/lib/water_drop/version.rb
CHANGED
data/lib/waterdrop.rb
CHANGED
@@ -13,15 +13,14 @@
|
|
13
13
|
).each { |lib| require lib }
|
14
14
|
|
15
15
|
# Internal components
|
16
|
-
|
17
16
|
base_path = File.dirname(__FILE__) + '/water_drop'
|
18
17
|
|
19
18
|
%w(
|
20
19
|
version
|
21
20
|
pool
|
22
21
|
config
|
23
|
-
event
|
24
22
|
logger
|
23
|
+
message
|
25
24
|
aspects/base_aspect
|
26
25
|
aspects/formatter
|
27
26
|
aspects/after_aspect
|
data/waterdrop.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['Maciej Mensfeld', 'Pavlo Vavruk']
|
11
11
|
spec.email = %w( maciej@mensfeld.pl pavlo.vavruk@gmail.com )
|
12
12
|
spec.homepage = 'https://github.com/karafka/waterdrop'
|
13
|
-
spec.summary = %q{ Kafka
|
13
|
+
spec.summary = %q{ Kafka messages with aspects made easy! }
|
14
14
|
spec.description = spec.summary
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
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.5
|
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-08-
|
12
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
-
description: Kafka
|
84
|
+
description: Kafka messages with aspects made easy!
|
85
85
|
email:
|
86
86
|
- maciej@mensfeld.pl
|
87
87
|
- pavlo.vavruk@gmail.com
|
@@ -105,8 +105,8 @@ files:
|
|
105
105
|
- lib/water_drop/aspects/before_aspect.rb
|
106
106
|
- lib/water_drop/aspects/formatter.rb
|
107
107
|
- lib/water_drop/config.rb
|
108
|
-
- lib/water_drop/event.rb
|
109
108
|
- lib/water_drop/logger.rb
|
109
|
+
- lib/water_drop/message.rb
|
110
110
|
- lib/water_drop/pool.rb
|
111
111
|
- lib/water_drop/version.rb
|
112
112
|
- lib/waterdrop.rb
|
@@ -131,9 +131,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.4.
|
134
|
+
rubygems_version: 2.4.8
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
|
-
summary: Kafka
|
137
|
+
summary: Kafka messages with aspects made easy!
|
138
138
|
test_files: []
|
139
139
|
has_rdoc:
|
data/lib/water_drop/event.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module WaterDrop
|
2
|
-
# Event module which encapsulate single Kafka event logic and its delivery
|
3
|
-
class Event
|
4
|
-
attr_reader :topic, :message
|
5
|
-
|
6
|
-
# @param topic [String, Symbol] a topic to which we want to send a message
|
7
|
-
# @param message [Object] any object that can be serialized to a JSON string or
|
8
|
-
# that can be casted to a string
|
9
|
-
# @return [WaterDrop::Event] WaterDrop event instance
|
10
|
-
# @example Creating a new event
|
11
|
-
# WaterDrop::Event.new(topic, message)
|
12
|
-
def initialize(topic, message)
|
13
|
-
@topic = topic.to_s
|
14
|
-
@message = message.respond_to?(:to_json) ? message.to_json : message.to_s
|
15
|
-
end
|
16
|
-
|
17
|
-
# Sents a current event to Kafka
|
18
|
-
# @note Won't send any events if send_events config flag is set to false
|
19
|
-
# @example Set a message
|
20
|
-
# WaterDrop::Event.new(topic, message).send!
|
21
|
-
def send!
|
22
|
-
return true unless ::WaterDrop.config.send_events?
|
23
|
-
|
24
|
-
Pool.with do |producer|
|
25
|
-
producer.send_messages([
|
26
|
-
Poseidon::MessageToSend.new(topic, message)
|
27
|
-
])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|