delivery_boy 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/delivery_boy.rb +36 -0
- data/lib/delivery_boy/config.rb +1 -0
- data/lib/delivery_boy/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: b22537575f9af9b44a9a9f285e74d073b48bec92
|
4
|
+
data.tar.gz: 2505ca15d3d2b60a94fb4c88f1a959803d334c44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5c0e279ebcd829f3b0961d10f705fc74d5307a983547c049542d391361daafdb71ef8c1747770e4b946e56d470e88a78d81b811c9995d26380fcf2ffcb5de13
|
7
|
+
data.tar.gz: 69ef0053f5a4873a6deaa9d7071502adb6ee677d5c9678d33467c1dd65473a6e76a97cd6427fe8b1e23feda1e83c506543ddb6010930d990f3aa71ca27b02edc
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
Once you've [installed the gem](#installation), and assuming your Kafka broker is running on localhost, you can simply start publishing messages to Kafka:
|
23
|
+
Once you've [installed the gem](#installation), and assuming your Kafka broker is running on localhost, you can simply start publishing messages to Kafka directly from your Rails code:
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
# app/controllers/comments_controller.rb
|
data/lib/delivery_boy.rb
CHANGED
@@ -6,6 +6,22 @@ require "delivery_boy/railtie" if defined?(Rails)
|
|
6
6
|
|
7
7
|
module DeliveryBoy
|
8
8
|
class << self
|
9
|
+
|
10
|
+
# Write a message to a specified Kafka topic synchronously.
|
11
|
+
#
|
12
|
+
# Keep in mind that the client will block until the message has been
|
13
|
+
# delivered.
|
14
|
+
#
|
15
|
+
# @param value [String] the message value.
|
16
|
+
# @param topic [String] the topic that the message should be written to.
|
17
|
+
# @param key [String, nil] the message key.
|
18
|
+
# @param partition [Integer, nil] the topic partition that the message should
|
19
|
+
# be written to.
|
20
|
+
# @param partition_key [String, nil] a key used to deterministically assign
|
21
|
+
# a partition to the message.
|
22
|
+
# @return [nil]
|
23
|
+
# @raise [Kafka::BufferOverflow] if the producer's buffer is full.
|
24
|
+
# @raise [Kafka::DeliveryFailed] if delivery failed for some reason.
|
9
25
|
def deliver(value, topic:, **options)
|
10
26
|
sync_producer.produce(value, topic: topic, **options)
|
11
27
|
sync_producer.deliver_messages
|
@@ -16,27 +32,47 @@ module DeliveryBoy
|
|
16
32
|
raise
|
17
33
|
end
|
18
34
|
|
35
|
+
# Like {.deliver_async!}, but handles +Kafka::BufferOverflow+ errors
|
36
|
+
# by logging them and just going on with normal business.
|
37
|
+
#
|
38
|
+
# @return [nil]
|
19
39
|
def deliver_async(value, topic:, **options)
|
20
40
|
deliver_async!(value, topic: topic, **options)
|
21
41
|
rescue Kafka::BufferOverflow
|
22
42
|
logger.error "Message for `#{topic}` dropped due to buffer overflow"
|
23
43
|
end
|
24
44
|
|
45
|
+
# Like {.deliver}, but returns immediately.
|
46
|
+
#
|
47
|
+
# The actual delivery takes place in a background thread.
|
48
|
+
#
|
49
|
+
# @return [nil]
|
25
50
|
def deliver_async!(value, topic:, **options)
|
26
51
|
async_producer.produce(value, topic: topic, **options)
|
27
52
|
end
|
28
53
|
|
54
|
+
# Shut down DeliveryBoy.
|
55
|
+
#
|
56
|
+
# Automatically called when the process exits.
|
57
|
+
#
|
58
|
+
# @return [nil]
|
29
59
|
def shutdown
|
30
60
|
sync_producer.shutdown if sync_producer?
|
31
61
|
async_producer.shutdown if async_producer?
|
32
62
|
end
|
33
63
|
|
64
|
+
# The logger used by DeliveryBoy.
|
65
|
+
#
|
66
|
+
# @return [Logger]
|
34
67
|
def logger
|
35
68
|
@logger ||= Logger.new($stdout)
|
36
69
|
end
|
37
70
|
|
38
71
|
attr_writer :logger
|
39
72
|
|
73
|
+
# The configuration used by DeliveryBoy.
|
74
|
+
#
|
75
|
+
# @return [DeliveryBoy::Config]
|
40
76
|
def config
|
41
77
|
@config ||= DeliveryBoy::Config.new(env: ENV)
|
42
78
|
end
|
data/lib/delivery_boy/config.rb
CHANGED
data/lib/delivery_boy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delivery_boy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-kafka
|