event_store_client 2.1.5 → 2.2.0

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: a4b94342dbb48eeba88c4f87758497bf3604ec01d1954163af2d9add2e88e46f
4
- data.tar.gz: 195564b4fded0a7c5986b4f3b5b76a19ad97018113238389a26254df27191f49
3
+ metadata.gz: f072cd6b9f3a8cb41ac746eed4cb472cf0581c042c117082076c9f29b391bbd5
4
+ data.tar.gz: 3fa6712c4be66e24b97bf364c22cbca1318a7681e1bc5ea765268ea19495545e
5
5
  SHA512:
6
- metadata.gz: 62c2faaed828d92add77f8c8af76f7bae5fe3fa990e9820e4fc5dd6b74ad7b3fbe0e84aa7d2975c6903e91e959d6969d5ae30aa3d2916300086d2cfa81fce8b0
7
- data.tar.gz: 5b282b014013149ecb61531ad02fe654321765f15da09fc4ffeadabc2fbefc21c919a769d657cfc0fe7922d80338dab6908bf1a00a21b672d9128603062e448f
6
+ metadata.gz: b0d8489a114c666079639e76817a01f1986df193434cdf0efc22e5fea968e4670e96176a433464ac2f5669f3bfdae5ef94a7b2f19b87a5ef891aebef5c6f65e2
7
+ data.tar.gz: 4e9ae526f384e00b2f4d5739b4f825f5336d87a9193e02f01ee87f94282c385344750653d844074e431ae1d59bad93270a362caa8d92c1a2972544e037372620
@@ -6,15 +6,52 @@ Currently only one setup is supported. For example, you can't configure a connec
6
6
 
7
7
  Configuration options:
8
8
 
9
- | name | value | default value | description |
10
- |----------------------|--------------------------------------------------------------------------------------|-----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
11
- | eventstore_url | String | `'esdb://localhost:2113'` | Connection string. See description of possible values below. |
12
- | per_page | Integer | `20` | Number of events to return in one response. |
13
- | mapper | `EventStoreClient::Mapper::Default.new` or `EventStoreClient::Mapper::Encrypted.new` | `EventStoreClient::Mapper::Default.new` | An object that is responsible for serialization / deserialization and encryption / decryption of events. |
14
- | default_event_class | `DeserializedEvent` or any class, inherited from it | `DeserializedEvent` | This class will be used during the deserialization process when deserializer fails to resolve an event's class from response. |
15
- | logger | `Logger` | `nil` | A logger that would log messages from `event_store_client` and `grpc` gems. |
16
- | skip_deserialization | Boolean | `false` | Whether to skip event deserialization using the given `mapper` setting. If you set it to `true` decryption will be skipped as well. It is useful when you want to defer deserialization and handle it later by yourself. |
17
- | skip_decryption | Boolean | `false` | Whether to skip decrypting encrypted event payloads. |
9
+ | name | value | default value | description |
10
+ |----------------------|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
11
+ | eventstore_url | String | `'esdb://localhost:2113'` | Connection string. See description of possible values below. |
12
+ | per_page | Integer | `20` | Number of events to return in one response. |
13
+ | mapper | `EventStoreClient::Mapper::Default.new` or `EventStoreClient::Mapper::Encrypted.new` | `EventStoreClient::Mapper::Default.new` | An object that is responsible for serialization / deserialization and encryption / decryption of events. |
14
+ | default_event_class | `DeserializedEvent` or any class, inherited from it | `DeserializedEvent` | This class will be used during the deserialization process when deserializer fails to resolve an event's class from response. |
15
+ | logger | `Logger` | `nil` | A logger that would log messages from `event_store_client` and `grpc` gems. |
16
+ | skip_deserialization | Boolean | `false` | Whether to skip event deserialization using the given `mapper` setting. If you set it to `true` decryption will be skipped as well. It is useful when you want to defer deserialization and handle it later by yourself. |
17
+ | skip_decryption | Boolean | `false` | Whether to skip decrypting encrypted event payloads. |
18
+ | channel_args | Hash | `{ 'grpc.min_reconnect_backoff_ms' => 100, 'grpc.max_reconnect_backoff_ms' => 100, 'grpc.initial_reconnect_backoff_ms' => 100 }` | GRPC-specific connection options. This hash will be passed into the `:channel_args` argument of a Stub class of your request. More GRPC options can be found [here](https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/grpc_types.h). |
19
+
20
+ ## A note about channel_args option
21
+
22
+ When defining the custom value of this option - the default value will be reverse-merged into it. So, for example, if you would like to set `grpc.min_reconnect_backoff_ms` like so:
23
+
24
+ ```ruby
25
+ EventStoreClient.configure do |config|
26
+ config.channel_args = { 'grpc.min_reconnect_backoff_ms' => 200 }
27
+ end
28
+ ```
29
+
30
+ the resulting `channel_args` value will be
31
+
32
+ ```ruby
33
+ {
34
+ "grpc.min_reconnect_backoff_ms" => 200,
35
+ "grpc.max_reconnect_backoff_ms" => 100,
36
+ "grpc.initial_reconnect_backoff_ms" => 100
37
+ }
38
+ ```
39
+
40
+ This behaviour is intentional. So, if you want to override them all - you should do it explicitly. Example:
41
+
42
+ ```ruby
43
+ EventStoreClient.configure do |config|
44
+ config.channel_args = {
45
+ 'grpc.min_reconnect_backoff_ms' => 500,
46
+ 'grpc.max_reconnect_backoff_ms' => 500,
47
+ 'grpc.initial_reconnect_backoff_ms' => 500
48
+ }
49
+ end
50
+ ```
51
+
52
+ It could be useful when you have high ping to your EventStore DB server.
53
+
54
+ Besides, there is an option which you can't change - `grpc.enable_retries`. It always defaults to `0`. This is because `event_store_client` implements its own retry functional.
18
55
 
