evt-consumer-postgres 1.0.1.0 → 1.0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/consumer/postgres/controls/condition.rb +6 -0
- data/lib/consumer/postgres/postgres.rb +46 -6
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c6bbee96c4b1ea1137efe3557dd3392c04b6c3389f87b66d67235a22eedb358
|
4
|
+
data.tar.gz: c93756676d9dadcfaa6311ebde4e58bd3343872b49baefaa4804d45f693af754
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc8bbb6fcd8befb11a287ed88f48e0da55fea427e11003f3321ee69bf2c49902f6f4372cd8026a993705a11a03096abcaa1ca61d180ca95d0f10e349965c8bce
|
7
|
+
data.tar.gz: 31d603dead6e7c0dbac11be9040566d3bc5415a2c9bf7d11893ca889d37a488e5f29c2c8664c636bd1684b5e17fdf278f09f3cd73c3cac1b8b12422449dec5f6
|
@@ -5,8 +5,10 @@ module Consumer
|
|
5
5
|
include ::Consumer
|
6
6
|
|
7
7
|
attr_accessor :batch_size
|
8
|
-
attr_accessor :condition
|
9
8
|
attr_accessor :correlation
|
9
|
+
attr_accessor :group_size
|
10
|
+
attr_accessor :group_member
|
11
|
+
attr_accessor :condition
|
10
12
|
attr_accessor :composed_condition
|
11
13
|
end
|
12
14
|
end
|
@@ -20,8 +22,12 @@ module Consumer
|
|
20
22
|
logger.info(tag: :*) { "Correlation: #{correlation}" }
|
21
23
|
end
|
22
24
|
|
25
|
+
unless group_size.nil? && group_member.nil?
|
26
|
+
logger.info(tag: :*) { "Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect}" }
|
27
|
+
end
|
28
|
+
|
23
29
|
unless condition.nil?
|
24
|
-
logger.info(tag: :*) { "Condition: #{
|
30
|
+
logger.info(tag: :*) { "Condition: #{condition}" }
|
25
31
|
end
|
26
32
|
|
27
33
|
unless composed_condition.nil?
|
@@ -29,11 +35,13 @@ module Consumer
|
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
32
|
-
def configure(batch_size: nil, settings: nil, correlation: nil, condition: nil)
|
33
|
-
composed_condition = Condition.compose(correlation: correlation, condition: condition)
|
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)
|
34
40
|
|
35
41
|
self.batch_size = batch_size
|
36
42
|
self.correlation = correlation
|
43
|
+
self.group_size = group_size
|
44
|
+
self.group_member = group_member
|
37
45
|
self.condition = condition
|
38
46
|
self.composed_condition = composed_condition
|
39
47
|
|
@@ -60,7 +68,7 @@ module Consumer
|
|
60
68
|
module Condition
|
61
69
|
extend self
|
62
70
|
|
63
|
-
def compose(condition: nil, correlation: nil)
|
71
|
+
def compose(condition: nil, correlation: nil, group_size: nil, group_member: nil)
|
64
72
|
composed_condition = []
|
65
73
|
|
66
74
|
unless condition.nil?
|
@@ -69,10 +77,14 @@ module Consumer
|
|
69
77
|
|
70
78
|
unless correlation.nil?
|
71
79
|
Correlation.assure(correlation)
|
72
|
-
|
73
80
|
composed_condition << "metadata->>'correlationStreamName' like '#{correlation}-%'"
|
74
81
|
end
|
75
82
|
|
83
|
+
unless group_size.nil? && group_member.nil?
|
84
|
+
Group.assure(group_size, group_member)
|
85
|
+
composed_condition << "@hash_64(stream_name) % #{group_size} = #{group_member}"
|
86
|
+
end
|
87
|
+
|
76
88
|
return nil if composed_condition.empty?
|
77
89
|
|
78
90
|
sql_condition = composed_condition.join(' AND ')
|
@@ -90,5 +102,33 @@ module Consumer
|
|
90
102
|
end
|
91
103
|
end
|
92
104
|
end
|
105
|
+
|
106
|
+
module Group
|
107
|
+
Error = Class.new(RuntimeError)
|
108
|
+
|
109
|
+
def self.assure(group_size, group_member)
|
110
|
+
error_message = 'Consumer group definition is incorrect.'
|
111
|
+
|
112
|
+
arguments_count = [group_size, group_member].compact.length
|
113
|
+
|
114
|
+
if arguments_count == 1
|
115
|
+
raise Error, "#{error_message} Group size and group member are both required. (Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect})"
|
116
|
+
end
|
117
|
+
|
118
|
+
return if arguments_count == 0
|
119
|
+
|
120
|
+
if group_size < 1
|
121
|
+
raise Error, "#{error_message} Group size must not be less than 1. (Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect})"
|
122
|
+
end
|
123
|
+
|
124
|
+
if group_member < 0
|
125
|
+
raise Error, "#{error_message} Group member must not be less than 0. (Group Size: #{group_size.inspect}, Group Member: #{group_member.inspect})"
|
126
|
+
end
|
127
|
+
|
128
|
+
if group_member >= group_size
|
129
|
+
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})"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
93
133
|
end
|
94
134
|
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.0.
|
4
|
+
version: 1.0.2.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:
|
11
|
+
date: 2019-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-consumer
|
@@ -95,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
|
-
|
99
|
-
rubygems_version: 2.7.3
|
98
|
+
rubygems_version: 3.0.1
|
100
99
|
signing_key:
|
101
100
|
specification_version: 4
|
102
101
|
summary: Postgres implementation of continuous subscription to a stream and message
|