evt-consumer-postgres 1.1.0.0 → 2.3.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: 861ae33dd8cdc77daa5ff1a5772a92197668213c7a40b3b043541184925af076
4
- data.tar.gz: b5c2826abe9d2b894206d089d566983386535229206c2ff1d0f629f36ec7a078
3
+ metadata.gz: 2cc5ecbb73d89d8374981ab62efe89cee7d5a6d9a8431dd2700ed880fce96806
4
+ data.tar.gz: bf8dbfc0bb5657e95f87ca26b823cc35c495ab85a506a2b53588715a0b607df3
5
5
  SHA512:
6
- metadata.gz: 52a29b32a7dc60e891d3faf0b023f24baaf4ce1ddbe45419767b32b407a53d9e9bebcf74f492f3e0b7fe8e934cc2eedf18cd33c87e9cacf82313a3e9d2788d02
7
- data.tar.gz: 714324b6df2649764467298e9826e6ae5e0c23eb490dcdadcb566124dbf93e8edb94f6e6e54e0116d14b98480349a7c236e5245dac7a1957db49ca1512fb6a4d
6
+ metadata.gz: 5f59a010a570efe5b51da63f28054a6a6447fc5b64203e053e5ce02d5e278c656d334be2425f64212556d41737ed7b2568c471f508cad731fe1496ad52386d32
7
+ data.tar.gz: a8e67c94d15340b3da9424e822cbd65e7b19ca6b6e6c2fac0ea8f90852c5769f2001bfaac49286fb0b4b9c0494c03604d1556b5980fe5a8c9fdb4e261e203f83
@@ -1,6 +1,7 @@
1
1
  require 'consumer'
2
2
 
3
3
  require 'messaging/postgres'
4
+ require 'consumer/postgres/identifier'
4
5
 
5
6
  require 'consumer/postgres/position_store'
6
7
  require 'consumer/postgres/position_store/recorded'
@@ -5,13 +5,11 @@ require 'message_store/postgres/controls'
5
5
  require 'consumer/postgres/controls/category'
6
6
  require 'consumer/postgres/controls/id'
7
7
  require 'consumer/postgres/controls/identifier'
8
- require 'consumer/postgres/controls/message_data'
9
8
  require 'consumer/postgres/controls/message'
10
9
  require 'consumer/postgres/controls/position'
11
10
  require 'consumer/postgres/controls/position/store/recorded'
12
11
  require 'consumer/postgres/controls/position/stream/write'
13
12
  require 'consumer/postgres/controls/stream_name'
14
13
 
15
- require 'consumer/postgres/controls/condition'
16
14
  require 'consumer/postgres/controls/handler'
17
15
  require 'consumer/postgres/controls/consumer'
@@ -2,6 +2,18 @@ module Consumer
2
2
  module Postgres
3
3
  module Controls
4
4
  Category = MessageStore::Postgres::Controls::Category
5
+
6
+ module Category
7
+ module Position
8
+ def self.example
9
+ category = Controls::Category.example
10
+
11
+ type = 'position'
12
+
13
+ MessageStore::StreamName.stream_name(category, type: type)
14
+ end
15
+ end
16
+ end
5
17
  end
6
18
  end
7
19
  end
@@ -1,7 +1,7 @@
1
1
  module Consumer
2
2
  module Postgres
3
3
  module Controls
4
- ID = Identifier::UUID::Controls::Incrementing
4
+ ID = ::Identifier::UUID::Controls::Incrementing
5
5
  end
6
6
  end
7
7
  end
@@ -8,6 +8,8 @@ module Consumer
8
8
 
9
9
  message
10
10
  end
11
+
12
+ Metadata = Messaging::Controls::Metadata
11
13
  end
12
14
  end
13
15
  end
@@ -5,9 +5,9 @@ module Consumer
5
5
  module Stream
6
6
  module Write
7
7
  def self.call(stream_name=nil, position: nil)
8
- stream_name ||= StreamName::Position.example
8
+ stream_name ||= Category::Position.example
9
9
 
10
- message = Store::Recorded.example position: position
10
+ message = Store::Recorded.example(position: position)
11
11
 
12
12
  Messaging::Postgres::Write.(message, stream_name)
13
13
 
