evt-message_store-postgres 1.0.0.1 → 1.1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/message_store/postgres.rb +3 -2
- data/lib/message_store/postgres/get.rb +50 -35
- data/lib/message_store/postgres/get/category.rb +17 -0
- data/lib/message_store/postgres/get/stream.rb +17 -0
- data/lib/message_store/postgres/get/stream/last.rb +88 -0
- data/lib/message_store/postgres/read.rb +1 -2
- metadata +6 -6
- data/lib/message_store/postgres/get/last.rb +0 -86
- data/lib/message_store/postgres/read/iterator.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08aecf38cd82a29b1b60344994cf41ece2c62b49057db4745314ec5d35f081ee'
|
4
|
+
data.tar.gz: 7de3cec77d52439df435f08a3949c8391dd81675ae31c5f743417db0c7b08a08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9e7dd59611731c9470fac62a26b0da19b1f3166499d100fe4bdeb60710c26fabd2b55bb0e9e845f946ba62268fe26369310aa87f33515f05a6a4df213bde3ab
|
7
|
+
data.tar.gz: c2d38e192e5c469c08a860ad8b187a1377ecd06f3b25e610c979df420330f7a0ac12ee33fc31a3de80173b3564bab7cb49de5f09cdb245e03210daf37ac80ad5
|
@@ -17,6 +17,7 @@ require 'message_store/postgres/put'
|
|
17
17
|
require 'message_store/postgres/write'
|
18
18
|
|
19
19
|
require 'message_store/postgres/get'
|
20
|
-
require 'message_store/postgres/get/
|
21
|
-
require 'message_store/postgres/
|
20
|
+
require 'message_store/postgres/get/stream'
|
21
|
+
require 'message_store/postgres/get/category'
|
22
|
+
require 'message_store/postgres/get/stream/last'
|
22
23
|
require 'message_store/postgres/read'
|
@@ -1,25 +1,37 @@
|
|
1
1
|
module MessageStore
|
2
2
|
module Postgres
|
3
|
-
|
4
|
-
|
3
|
+
module Get
|
4
|
+
def self.included(cls)
|
5
|
+
cls.class_exec do
|
6
|
+
include MessageStore::Get
|
7
|
+
prepend Call
|
8
|
+
prepend BatchSize
|
5
9
|
|
6
|
-
|
10
|
+
extend SQLCommand
|
7
11
|
|
8
|
-
|
12
|
+
dependency :session, Session
|
9
13
|
|
10
|
-
|
11
|
-
|
14
|
+
initializer :stream_name, na(:batch_size), :condition
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module BatchSize
|
19
|
+
def batch_size
|
20
|
+
@batch_size ||= Defaults.batch_size
|
21
|
+
end
|
12
22
|
end
|
13
23
|
|
14
|
-
def self.build(batch_size: nil, session: nil, condition: nil)
|
15
|
-
|
24
|
+
def self.build(stream_name, batch_size: nil, session: nil, condition: nil)
|
25
|
+
cls = specialization(stream_name)
|
26
|
+
|
27
|
+
cls.new(stream_name, batch_size, condition).tap do |instance|
|
16
28
|
instance.configure(session: session)
|
17
29
|
end
|
18
30
|
end
|
19
31
|
|
20
|
-
def self.configure(receiver, attr_name: nil, batch_size: nil, condition: nil, session: nil)
|
32
|
+
def self.configure(receiver, stream_name, attr_name: nil, batch_size: nil, condition: nil, session: nil)
|
21
33
|
attr_name ||= :get
|
22
|
-
instance = build(batch_size: batch_size, condition: condition, session: session)
|
34
|
+
instance = build(stream_name, batch_size: batch_size, condition: condition, session: session)
|
23
35
|
receiver.public_send "#{attr_name}=", instance
|
24
36
|
end
|
25
37
|
|
@@ -28,31 +40,33 @@ module MessageStore
|
|
28
40
|
end
|
29
41
|
|
30
42
|
def self.call(stream_name, position: nil, batch_size: nil, condition: nil, session: nil)
|
31
|
-
instance = build(batch_size: batch_size, condition: condition, session: session)
|
32
|
-
instance.(
|
43
|
+
instance = build(stream_name, batch_size: batch_size, condition: condition, session: session)
|
44
|
+
instance.(position)
|
33
45
|
end
|
34
46
|
|
35
|
-
|
36
|
-
|
47
|
+
module Call
|
48
|
+
def call(position)
|
49
|
+
logger.trace(tag: :get) { "Getting message data (Stream Name: #{stream_name}, Position: #{position.inspect}, Batch Size: #{batch_size.inspect})" }
|
37
50
|
|
38
|
-
|
51
|
+
position ||= Defaults.position
|
39
52
|
|
40
|
-
|
53
|
+
result = get_result(stream_name, position)
|
41
54
|
|
42
|
-
|
55
|
+
message_data = convert(result)
|
43
56
|
|
44
|
-
|
45
|
-
|
57
|
+
logger.info(tag: :get) { "Finished getting message data (Count: #{message_data.length}, Stream Name: #{stream_name}, Position: #{position.inspect}, Batch Size: #{batch_size.inspect})" }
|
58
|
+
logger.info(tags: [:data, :message_data]) { message_data.pretty_inspect }
|
46
59
|
|
47
|
-
|
60
|
+
message_data
|
61
|
+
end
|
48
62
|
end
|
49
63
|
|
50
64
|
def get_result(stream_name, position)
|
51
|
-
logger.trace(tag: :get) { "Getting result (Stream: #{stream_name}, Position: #{position.inspect}, Batch Size: #{batch_size.inspect}, Condition: #{condition || '(none)'})" }
|
65
|
+
logger.trace(tag: :get) { "Getting result (Stream Name: #{stream_name}, Position: #{position.inspect}, Batch Size: #{batch_size.inspect}, Condition: #{condition || '(none)'})" }
|
52
66
|
|
53
67
|
sql_command = self.class.sql_command(stream_name, position, batch_size, condition)
|
54
68
|
|
55
|
-
cond =
|
69
|
+
cond = Get.constrain_condition(condition)
|
56
70
|
|
57
71
|
params = [
|
58
72
|
stream_name,
|
@@ -63,7 +77,7 @@ module MessageStore
|
|
63
77
|
|
64
78
|
result = session.execute(sql_command, params)
|
65
79
|
|
66
|
-
logger.debug(tag: :get) { "Finished getting result (Count: #{result.ntuples}, Stream: #{stream_name}, Position: #{position.inspect}, Batch Size: #{batch_size.inspect}, Condition: #{condition || '(none)'})" }
|
80
|
+
logger.debug(tag: :get) { "Finished getting result (Count: #{result.ntuples}, Stream Name: #{stream_name}, Position: #{position.inspect}, Batch Size: #{batch_size.inspect}, Condition: #{condition || '(none)'})" }
|
67
81
|
|
68
82
|
result
|
69
83
|
end
|
@@ -74,20 +88,13 @@ module MessageStore
|
|
74
88
|
"(#{condition})"
|
75
89
|
end
|
76
90
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
return "SELECT * FROM get_category_messages(#{parameters});"
|
82
|
-
else
|
83
|
-
return "SELECT * FROM get_stream_messages(#{parameters});"
|
91
|
+
module SQLCommand
|
92
|
+
def sql_command(stream_name, position, batch_size, condition)
|
93
|
+
parameters = '$1::varchar, $2::bigint, $3::bigint, $4::varchar'
|
94
|
+
command_text(parameters)
|
84
95
|
end
|
85
96
|
end
|
86
97
|
|
87
|
-
def self.category_stream?(stream_name)
|
88
|
-
StreamName.category?(stream_name)
|
89
|
-
end
|
90
|
-
|
91
98
|
def convert(result)
|
92
99
|
logger.trace(tag: :get) { "Converting result to message data (Result Count: #{result.ntuples})" }
|
93
100
|
|
@@ -96,7 +103,7 @@ module MessageStore
|
|
96
103
|
record['metadata'] = Deserialize.metadata(record['metadata'])
|
97
104
|
record['time'] = Time.utc_coerced(record['time'])
|
98
105
|
|
99
|
-
MessageData::Read.build
|
106
|
+
MessageData::Read.build(record)
|
100
107
|
end
|
101
108
|
|
102
109
|
logger.debug(tag: :get) { "Converted result to message data (Message Data Count: #{message_data.length})" }
|
@@ -104,6 +111,14 @@ module MessageStore
|
|
104
111
|
message_data
|
105
112
|
end
|
106
113
|
|
114
|
+
def self.specialization(stream_name)
|
115
|
+
if StreamName.category?(stream_name)
|
116
|
+
Category
|
117
|
+
else
|
118
|
+
Stream
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
107
122
|
module Deserialize
|
108
123
|
def self.data(serialized_data)
|
109
124
|
return nil if serialized_data.nil?
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MessageStore
|
2
|
+
module Postgres
|
3
|
+
module Get
|
4
|
+
class Category
|
5
|
+
include Get
|
6
|
+
|
7
|
+
def self.command_text(parameters)
|
8
|
+
"SELECT * FROM get_category_messages(#{parameters});"
|
9
|
+
end
|
10
|
+
|
11
|
+
def last_position(batch)
|
12
|
+
batch.last.global_position
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MessageStore
|
2
|
+
module Postgres
|
3
|
+
module Get
|
4
|
+
class Stream
|
5
|
+
include Get
|
6
|
+
|
7
|
+
def self.command_text(parameters)
|
8
|
+
"SELECT * FROM get_stream_messages(#{parameters});"
|
9
|
+
end
|
10
|
+
|
11
|
+
def last_position(batch)
|
12
|
+
batch.last.position
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module MessageStore
|
2
|
+
module Postgres
|
3
|
+
module Get
|
4
|
+
class Stream
|
5
|
+
class Last
|
6
|
+
include MessageStore::Get::Stream::Last
|
7
|
+
|
8
|
+
dependency :session, Session
|
9
|
+
|
10
|
+
def configure(session: nil)
|
11
|
+
Session.configure(self, session: session)
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(stream_name)
|
15
|
+
logger.trace(tag: :get) { "Getting last message data (Stream Name: #{stream_name})" }
|
16
|
+
|
17
|
+
result = get_result(stream_name)
|
18
|
+
|
19
|
+
return nil if result.nil?
|
20
|
+
|
21
|
+
message_data = convert(result[0])
|
22
|
+
|
23
|
+
logger.info(tag: :get) { "Finished getting message data (Stream Name: #{stream_name})" }
|
24
|
+
logger.info(tags: [:data, :message_data]) { message_data.pretty_inspect }
|
25
|
+
|
26
|
+
message_data
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_result(stream_name)
|
30
|
+
logger.trace(tag: :get) { "Getting last record (Stream: #{stream_name})" }
|
31
|
+
|
32
|
+
sql_command = self.class.sql_command(stream_name)
|
33
|
+
|
34
|
+
params = [
|
35
|
+
stream_name
|
36
|
+
]
|
37
|
+
|
38
|
+
result = session.execute(sql_command, params)
|
39
|
+
|
40
|
+
logger.debug(tag: :get) { "Finished getting result (Count: #{result.ntuples}, Stream: #{stream_name}" }
|
41
|
+
|
42
|
+
return nil if result.ntuples == 0
|
43
|
+
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.sql_command(stream_name)
|
48
|
+
parameters = '$1::varchar'
|
49
|
+
|
50
|
+
"SELECT * FROM get_last_message(#{parameters});"
|
51
|
+
end
|
52
|
+
|
53
|
+
def convert(record)
|
54
|
+
logger.trace(tag: :get) { "Converting record to message data" }
|
55
|
+
|
56
|
+
record['data'] = Deserialize.data(record['data'])
|
57
|
+
record['metadata'] = Deserialize.metadata(record['metadata'])
|
58
|
+
record['time'] = Time.utc_coerced(record['time'])
|
59
|
+
|
60
|
+
message_data = MessageData::Read.build(record)
|
61
|
+
|
62
|
+
logger.debug(tag: :get) { "Converted record to message data" }
|
63
|
+
|
64
|
+
message_data
|
65
|
+
end
|
66
|
+
|
67
|
+
module Deserialize
|
68
|
+
def self.data(serialized_data)
|
69
|
+
return nil if serialized_data.nil?
|
70
|
+
Transform::Read.(serialized_data, :json, MessageData::Hash)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.metadata(serialized_metadata)
|
74
|
+
return nil if serialized_metadata.nil?
|
75
|
+
Transform::Read.(serialized_metadata, :json, MessageData::Hash)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
module Time
|
80
|
+
def self.utc_coerced(local_time)
|
81
|
+
Clock::UTC.coerce(local_time)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -4,8 +4,7 @@ module MessageStore
|
|
4
4
|
include MessageStore::Read
|
5
5
|
|
6
6
|
def configure(session: nil, condition: nil)
|
7
|
-
|
8
|
-
Get.configure(self.iterator, batch_size: batch_size, condition: condition, session: session)
|
7
|
+
Get.configure(self.iterator, self.stream_name, batch_size: batch_size, condition: condition, session: session)
|
9
8
|
end
|
10
9
|
|
11
10
|
module Defaults
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-message_store-postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: scripts
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-message_store
|
@@ -136,11 +136,12 @@ files:
|
|
136
136
|
- lib/message_store/postgres/controls/put.rb
|
137
137
|
- lib/message_store/postgres/controls/stream_name.rb
|
138
138
|
- lib/message_store/postgres/get.rb
|
139
|
-
- lib/message_store/postgres/get/
|
139
|
+
- lib/message_store/postgres/get/category.rb
|
140
|
+
- lib/message_store/postgres/get/stream.rb
|
141
|
+
- lib/message_store/postgres/get/stream/last.rb
|
140
142
|
- lib/message_store/postgres/log.rb
|
141
143
|
- lib/message_store/postgres/put.rb
|
142
144
|
- lib/message_store/postgres/read.rb
|
143
|
-
- lib/message_store/postgres/read/iterator.rb
|
144
145
|
- lib/message_store/postgres/session.rb
|
145
146
|
- lib/message_store/postgres/settings.rb
|
146
147
|
- lib/message_store/postgres/stream_name.rb
|
@@ -164,8 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
165
|
- !ruby/object:Gem::Version
|
165
166
|
version: '0'
|
166
167
|
requirements: []
|
167
|
-
|
168
|
-
rubygems_version: 2.7.3
|
168
|
+
rubygems_version: 3.0.1
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Message store implementation for PostgreSQL
|
@@ -1,86 +0,0 @@
|
|
1
|
-
module MessageStore
|
2
|
-
module Postgres
|
3
|
-
class Get
|
4
|
-
class Last
|
5
|
-
include MessageStore::Get::Last
|
6
|
-
|
7
|
-
dependency :session, Session
|
8
|
-
|
9
|
-
def configure(session: nil)
|
10
|
-
Session.configure(self, session: session)
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(stream_name)
|
14
|
-
logger.trace(tag: :get) { "Getting last message data (Stream Name: #{stream_name})" }
|
15
|
-
|
16
|
-
result = get_result(stream_name)
|
17
|
-
|
18
|
-
return nil if result.nil?
|
19
|
-
|
20
|
-
message_data = convert(result[0])
|
21
|
-
|
22
|
-
logger.info(tag: :get) { "Finished getting message data (Stream Name: #{stream_name})" }
|
23
|
-
logger.info(tags: [:data, :message_data]) { message_data.pretty_inspect }
|
24
|
-
|
25
|
-
message_data
|
26
|
-
end
|
27
|
-
|
28
|
-
def get_result(stream_name)
|
29
|
-
logger.trace(tag: :get) { "Getting last record (Stream: #{stream_name})" }
|
30
|
-
|
31
|
-
sql_command = self.class.sql_command(stream_name)
|
32
|
-
|
33
|
-
params = [
|
34
|
-
stream_name
|
35
|
-
]
|
36
|
-
|
37
|
-
result = session.execute(sql_command, params)
|
38
|
-
|
39
|
-
logger.debug(tag: :get) { "Finished getting result (Count: #{result.ntuples}, Stream: #{stream_name}" }
|
40
|
-
|
41
|
-
return nil if result.ntuples == 0
|
42
|
-
|
43
|
-
result
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.sql_command(stream_name)
|
47
|
-
parameters = '$1::varchar'
|
48
|
-
|
49
|
-
"SELECT * FROM get_last_message(#{parameters});"
|
50
|
-
end
|
51
|
-
|
52
|
-
def convert(record)
|
53
|
-
logger.trace(tag: :get) { "Converting record to message data" }
|
54
|
-
|
55
|
-
record['data'] = Deserialize.data(record['data'])
|
56
|
-
record['metadata'] = Deserialize.metadata(record['metadata'])
|
57
|
-
record['time'] = Time.utc_coerced(record['time'])
|
58
|
-
|
59
|
-
message_data = MessageData::Read.build(record)
|
60
|
-
|
61
|
-
logger.debug(tag: :get) { "Converted record to message data" }
|
62
|
-
|
63
|
-
message_data
|
64
|
-
end
|
65
|
-
|
66
|
-
module Deserialize
|
67
|
-
def self.data(serialized_data)
|
68
|
-
return nil if serialized_data.nil?
|
69
|
-
Transform::Read.(serialized_data, :json, MessageData::Hash)
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.metadata(serialized_metadata)
|
73
|
-
return nil if serialized_metadata.nil?
|
74
|
-
Transform::Read.(serialized_metadata, :json, MessageData::Hash)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
module Time
|
79
|
-
def self.utc_coerced(local_time)
|
80
|
-
Clock::UTC.coerce(local_time)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module MessageStore
|
2
|
-
module Postgres
|
3
|
-
class Read
|
4
|
-
class Iterator
|
5
|
-
include MessageStore::Read::Iterator
|
6
|
-
|
7
|
-
def last_position
|
8
|
-
unless MessageStore::Postgres::StreamName.category?(stream_name)
|
9
|
-
batch.last.position
|
10
|
-
else
|
11
|
-
batch.last.global_position
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|