19
56
  ## Connection string
20
57
 
@@ -11,7 +11,7 @@ module EventStoreClient
11
11
  stub_class.new(
12
12
  "#{host}:#{port}",
13
13
  :this_channel_is_insecure,
14
- channel_args: channel_args,
14
+ channel_args: config.channel_args,
15
15
  timeout: (timeout / 1000.0 if timeout)
16
16
  )
17
17
  end
@@ -13,7 +13,7 @@ module EventStoreClient
13
13
  stub_class.new(
14
14
  "#{host}:#{port}",
15
15
  channel_credentials,
16
- channel_args: channel_args,
16
+ channel_args: config.channel_args,
17
17
  timeout: (timeout / 1000.0 if timeout)
18
18
  )
19
19
  end
@@ -55,23 +55,6 @@ module EventStoreClient
55
55
  def call(stub_class)
56
56
  raise NotImplementedError
57
57
  end
58
-
59
- private
60
-
61
- # Common channel arguments for all GRPC requests.
62
- # Available channel arguments are described here
63
- # https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/grpc_types.h
64
- # @return [Hash]
65
- def channel_args
66
- {
67
- # disable build-in GRPC retries functional
68
- 'grpc.enable_retries' => 0,
69
- # These three options reduce delays between failed requests.
70
- 'grpc.min_reconnect_backoff_ms' => 100, # milliseconds
71
- 'grpc.max_reconnect_backoff_ms' => 100, # milliseconds
72
- 'grpc.initial_reconnect_backoff_ms' => 100 # milliseconds
73
- }
74
- end
75
58
  end
76
59
  end
