phobos 1.8.2.pre.beta1 → 1.8.2.pre.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6610d5e383b53c4d2f926b4ab10ae33c260215fe2de0520132fa38e6b51089d8
4
- data.tar.gz: '0791b9c0fc4d4b10f878607bddc1374c359bbe627386375ce48ea3ff6996329d'
3
+ metadata.gz: 1263c2db9d40f0099ff81e41fd27c93c29e18a1d5b7b82db37f22c141db11a67
4
+ data.tar.gz: 3185ecc3c82100c1667d7aa70e0c7338fd5077ec77aff07676457d637c6acbf1
5
5
  SHA512:
6
- metadata.gz: dc15fe9776e8aff478e3263a9d8d16b9d693baff6259ae62bdbf1e229b7f8c8bfb345fdf7b9603583ca5405642e1424461c2523ef4bdbcd9b85bd80140a03e6d
7
- data.tar.gz: 782ca0a9838cf38a6ae37c92b33d3ce2f4692438a837aeeefabbea629dd6d5b6c595a6cdc7932e804882d29854784583d356574f8adfaa25613fe093e42cf10c
6
+ metadata.gz: e3010972a7e2de780a046f10c188ec3b65d75c470a84e4f7a64861940a88e95c04dcb99c46cbe08f9ea10ed2ad055fffb13b2ea858891b603f3d5527cd89ab60
7
+ data.tar.gz: '09778609c9c57778ea845f676024c76a7fce13e3942ba3e4f4beca2571cb88ddb4311e39831ff866a1256d18612f179f05415298b249932c0d97a35fb0c069e1'
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --backtrace
data/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## UNRELEASED
8
+
9
+ ## [1.8.2-beta2] - 2019-06-21
10
+ - Added the `persistent_connections` setting and the corresponding
11
+ `sync_producer_shutdown` method to enable reusing the connection
12
+ for regular (sync) producers.
13
+
7
14
  ## [1.8.2-beta1] - 2019-03-13
8
15
 
9
16
  - Added `BatchHandler` to consume messages in batches on the business
data/README.md CHANGED
@@ -21,6 +21,7 @@ With Phobos by your side, all this becomes smooth sailing.
21
21
  ## Table of Contents
22
22
 
