event_store_client 2.1.4 → 2.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4ff17cd8c1913a09f27fd8ae0c846309b54d984ca81faa8291b769357ead3ec
4
- data.tar.gz: b658667a55cc43ba62995e1369e4b8b0f2ee2c950b08dc5dfd19da75e1af430f
3
+ metadata.gz: f072cd6b9f3a8cb41ac746eed4cb472cf0581c042c117082076c9f29b391bbd5
4
+ data.tar.gz: 3fa6712c4be66e24b97bf364c22cbca1318a7681e1bc5ea765268ea19495545e
5
5
  SHA512:
6
- metadata.gz: 6ece79e50bb8a38629587ad87fc6b69e4dea30fd2edb83f34a5fbc5daa760eb11970a02475c6258769d3ba0c9b108bd0bec0464398885e8ae909884650f37047
7
- data.tar.gz: 3cc3551a091362045c125b0ea1ef014a0f798a0683401c5c13a43688d570809a185f74d4f7f5e405f442101e906edd4e0f42282114d8e0910cae1cbbb9884635
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
 
@@ -83,3 +120,11 @@ Possible options:
83
120
  | grpcRetryAttempts | Integer | `3` | Number of times to retry GRPC requests. Does not apply to discovery requests. Final number of requests in cases of error will be initial request + grpcRetryAttempts. |
84
121
  | grpcRetryInterval | Integer | `100` | Milliseconds. Delay between GRPC requests. retries. |
85
122
  | throwOnAppendFailure | Boolean | `true` | Defines if append requests should immediately raise an error. If set to `false`, request will be retried in case of a server error. |
123
+
124
+ Examples:
125
+
126
+ ```
127
+ esdb://localhost:2113/?tls=false
128
+ esdb+discover://localhost:2113/?grpcRetryAttempts=3&grpcRetryInterval=300&discoverInterval=200
129
+ esdb://localhost:2113,localhost:2114,localhost:2115/?gossipTimeout=500&maxDiscoverAttempts=3
130
+ ```
@@ -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
@@ -4,6 +4,7 @@
4
4
  require 'google/protobuf'
5
5
 
6
6
  require 'google/protobuf/empty_pb'
7
+ require 'google/protobuf/any_pb'
7
8
 
8
9
  Google::Protobuf::DescriptorPool.generated_pool.build do
9
10
  add_file("shared.proto", :syntax => :proto3) do
@@ -55,6 +56,30 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
55
56
  add_message "event_store.client.BadRequest" do
56
57
  optional :message, :string, 1
57
58
  end
59
+ add_message "event_store.client.Status" do
60
+ optional :code, :enum, 1, "event_store.client.Code"
61
+ optional :message, :string, 2
62
+ optional :details, :message, 3, "google.protobuf.Any"
63
+ end
64
+ add_enum "event_store.client.Code" do
65
+ value :OK, 0
66
+ value :CANCELLED, 1
67
+ value :UNKNOWN, 2
68
+ value :INVALID_ARGUMENT, 3
69
+ value :DEADLINE_EXCEEDED, 4
70
+ value :NOT_FOUND, 5
71
+ value :ALREADY_EXISTS, 6
72
+ value :PERMISSION_DENIED, 7
73
+ value :UNAUTHENTICATED, 16
74
+ value :RESOURCE_EXHAUSTED, 8
75
+ value :FAILED_PRECONDITION, 9
76
+ value :ABORTED, 10
77
+ value :OUT_OF_RANGE, 11
78
+ value :UNIMPLEMENTED, 12
79
+ value :INTERNAL, 13
80
+ value :UNAVAILABLE, 14
81
+ value :DATA_LOSS, 15
82
+ end
58
83
  end
59
84
  end
60
85
 
@@ -73,5 +98,7 @@ module EventStore
73
98
  InvalidTransaction = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.InvalidTransaction").msgclass
74
99
  MaximumAppendSizeExceeded = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.MaximumAppendSizeExceeded").msgclass
75
100
  BadRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.BadRequest").msgclass
101
+ Status = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.Status").msgclass
102
+ Code = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.Code").enummodule
76
103
  end
77
104
  end
@@ -4,7 +4,6 @@
4
4
  require 'google/protobuf'
5
5
 
6
6
  require_relative 'shared_pb'
7
- require_relative 'status_pb'
8
7
  require 'google/protobuf/duration_pb'
9
8
  require 'google/protobuf/empty_pb'
10
9
  require 'google/protobuf/timestamp_pb'
