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 +4 -4
- data/lib/consumer/postgres.rb +1 -0
- data/lib/consumer/postgres/controls.rb +0 -2
- data/lib/consumer/postgres/controls/category.rb +12 -0
- data/lib/consumer/postgres/controls/id.rb +1 -1
- data/lib/consumer/postgres/controls/message.rb +2 -0
- data/lib/consumer/postgres/controls/position/stream/write.rb +2 -2
- data/lib/consumer/postgres/controls/stream_name.rb +5 -14
- data/lib/consumer/postgres/identifier.rb +7 -0
- data/lib/consumer/postgres/position_store.rb +4 -0
- data/lib/consumer/postgres/position_store/stream_name.rb +12 -4
- data/lib/consumer/postgres/postgres.rb +43 -96
- metadata +8 -9
- data/lib/consumer/postgres/controls/condition.rb +0 -25
- data/lib/consumer/postgres/controls/message_data.rb +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2cc5ecbb73d89d8374981ab62efe89cee7d5a6d9a8431dd2700ed880fce96806
|
|
4
|
+
data.tar.gz: bf8dbfc0bb5657e95f87ca26b823cc35c495ab85a506a2b53588715a0b607df3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5f59a010a570efe5b51da63f28054a6a6447fc5b64203e053e5ce02d5e278c656d334be2425f64212556d41737ed7b2568c471f508cad731fe1496ad52386d32
|
|
7
|
+
data.tar.gz: a8e67c94d15340b3da9424e822cbd65e7b19ca6b6e6c2fac0ea8f90852c5769f2001bfaac49286fb0b4b9c0494c03604d1556b5980fe5a8c9fdb4e261e203f83
|
data/lib/consumer/postgres.rb
CHANGED
|
@@ -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
|
|
@@ -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 ||=
|
|
8
|
+
stream_name ||= Category::Position.example
|
|
9
9
|
|
|
10
|
-
message = Store::Recorded.example
|
|
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 = ::
|
|
4
|
+
StreamName = Messaging::Controls::StreamName
|
|
5
5
|
|
|
6
6
|
module StreamName
|
|
7
7
|
module Position
|
|
8
|
-
def self.example(id: 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
|
-
|
|
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
|
|
@@ -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
|
-
|
|
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
|
-
|
|
18
|
+
if not type_list.include?(position_type)
|
|
19
|
+
type_list << position_type
|
|
20
|
+
end
|
|
13
21
|
|
|
14
|
-
|
|
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
|
-
|
|
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
|
|
17
|
-
|
|
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
|
|
26
|
-
|
|
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
|
-
|
|
24
|
+
STDOUT.puts " Condition: #{condition.inspect || '(none)'}"
|
|
31
25
|
end
|
|
26
|
+
end
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
39
|
-
|
|
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
|
-
|
|
50
|
+
session_settings ||= settings
|
|
49
51
|
|
|
50
|
-
|
|
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
|
-
|
|
53
|
-
|
|
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
|
-
|
|
62
|
+
|
|
63
|
+
MessageStore::Postgres::Get::Category.configure(
|
|
61
64
|
self,
|
|
62
|
-
|
|
65
|
+
category,
|
|
63
66
|
batch_size: batch_size,
|
|
64
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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:
|
|
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:
|
|
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.
|
|
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
|
|
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
|