evt-consumer-postgres 1.0.0.0 → 1.0.1.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 +19 -0
- data/lib/consumer/postgres/controls/consumer.rb +0 -13
- data/lib/consumer/postgres/controls/handler.rb +15 -0
- data/lib/consumer/postgres/controls/message.rb +14 -0
- data/lib/consumer/postgres/controls.rb +3 -0
- data/lib/consumer/postgres/postgres.rb +67 -2
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b9e728d8d64095daf2e0e8b4c257a33442d3fee6aa04796cf3261371b4b9c23
|
4
|
+
data.tar.gz: eef0e89380daecf69c95c13b4d47d5c594201fd22c7ab0be021427652ed4ba53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 196daa0e73fce6a1d842db093d6bba4f8811977b313befb7cc8ae67ed68ea7a686335665892db021045a411c9c1cdbaaa55bfa86c3237af84f5039ed482f4db1
|
7
|
+
data.tar.gz: f479fd56d52159824c1e8c7d1bf0528f950ca5ffa37633cdb8a504f73369cbce88705177f4f1a976c2afce25528c7e1e9150a7c121c5f377e53f6c483de60b2b
|
@@ -0,0 +1,19 @@
|
|
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 Ordinary
|
12
|
+
def self.example
|
13
|
+
'some condition'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -4,20 +4,7 @@ module Consumer
|
|
4
4
|
module Consumer
|
5
5
|
class Example
|
6
6
|
include ::Consumer::Postgres
|
7
|
-
end
|
8
|
-
|
9
|
-
class Incrementing
|
10
|
-
include ::Consumer::Postgres
|
11
|
-
|
12
|
-
class Handler
|
13
|
-
include Messaging::Handle
|
14
|
-
include Log::Dependency
|
15
7
|
|
16
|
-
def handle(message_data)
|
17
|
-
logger.info { "Handled message (StreamName: #{message_data.stream_name}, GlobalPosition: #{message_data.global_position})" }
|
18
|
-
logger.debug { message_data.data.pretty_inspect }
|
19
|
-
end
|
20
|
-
end
|
21
8
|
handler Handler
|
22
9
|
end
|
23
10
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Consumer
|
2
|
+
module Postgres
|
3
|
+
module Controls
|
4
|
+
class Handler
|
5
|
+
include Messaging::Handle
|
6
|
+
include Log::Dependency
|
7
|
+
|
8
|
+
def handle(message_data)
|
9
|
+
logger.info "Handled message (StreamName: #{message_data.stream_name}, Correlation Stream Name: #{message_data.metadata[:correlation_stream_name]}, GlobalPosition: #{message_data.global_position})"
|
10
|
+
logger.debug message_data.data.pretty_inspect
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Consumer
|
2
|
+
module Postgres
|
3
|
+
module Controls
|
4
|
+
module Message
|
5
|
+
def self.example(attribute: nil, correlation: nil)
|
6
|
+
message = Messaging::Controls::Message.example(some_attribute: attribute)
|
7
|
+
message.metadata.correlation_stream_name = correlation unless correlation.nil?
|
8
|
+
|
9
|
+
message
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -6,9 +6,12 @@ require 'consumer/postgres/controls/category'
|
|
6
6
|
require 'consumer/postgres/controls/id'
|
7
7
|
require 'consumer/postgres/controls/identifier'
|
8
8
|
require 'consumer/postgres/controls/message_data'
|
9
|
+
require 'consumer/postgres/controls/message'
|
9
10
|
require 'consumer/postgres/controls/position'
|
10
11
|
require 'consumer/postgres/controls/position/store/recorded'
|
11
12
|
require 'consumer/postgres/controls/position/stream/write'
|
12
13
|
require 'consumer/postgres/controls/stream_name'
|
13
14
|
|
15
|
+
require 'consumer/postgres/controls/condition'
|
16
|
+
require 'consumer/postgres/controls/handler'
|
14
17
|
require 'consumer/postgres/controls/consumer'
|
@@ -3,13 +3,44 @@ module Consumer
|
|
3
3
|
def self.included(cls)
|
4
4
|
cls.class_exec do
|
5
5
|
include ::Consumer
|
6
|
+
|
7
|
+
attr_accessor :batch_size
|
8
|
+
attr_accessor :condition
|
9
|
+
attr_accessor :correlation
|
10
|
+
attr_accessor :composed_condition
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def starting
|
15
|
+
unless batch_size.nil?
|
16
|
+
logger.info(tag: :*) { "Batch Size: #{batch_size}" }
|
17
|
+
end
|
18
|
+
|
19
|
+
unless correlation.nil?
|
20
|
+
logger.info(tag: :*) { "Correlation: #{correlation}" }
|
21
|
+
end
|
22
|
+
|
23
|
+
unless condition.nil?
|
24
|
+
logger.info(tag: :*) { "Condition: #{composed_condition}" }
|
25
|
+
end
|
26
|
+
|
27
|
+
unless composed_condition.nil?
|
28
|
+
logger.debug(tag: :*) { "Composed Condition: #{composed_condition}" }
|
6
29
|
end
|
7
30
|
end
|
8
31
|
|
9
|
-
def configure(batch_size: nil, settings: nil, condition: nil)
|
32
|
+
def configure(batch_size: nil, settings: nil, correlation: nil, condition: nil)
|
33
|
+
composed_condition = Condition.compose(correlation: correlation, condition: condition)
|
34
|
+
|
35
|
+
self.batch_size = batch_size
|
36
|
+
self.correlation = correlation
|
37
|
+
self.condition = condition
|
38
|
+
self.composed_condition = composed_condition
|
39
|
+
|
10
40
|
MessageStore::Postgres::Session.configure(self, settings: settings)
|
11
41
|
|
12
42
|
session = self.session
|
43
|
+
|
13
44
|
PositionStore.configure(
|
14
45
|
self,
|
15
46
|
stream_name,
|
@@ -21,9 +52,43 @@ module Consumer
|
|
21
52
|
MessageStore::Postgres::Get.configure(
|
22
53
|
self,
|
23
54
|
batch_size: batch_size,
|
24
|
-
condition:
|
55
|
+
condition: composed_condition,
|
25
56
|
session: get_session
|
26
57
|
)
|
27
58
|
end
|
59
|
+
|
60
|
+
module Condition
|
61
|
+
extend self
|
62
|
+
|
63
|
+
def compose(condition: nil, correlation: nil)
|
64
|
+
composed_condition = []
|
65
|
+
|
66
|
+
unless condition.nil?
|
67
|
+
composed_condition << condition
|
68
|
+
end
|
69
|
+
|
70
|
+
unless correlation.nil?
|
71
|
+
Correlation.assure(correlation)
|
72
|
+
|
73
|
+
composed_condition << "metadata->>'correlationStreamName' like '#{correlation}-%'"
|
74
|
+
end
|
75
|
+
|
76
|
+
return nil if composed_condition.empty?
|
77
|
+
|
78
|
+
sql_condition = composed_condition.join(' AND ')
|
79
|
+
|
80
|
+
sql_condition
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
module Correlation
|
85
|
+
Error = Class.new(RuntimeError)
|
86
|
+
|
87
|
+
def self.assure(correlation)
|
88
|
+
unless MessageStore::StreamName.category?(correlation)
|
89
|
+
raise Correlation::Error, "Correlation must be a category (Correlation: #{correlation})"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
28
93
|
end
|
29
94
|
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.1.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: 2018-
|
11
|
+
date: 2018-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-consumer
|
@@ -61,9 +61,12 @@ 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
|
64
65
|
- lib/consumer/postgres/controls/consumer.rb
|
66
|
+
- lib/consumer/postgres/controls/handler.rb
|
65
67
|
- lib/consumer/postgres/controls/id.rb
|
66
68
|
- lib/consumer/postgres/controls/identifier.rb
|
69
|
+
- lib/consumer/postgres/controls/message.rb
|
67
70
|
- lib/consumer/postgres/controls/message_data.rb
|
68
71
|
- lib/consumer/postgres/controls/position.rb
|
69
72
|
- lib/consumer/postgres/controls/position/store/recorded.rb
|
@@ -93,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
96
|
version: '0'
|
94
97
|
requirements: []
|
95
98
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.7.
|
99
|
+
rubygems_version: 2.7.3
|
97
100
|
signing_key:
|
98
101
|
specification_version: 4
|
99
102
|
summary: Postgres implementation of continuous subscription to a stream and message
|