@@ -211,7 +210,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
211
210
  optional :correlation_id, :message, 1, "event_store.client.UUID"
212
211
  optional :stream_identifier, :message, 4, "event_store.client.StreamIdentifier"
213
212
  oneof :result do
214
- optional :error, :message, 2, "google.rpc.Status"
213
+ optional :error, :message, 2, "event_store.client.Status"
215
214
  optional :success, :message, 3, "event_store.client.streams.BatchAppendResp.Success"
216
215
  end
217
216
  oneof :expected_stream_position do
@@ -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.4'
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_store_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Wilgosz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-29 00:00:00.000000000 Z
11
+ date: 2022-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads
@@ -191,7 +191,6 @@ files:
191
191
  - lib/event_store_client/adapters/grpc/discover.rb
192
192
  - lib/event_store_client/adapters/grpc/generated/cluster_pb.rb
193
193
  - lib/event_store_client/adapters/grpc/generated/cluster_services_pb.rb
194
- - lib/event_store_client/adapters/grpc/generated/code_pb.rb
195
194
  - lib/event_store_client/adapters/grpc/generated/gossip_pb.rb
196
195
  - lib/event_store_client/adapters/grpc/generated/gossip_services_pb.rb
197
196
  - lib/event_store_client/adapters/grpc/generated/monitoring_pb.rb
@@ -205,7 +204,6 @@ files:
205
204
  - lib/event_store_client/adapters/grpc/generated/serverfeatures_pb.rb
206
205
  - lib/event_store_client/adapters/grpc/generated/serverfeatures_services_pb.rb
207
206
  - lib/event_store_client/adapters/grpc/generated/shared_pb.rb
208
- - lib/event_store_client/adapters/grpc/generated/status_pb.rb
209
207
  - lib/event_store_client/adapters/grpc/generated/streams_pb.rb
210
208
  - lib/event_store_client/adapters/grpc/generated/streams_services_pb.rb
211
209
  - lib/event_store_client/adapters/grpc/generated/users_pb.rb
@@ -216,6 +214,7 @@ files:
216
214
  - lib/event_store_client/adapters/grpc/shared/options/stream_options.rb
217
215
  - lib/event_store_client/adapters/grpc/shared/streams/process_response.rb
218
216
  - lib/event_store_client/adapters/grpc/shared/streams/process_responses.rb
217
+ - lib/event_store_client/config.rb
219
218
  - lib/event_store_client/configuration.rb
220
219
  - lib/event_store_client/connection/url.rb
221
220
  - lib/event_store_client/connection/url_parser.rb
@@ -1,34 +0,0 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # source: code.proto
3
-
4
- require 'google/protobuf'
5
-
6
- Google::Protobuf::DescriptorPool.generated_pool.build do
7
- add_file("code.proto", :syntax => :proto3) do
8
- add_enum "google.rpc.Code" do
9
- value :OK, 0
10
- value :CANCELLED, 1
11
- value :UNKNOWN, 2
12
- value :INVALID_ARGUMENT, 3
13
- value :DEADLINE_EXCEEDED, 4
14
- value :NOT_FOUND, 5
15
- value :ALREADY_EXISTS, 6
16
- value :PERMISSION_DENIED, 7
17
- value :UNAUTHENTICATED, 16
18
- value :RESOURCE_EXHAUSTED, 8
19
- value :FAILED_PRECONDITION, 9
20
- value :ABORTED, 10
21
- value :OUT_OF_RANGE, 11
22
- value :UNIMPLEMENTED, 12
23
- value :INTERNAL, 13
24
- value :UNAVAILABLE, 14
25
- value :DATA_LOSS, 15
26
- end
27
- end
28
- end
29
-
30
- module Google
31
- module Rpc
32
- Code = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.rpc.Code").enummodule
33
- end
34
- end
@@ -1,23 +0,0 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # source: status.proto
3
-
4
- require 'google/protobuf'
5
-
6
- require 'google/protobuf/any_pb'
7
- require_relative 'code_pb'
8
-
9
- Google::Protobuf::DescriptorPool.generated_pool.build do
10
- add_file("status.proto", :syntax => :proto3) do
11
- add_message "google.rpc.Status" do
12
- optional :code, :enum, 1, "google.rpc.Code"
13
- optional :message, :string, 2
14
- optional :details, :message, 3, "google.protobuf.Any"
15
- end
16
- end
17
- end
18
-
19
- module Google
20
- module Rpc
21
- Status = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.rpc.Status").msgclass
22
- end
23
- end