77
60
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EventStoreClient
4
+ class Config
5
+ include Extensions::OptionsExtension
6
+
7
+ CHANNEL_ARGS_DEFAULTS = {
8
+ # These three options reduce delays between failed requests.
9
+ 'grpc.min_reconnect_backoff_ms' => 100, # milliseconds
10
+ 'grpc.max_reconnect_backoff_ms' => 100, # milliseconds
11
+ 'grpc.initial_reconnect_backoff_ms' => 100 # milliseconds
12
+ }.freeze
13
+
14
+ option(:eventstore_url) { 'esdb://localhost:2113' }
15
+ option(:per_page) { 20 }
16
+ option(:mapper) { Mapper::Default.new }
17
+ option(:default_event_class) { DeserializedEvent }
18
+ option(:logger)
19
+ option(:skip_deserialization) { false }
20
+ option(:skip_decryption) { false }
21
+ # GRPC-specific connection options. This hash will be passed into the `:channel_args` argument
22
+ # of a Stub class of your request. More GRPC options can be found here
23
+ # https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/grpc_types.h
24
+ option(:channel_args) # Hash
25
+
26
+ def eventstore_url=(value)
27
+ @eventstore_url =
28
+ if value.is_a?(Connection::Url)
29
+ value
30
+ else
31
+ Connection::UrlParser.new.call(value)
32
+ end
33
+ end
34
+
35
+ # @param logger [Logger, nil]
36
+ # @return [Logger, nil]
37
+ def logger=(logger)
38
+ ::GRPC.define_singleton_method :logger do
39
+ @logger ||= logger.nil? ? ::GRPC::DefaultLogger::NoopLogger.new : logger
40
+ end
41
+ @logger = logger
42
+ end
43
+
44
+ # @param val [Hash, nil]
45
+ # @return [Hash]
46
+ def channel_args=(val)
47
+ channel_args = CHANNEL_ARGS_DEFAULTS.merge(val&.transform_keys(&:to_s) || {})
48
+ # This options always defaults to `0`. This is because `event_store_client` implements its
49
+ # own retry functional.
50
+ channel_args['grpc.enable_retries'] = 0
51
+ @channel_args = channel_args
52
+ end
53
+ end
54
+ end
@@ -1,57 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EventStoreClient
4
- class Config
5
- include Extensions::OptionsExtension
6
-
7
- option(:eventstore_url) { 'esdb://localhost:2113' }
8
- option(:per_page) { 20 }
9
- option(:mapper) { Mapper::Default.new }
10
- option(:default_event_class) { DeserializedEvent }
11
- option(:logger)
12
- option(:skip_deserialization) { false }
13
- option(:skip_decryption) { false }
14
-
15
- def eventstore_url=(value)
16
- @eventstore_url =
17
- if value.is_a?(Connection::Url)
18
- value
19
- else
20
- Connection::UrlParser.new.call(value)
21
- end
22
- end
23
-
24
- # @param logger [Logger, nil]
25
- # @return [Logger, nil]
26
- def logger=(logger)
27
- ::GRPC.define_singleton_method :logger do
28
- @logger ||= logger.nil? ? ::GRPC::DefaultLogger::NoopLogger.new : logger
29
- end
30
- @logger = logger
31
- end
32
- end
33
-
34
- class << self
35
- def configure
36
- yield(config) if block_given?
37
- end
38
-
39
- def config
40
- @config ||= Config.new
41
- end
42
-
43
- def client
44
- GRPC::Client.new
45
- end
46
- end
47
-
48
- # Configuration module to be included in classes required configured variables
49
- # Usage: include EventStore::Configuration
50
- # config.eventstore_url
51
- #
52
4
  module Configuration
53
- # An instance of the EventStoreClient's configuration
54
- #
5
+ # @return [EventStoreClient::Config]
55
6
  def config
56
7
  EventStoreClient.config
57
8
  end
@@ -52,6 +52,14 @@ module EventStoreClient
52
52
  option(:grpc_retry_attempts) { 3 }
53
53
  # Delay between GRPC request retries
54
54
  option(:grpc_retry_interval) { 100 } # milliseconds
55
+
56
+ # @param other [EventStoreClient::Connection::Url, Object]
57
+ # @return [Boolean]
58
+ def ==(other)
59
+ return false unless other.is_a?(Url)
60
+
61
+ options_hash == other.options_hash
62
+ end
55
63
  end
56
64
  end
57
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EventStoreClient
4
- VERSION = '2.1.5'
4
+ VERSION = '2.2.0'
5
5
  end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module EventStoreClient
4
- end
5
-
6
3
  require 'json'
7
4
  require 'set'
8
5
 
@@ -18,8 +15,27 @@ require 'event_store_client/connection/url'
18
15
  require 'event_store_client/connection/url_parser'
19
16
  require 'event_store_client/deserialized_event'
20
17
  require 'event_store_client/serialized_event'
18
+ require 'event_store_client/config'
21
19
  require 'event_store_client/configuration'
22
20
 
23
21
  require 'event_store_client/mapper'
24
22
 
25
23
  require 'event_store_client/adapters/grpc'
24
+
25
+ module EventStoreClient
26
+ class << self
27
+ def configure
28
+ yield(config) if block_given?
29
+ end
30
+
31
+ # @return [EventStore::Config]
32
+ def config
33
+ @config ||= Config.new
34
+ end
35
+
36
+ # @return [EventStore::GRPC::Client]
37
+ def client
38
+ GRPC::Client.new
39
+ end
40
+ end
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_store_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Wilgosz
@@ -214,6 +214,7 @@ files:
214
214
  - lib/event_store_client/adapters/grpc/shared/options/stream_options.rb
215
215
  - lib/event_store_client/adapters/grpc/shared/streams/process_response.rb
216
216
  - lib/event_store_client/adapters/grpc/shared/streams/process_responses.rb
217
+ - lib/event_store_client/config.rb
217
218
  - lib/event_store_client/configuration.rb
218
219
  - lib/event_store_client/connection/url.rb
219
220
  - lib/event_store_client/connection/url_parser.rb