23
23
  1. [Installation](#installation)
24
+ 1. [Upgrade Notes](#upgrade-notes)
24
25
  1. [Usage](#usage)
25
26
  1. [Standalone apps](#usage-standalone-apps)
26
27
  1. [Consuming messages from Kafka](#usage-consuming-messages-from-kafka)
@@ -52,6 +53,10 @@ Or install it yourself as:
52
53
  $ gem install phobos
53
54
  ```
54
55
 
56
+ ### <a name="upgrade-notes"></a> Upgrade Notes
57
+
58
+ Version 1.8.2 introduced a new `persistent_connections` setting for regular producers. This reduces the number of connections used to produce messages and you should consider setting it to true. This does require a manual shutdown call - please see [Producers with persistent connections](#persistent-connection).
59
+
55
60
  ## <a name="usage"></a> Usage
56
61
 
57
62
  Phobos can be used in two ways: as a standalone application or to support Kafka features in your existing project - including Rails apps. It provides a CLI tool to run it.
@@ -291,7 +296,7 @@ MyProducer
291
296
 
292
297
  There are two flavors of producers: __regular__ producers and __async__ producers.
293
298
 
294
- Regular producers will deliver the messages synchronously and disconnect, it doesn't matter if you use `publish` or `publish_list` after the messages get delivered the producer will disconnect.
299
+ Regular producers will deliver the messages synchronously and disconnect, it doesn't matter if you use `publish` or `publish_list`; by default, after the messages get delivered the producer will disconnect.
295
300
 
296
301
  Async producers will accept your messages without blocking, use the methods `async_publish` and `async_publish_list` to use async producers.
297
302
 
@@ -310,7 +315,7 @@ class MyHandler
310
315
  end
311
316
  ```
312
317
 
313
- #### Note about configuring producers
318
+ #### <a name="producer-config"></a> Note about configuring producers
314
319
 
315
320
  Since the handler life cycle is managed by the Listener, it will make sure the producer is properly closed before it stops. When calling the producer outside a handler remember, you need to shutdown them manually before you close the application. Use the class method `async_producer_shutdown` to safely shutdown the producer.
316
321
 
@@ -328,6 +333,18 @@ MyProducer
328
333
  .close
329
334
  ```
330
335
 
336
+ ### <a name="persistent-connection"></a> Note about producers with persistent connections
337
+
338
+ By default, regular producers will automatically disconnect after every `publish` call. You can change this behavior (which reduces connection overhead, TLS etc - which increases speed significantly) by setting the `persistent_connections` config in `phobos.yml`. When set, regular producers behave identically to async producers and will also need to be shutdown manually using the `sync_producer_shutdown` method.
339
+
340
+ Since regular producers with persistent connections have open connections, you need to manually disconnect from Kafka when ending your producers' life cycle:
341
+
342
+ ```ruby
343
+ MyProducer
344
+ .producer
345
+ .sync_producer_shutdown
346
+ ```
347
+
331
348
  ### <a name="usage-as-library"></a> Phobos as a library in an existing project
332
349
 
333
350
  When running as a standalone service, Phobos sets up a `Listener` and `Executor` for you. When you use Phobos as a library in your own project, you need to set these components up yourself.
@@ -60,6 +60,11 @@ producer:
60
60
  # if greater than zero, the number of seconds between automatic message
61
61
  # deliveries. Only used for async_producer
62
62
  delivery_interval: 0
63
+ # Set this to true to keep the producer connection between publish calls.
64
+ # This can speed up subsequent messages by around 30%, but it does mean
65
+ # that you need to manually call sync_producer_shutdown before exiting,
66
+ # similar to async_producer_shutdown.
67
+ persistent_connections: false
63
68
 
64
69
  consumer:
65
70
  # number of seconds after which, if a client hasn't contacted the Kafka cluster,
data/lib/phobos.rb CHANGED
@@ -31,6 +31,23 @@ require 'phobos/executor'
31
31
 
32
32
  Thread.abort_on_exception = true
33
33
 
34
+ Logging.init :debug, :info, :warn, :error, :fatal
35
+
36
+ # Monkey patch to fix this issue: https://github.com/zendesk/ruby-kafka/pull/732
37
+ module Logging
38
+ # :nodoc:
39
+ class Logger
40
+ # :nodoc:
41
+ def formatter=(*args); end
42
+
43
+ # :nodoc:
44
+ def push_tags(*args); end
45
+
46
+ # :nodoc:
47
+ def pop_tags(*args); end
48
+ end
49
+ end
50
+
34
51
  module Phobos
35
52
  class << self
36
53
  attr_reader :config, :logger
@@ -52,6 +52,7 @@ module Phobos
52
52
  class PublicAPI
53
53
  NAMESPACE = :phobos_producer_store
54
54
  ASYNC_PRODUCER_PARAMS = [:max_queue_size, :delivery_threshold, :delivery_interval].freeze
55
+ INTERNAL_PRODUCER_PARAMS = [:persistent_connections].freeze
55
56
 
56
57
  # This method configures the kafka client used with publish operations
57
58
  # performed by the host class
@@ -67,18 +68,35 @@ module Phobos
67
68
  producer_store[:kafka_client]
68
69
  end
69
70
 
71
+ def create_sync_producer
72
+ client = kafka_client || configure_kafka_client(Phobos.create_kafka_client)
73
+ sync_producer = client.producer(regular_configs)
74
+ if Phobos.config.producer_hash[:persistent_connections]
75
+ producer_store[:sync_producer] = sync_producer
76
+ end
77
+ sync_producer
78
+ end
79
+
80
+ def sync_producer
81
+ producer_store[:sync_producer]
82
+ end
83
+
84
+ def sync_producer_shutdown
85
+ sync_producer&.shutdown
86
+ producer_store[:sync_producer] = nil
87
+ end
88
+
70
89
  def publish(topic, payload, key = nil, partition_key = nil)
71
90
  publish_list([{ topic: topic, payload: payload, key: key,
72
91
  partition_key: partition_key }])
73
92
  end
74
93
 
75
94
  def publish_list(messages)
76
- client = kafka_client || configure_kafka_client(Phobos.create_kafka_client)
77
- producer = client.producer(regular_configs)
95
+ producer = sync_producer || create_sync_producer
78
96
  produce_messages(producer, messages)
79
97
  producer.deliver_messages
80
98
  ensure
81
- producer&.shutdown
99
+ producer&.shutdown unless Phobos.config.producer_hash[:persistent_connections]
82
100
  end
83
101
 
84
102
  def create_async_producer
@@ -109,11 +127,14 @@ module Phobos
109
127
  end
110
128
 
111
129
  def regular_configs
112
- Phobos.config.producer_hash.reject { |k, _| ASYNC_PRODUCER_PARAMS.include?(k) }
130
+ Phobos.config.producer_hash
131
+ .reject { |k, _| ASYNC_PRODUCER_PARAMS.include?(k) }
132
+ .reject { |k, _| INTERNAL_PRODUCER_PARAMS.include?(k) }
113
133
  end
114
134
 
115
135
  def async_configs
116
136
  Phobos.config.producer_hash
137
+ .reject { |k, _| INTERNAL_PRODUCER_PARAMS.include?(k) }
117
138
  end
118
139
 
119
140
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phobos
4
- VERSION = '1.8.2-beta1'
4
+ VERSION = '1.8.2-beta2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phobos
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2.pre.beta1
4
+ version: 1.8.2.pre.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Túlio Ornelas
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2019-03-13 00:00:00.000000000 Z
18
+ date: 2019-06-21 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler