evt-consumer-postgres 1.1.0.0 → 2.2.0.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/controls/category.rb +12 -0
- data/lib/consumer/postgres/controls/position/stream/write.rb +2 -2
- data/lib/consumer/postgres/controls/stream_name.rb +3 -12
- data/lib/consumer/postgres/controls.rb +0 -2
- data/lib/consumer/postgres/position_store/stream_name.rb +12 -4
- data/lib/consumer/postgres/postgres.rb +18 -89
- metadata +3 -5
- 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: d70c7356d131dd6d6cbe9242ddfa54ac600e40cea725de3232042cb3b0cac802
|
4
|
+
data.tar.gz: 2aecd3ff64cd6258b48b1ebcb95f432606d998b386592f4cdc94775d86ea2faa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02e7fa5d900dd3e9afa138aedb2f257fd7b2d16dae4fbf8373981ddab290c63d2854e555921c0b06894c679f5cf2bf15b68df2c3a69daba037624ee9868a9b00
|
7
|
+
data.tar.gz: bc1c3e7c2cfc5db09cdb805463602c450785a0b9d283044ad77a3921ba40004c2c7a7c7b4f851e739a47f09faa3a4359c30143cf41dd02d5634d334c0db509d1
|
@@ -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
|
|
@@ -5,27 +5,18 @@ module Consumer
|
|
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
14
|
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
|
@@ -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,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,10 +6,9 @@ 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
|
|
@@ -22,114 +21,44 @@ module Consumer
|
|
22
21
|
logger.info(tag: :*) { "Correlation: #{correlation}" }
|
23
22
|
end
|
24
23
|
|
25
|
-
unless
|
26
|
-
logger.info(tag: :*) { "Group
|
24
|
+
unless group_member.nil? && group_size.nil?
|
25
|
+
logger.info(tag: :*) { "Group Member: #{group_member.inspect}, Group Size: #{group_size.inspect}" }
|
27
26
|
end
|
28
27
|
|
29
28
|
unless condition.nil?
|
30
29
|
logger.info(tag: :*) { "Condition: #{condition}" }
|
31
30
|
end
|
32
|
-
|
33
|
-
unless composed_condition.nil?
|
34
|
-
logger.debug(tag: :*) { "Composed Condition: #{composed_condition}" }
|
35
|
-
end
|
36
31
|
end
|
37
32
|
|
38
|
-
def configure(batch_size: nil, settings: nil, correlation: nil,
|
39
|
-
composed_condition = Condition.compose(correlation: correlation, group_size: group_size, group_member: group_member, condition: condition)
|
40
|
-
|
33
|
+
def configure(batch_size: nil, settings: nil, correlation: nil, group_member: nil, group_size: nil, condition: nil)
|
41
34
|
self.batch_size = batch_size
|
42
35
|
self.correlation = correlation
|
43
|
-
self.group_size = group_size
|
44
36
|
self.group_member = group_member
|
37
|
+
self.group_size = group_size
|
45
38
|
self.condition = condition
|
46
|
-
self.composed_condition = composed_condition
|
47
39
|
|
48
40
|
MessageStore::Postgres::Session.configure(self, settings: settings)
|
49
|
-
|
50
41
|
session = self.session
|
51
42
|
|
52
|
-
PositionStore.configure(
|
53
|
-
self,
|
54
|
-
stream_name,
|
55
|
-
consumer_identifier: identifier,
|
56
|
-
session: session
|
57
|
-
)
|
58
|
-
|
59
43
|
get_session = MessageStore::Postgres::Session.build(settings: settings)
|
60
|
-
|
44
|
+
|
45
|
+
MessageStore::Postgres::Get::Category.configure(
|
61
46
|
self,
|
62
|
-
|
47
|
+
category,
|
63
48
|
batch_size: batch_size,
|
64
|
-
|
49
|
+
correlation: correlation,
|
50
|
+
consumer_group_member: group_member,
|
51
|
+
consumer_group_size: group_size,
|
52
|
+
condition: condition,
|
65
53
|
session: get_session
|
66
54
|
)
|
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
|
-
|
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
55
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
56
|
+
PositionStore.configure(
|
57
|
+
self,
|
58
|
+
category,
|
59
|
+
consumer_identifier: identifier,
|
60
|
+
session: session
|
61
|
+
)
|
133
62
|
end
|
134
63
|
end
|
135
64
|
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.2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10
|
11
|
+
date: 2019-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-consumer
|
@@ -61,13 +61,11 @@ 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
|
@@ -98,6 +96,6 @@ requirements: []
|
|
98
96
|
rubygems_version: 3.0.1
|
99
97
|
signing_key:
|
100
98
|
specification_version: 4
|
101
|
-
summary: Postgres implementation of continuous subscription to a
|
99
|
+
summary: Postgres implementation of continuous subscription to a category and message
|
102
100
|
dispatching to handlers
|
103
101
|
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
|