@@ -1,31 +1,22 @@
1
1
  module Consumer
2
2
  module Postgres
3
3
  module Controls
4
- StreamName = ::Consumer::Controls::StreamName
4
+ StreamName = Messaging::Controls::StreamName
5
5
 
6
6
  module StreamName
7
7
  module Position
8
- def self.example(id: nil, randomize_category: nil, types: nil)
8
+ def self.example(id: nil, category: nil, types: nil)
9
+ category ||= Controls::Category.example(category: category)
9
10
  types ||= []
10
11
 
11
12
  types << 'position'
12
13
 
13
- StreamName.example(
14
+ Messaging::Controls::StreamName.example(
14
15
  id: id,
15
- randomize_category: randomize_category,
16
+ category: category,
16
17
  types: types
17
18
  )
18
19
  end
19
-
20
- module Category
21
- def self.example(category: nil)
22
- category = Controls::Category.example category: category
23
-
24
- position_type = 'position'
25
-
26
- MessageStore::StreamName.stream_name(category, type: position_type)
27
- end
28
- end
29
20
  end
30
21
  end
31
22
  end
@@ -0,0 +1,7 @@
1
+ module Consumer
2
+ module Postgres
3
+ module Identifier
4
+ Error = Class.new(RuntimeError)
5
+ end
6
+ end
7
+ end
@@ -29,6 +29,10 @@ module Consumer
29
29
  Messaging::Postgres::Write.configure(self, session: session)
30
30
  end
31
31
 
32
+ def location
33
+ stream_name
34
+ end
35
+
32
36
  def get
33
37
  message_data = read.(stream_name)
34
38
 
@@ -2,16 +2,24 @@ module Consumer
2
2
  module Postgres
3
3
  class PositionStore
4
4
  module StreamName
5
+ Error = Class.new(RuntimeError)
6
+
5
7
  def self.position_stream_name(stream_name, consumer_identifier: nil)
8
+ if not MessageStore::StreamName.category?(stream_name)
9
+ raise Error, "Position store's stream name must be a category (Stream Name: #{stream_name})"
10
+ end
11
+
6
12
  stream_id = MessageStore::StreamName.get_id(stream_name)
7
- entity = MessageStore::StreamName.get_entity_name(stream_name)
13
+ entity_name = MessageStore::StreamName.get_entity_name(stream_name)
8
14
  type_list = MessageStore::StreamName.get_types(stream_name)
9
15
 
10
16
  position_type = Type.get
11
17
 
12
- type_list << position_type unless type_list.include?(position_type)
18
+ if not type_list.include?(position_type)
19
+ type_list << position_type
20
+ end
13
21
 
14
- unless consumer_identifier.nil?
22
+ if not consumer_identifier.nil?
15
23
  if stream_id.nil?
16
24
  stream_id = consumer_identifier
17
25
  else
@@ -20,7 +28,7 @@ module Consumer
20
28
  end
21
29
 
22
30
  MessageStore::StreamName.stream_name(
23
- entity,
31
+ entity_name,
24
32
  stream_id,
25
33
  types: type_list
26
34
  )
@@ -6,130 +6,77 @@ module Consumer
6
6
 
7
7
  attr_accessor :batch_size
8
8
  attr_accessor :correlation
9
- attr_accessor :group_size
10
9
  attr_accessor :group_member
10
+ attr_accessor :group_size
11
11
  attr_accessor :condition
12
- attr_accessor :composed_condition
13
12
  end
14
13
  end
15
14
 
16
- def starting
17
- unless batch_size.nil?
18
- logger.info(tag: :*) { "Batch Size: #{batch_size}" }
19
- end
20
-
21
- unless correlation.nil?
22
- logger.info(tag: :*) { "Correlation: #{correlation}" }
23
- end
15
+ def print_startup_info
16
+ STDOUT.puts " Correlation: #{correlation || '(none)'}"
24
17
 
25
- unless group_size.nil? && group_member.nil?
26
- logger.info(tag: :*) { "Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect}" }
18
+ unless group_member.nil? && group_size.nil?
19
+ STDOUT.puts " Group Member: #{group_member.inspect}"
20
+ STDOUT.puts " Group Size: #{group_size.inspect}"
27
21
  end
28
22
 
29
23
  unless condition.nil?
30
- logger.info(tag: :*) { "Condition: #{condition}" }
24
+ STDOUT.puts " Condition: #{condition.inspect || '(none)'}"
31
25
  end
26
+ end
32
27
 
33
- unless composed_condition.nil?
34
- logger.debug(tag: :*) { "Composed Condition: #{composed_condition}" }
35
- end
28
+ def log_startup_info
29
+ logger.info(tags: [:consumer, :start]) { "Correlation: #{correlation.inspect} (Consumer: #{self.class.name})" }
30
+ logger.info(tags: [:consumer, :start]) { "Batch Size: #{get.batch_size.inspect} (Consumer: #{self.class.name})" }
31
+ logger.info(tags: [:consumer, :start]) { "Group Member: #{group_member.inspect} (Consumer: #{self.class.name})" }
32
+ logger.info(tags: [:consumer, :start]) { "Group Size: #{group_size.inspect} (Consumer: #{self.class.name})" }
33
+ logger.info(tags: [:consumer, :start]) { "Condition: #{condition.inspect} (Consumer: #{self.class.name})" }
36
34
  end
37
35
 
38
- def configure(batch_size: nil, settings: nil, correlation: nil, group_size: nil, group_member: nil, condition: nil)
39
- composed_condition = Condition.compose(correlation: correlation, group_size: group_size, group_member: group_member, condition: condition)
36
+ def starting
37
+ if identifier.nil? && !group_member.nil? && !group_size.nil?
38
+ raise Identifier::Error, 'Identifier must not be omitted when the consumer is a member of a group'
39
+ end
40
+ end
40
41
 
42
+ # TODO: Remove deprecated settings argument that has been replaced with session_settings when no longer in use (Nathan Ladd, Mon Nov 30 2020)
43
+ def configure(session_settings: nil, batch_size: nil, correlation: nil, group_member: nil, group_size: nil, condition: nil, settings: nil)
41
44
  self.batch_size = batch_size
42
45
  self.correlation = correlation
43
- self.group_size = group_size
44
46
  self.group_member = group_member
47
+ self.group_size = group_size
45
48
  self.condition = condition
46
- self.composed_condition = composed_condition
47
49
 
48
- MessageStore::Postgres::Session.configure(self, settings: settings)
50
+ session_settings ||= settings
49
51
 
50
- session = self.session
52
+ if not session_settings.nil?
53
+ if not session_settings.is_a?(::Settings)
54
+ session_settings = ::Settings.build(session_settings)
55
+ end
56
+ end
51
57
 
52
- PositionStore.configure(
53
- self,
54
- stream_name,
55
- consumer_identifier: identifier,
56
- session: session
57
- )
58
+ MessageStore::Postgres::Session.configure(self, settings: session_settings)
59
+ session = self.session
58
60
 
59
61
  get_session = MessageStore::Postgres::Session.build(settings: settings)
60
- MessageStore::Postgres::Get.configure(
62
+
63
+ MessageStore::Postgres::Get::Category.configure(
61
64
  self,
62
- stream_name,
65
+ category,
63
66
  batch_size: batch_size,
64
- condition: composed_condition,
67
+ correlation: correlation,
68
+ consumer_group_member: group_member,
69
+ consumer_group_size: group_size,
70
+ condition: condition,
65
71
  session: get_session
66
72
  )
67
- end
68
-
69
- module Condition
70
- extend self
71
-
72
- def compose(condition: nil, correlation: nil, group_size: nil, group_member: nil)
73
- composed_condition = []
74
-
75
- unless condition.nil?
76
- composed_condition << condition
77
- end
78
-
79
- unless correlation.nil?
80
- Correlation.assure(correlation)
81
- composed_condition << "metadata->>'correlationStreamName' like '#{correlation}-%'"
82
- end
83
73
 
84
- unless group_size.nil? && group_member.nil?
85
- Group.assure(group_size, group_member)
86
- composed_condition << "@hash_64(stream_name) % #{group_size} = #{group_member}"
87
- end
88
-
89
- return nil if composed_condition.empty?
90
-
91
- sql_condition = composed_condition.join(' AND ')
92
-
93
- sql_condition
94
- end
95
- end
96
-
97
- module Correlation
98
- Error = Class.new(RuntimeError)
99
-
100
- def self.assure(correlation)
101
- unless MessageStore::StreamName.category?(correlation)
102
- raise Correlation::Error, "Correlation must be a category (Correlation: #{correlation})"
103
- end
104
- end
105
- end
106
-
107
- module Group
108
- Error = Class.new(RuntimeError)
109
-
110
- def self.assure(group_size, group_member)
111
- error_message = 'Consumer group definition is incorrect.'
112
-
113
- arguments_count = [group_size, group_member].compact.length
114
-
115
- if arguments_count == 1
116
- raise Error, "#{error_message} Group size and group member are both required. (Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect})"
117
- end
118
-
119
- return if arguments_count == 0
120
-
121
- if group_size < 1
122
- raise Error, "#{error_message} Group size must not be less than 1. (Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect})"
123
- end
124
-
125
- if group_member < 0
126
- raise Error, "#{error_message} Group member must not be less than 0. (Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect})"
127
- end
128
-
129
- if group_member >= group_size
130
- raise Error, "#{error_message} Group member must be at least one less than group size. (Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect})"
131
- end
132
- end
74
+ PositionStore.configure(
75
+ self,
76
+ category,
77
+ consumer_identifier: identifier,
78
+ session: session
79
+ )
133
80
  end
134
81
  end
135
82
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-consumer-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.0
4
+ version: 2.3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-02 00:00:00.000000000 Z
11
+ date: 2020-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-consumer
@@ -61,17 +61,16 @@ files:
61
61
  - lib/consumer/postgres.rb
62
62
  - lib/consumer/postgres/controls.rb
63
63
  - lib/consumer/postgres/controls/category.rb
64
- - lib/consumer/postgres/controls/condition.rb
65
64
  - lib/consumer/postgres/controls/consumer.rb
66
65
  - lib/consumer/postgres/controls/handler.rb
67
66
  - lib/consumer/postgres/controls/id.rb
68
67
  - lib/consumer/postgres/controls/identifier.rb
69
68
  - lib/consumer/postgres/controls/message.rb
70
- - lib/consumer/postgres/controls/message_data.rb
71
69
  - lib/consumer/postgres/controls/position.rb
72
70
  - lib/consumer/postgres/controls/position/store/recorded.rb
73
71
  - lib/consumer/postgres/controls/position/stream/write.rb
74
72
  - lib/consumer/postgres/controls/stream_name.rb
73
+ - lib/consumer/postgres/identifier.rb
75
74
  - lib/consumer/postgres/position_store.rb
76
75
  - lib/consumer/postgres/position_store/recorded.rb
77
76
  - lib/consumer/postgres/position_store/stream_name.rb
@@ -80,7 +79,7 @@ homepage: https://github.com/eventide-project/consumer-postgres
80
79
  licenses:
81
80
  - MIT
82
81
  metadata: {}
83
- post_install_message:
82
+ post_install_message:
84
83
  rdoc_options: []
85
84
  require_paths:
86
85
  - lib
@@ -95,9 +94,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0'
97
96
  requirements: []
98
- rubygems_version: 3.0.1
99
- signing_key:
97
+ rubygems_version: 3.1.2
98
+ signing_key:
100
99
  specification_version: 4
101
- summary: Postgres implementation of continuous subscription to a stream and message
100
+ summary: Postgres implementation of continuous subscription to a category and message
102
101
  dispatching to handlers
103
102
  test_files: []
@@ -1,25 +0,0 @@
1
- module Consumer
2
- module Postgres
3
- module Controls
4
- module Condition
5
- module Correlation
6
- def self.example(category:)
7
- "metadata->>'correlationStreamName' like '#{category}-%'"
8
- end
9
- end
10
-
11
- module ConsumerGroup
12
- def self.example(group_size:, group_member:)
13
- "@hash_64(stream_name) % #{group_size} = #{group_member}"
14
- end
15
- end
16
-
17
- module Ordinary
18
- def self.example
19
- 'some condition'
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,7 +0,0 @@
1
- module Consumer
2
- module Postgres
3
- module Controls
4
- MessageData = ::Consumer::Controls::MessageData
5
- end
6
- end
7
- end