tdl-client-ruby 0.20.2 → 0.20.4
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/tdl.rb +0 -1
- data/lib/tdl/previous_version.rb +1 -1
- data/lib/tdl/queue/queue_based_implementation_runner.rb +27 -1
- data/lib/tdl/queue/transport/remote_broker.rb +2 -0
- metadata +3 -5
- data/examples/add_numbers.rb +0 -31
- data/lib/tdl/queue/client.rb +0 -112
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa06f4cfebda29d3cc02c23b061f6726e72f0038
|
4
|
+
data.tar.gz: 480a07f019c1bd689dd3a4f5b5b5a3fd5c6c68cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 743ceb9a9eacbd64347094369fa7e710dfb0d2b9ab49dd6f61168acb1e4e18d4c88080d5179de8372fc02a6b80564b889833aeda6b3bc3c15aa2373d418fa45c
|
7
|
+
data.tar.gz: 51fe054e7c3d2100d3d7fe1b5ab2cbb2fd09a55079a6d8833c29344fb210fd5c6a282b89b5e72273a4f0209e24165629c6ba2c9e6527a3fc6cd623411d77152a
|
data/lib/tdl.rb
CHANGED
data/lib/tdl/previous_version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'logging'
|
2
|
-
|
3
2
|
require 'tdl/queue/processing_rules'
|
3
|
+
require 'tdl/queue/transport/remote_broker'
|
4
4
|
|
5
5
|
module TDL
|
6
6
|
class QueueBasedImplementationRunner
|
@@ -73,3 +73,29 @@ module TDL
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
class AuditStream
|
78
|
+
|
79
|
+
def initialize
|
80
|
+
@logger = Logging.logger[self]
|
81
|
+
start_line
|
82
|
+
end
|
83
|
+
|
84
|
+
def start_line
|
85
|
+
@str = ''
|
86
|
+
end
|
87
|
+
|
88
|
+
def log(auditable)
|
89
|
+
text = auditable.audit_text
|
90
|
+
if not text.empty? and @str.length > 0
|
91
|
+
@str << ', '
|
92
|
+
end
|
93
|
+
|
94
|
+
@str << text
|
95
|
+
end
|
96
|
+
|
97
|
+
def end_line
|
98
|
+
@logger.info @str
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tdl-client-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.20.
|
4
|
+
version: 0.20.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Ghionoiu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stomp
|
@@ -210,7 +210,6 @@ files:
|
|
210
210
|
- LICENSE
|
211
211
|
- README.md
|
212
212
|
- Rakefile
|
213
|
-
- examples/add_numbers.rb
|
214
213
|
- lib/tdl.rb
|
215
214
|
- lib/tdl/audit/console_audit_stream.rb
|
216
215
|
- lib/tdl/previous_version.rb
|
@@ -222,7 +221,6 @@ files:
|
|
222
221
|
- lib/tdl/queue/actions/publish_action.rb
|
223
222
|
- lib/tdl/queue/actions/publish_and_stop_action.rb
|
224
223
|
- lib/tdl/queue/actions/stop_action.rb
|
225
|
-
- lib/tdl/queue/client.rb
|
226
224
|
- lib/tdl/queue/implementation_runner_config.rb
|
227
225
|
- lib/tdl/queue/processing_rules.rb
|
228
226
|
- lib/tdl/queue/queue_based_implementation_runner.rb
|
@@ -245,7 +243,7 @@ homepage: https://github.com/julianghionoiu/tdl-client-ruby
|
|
245
243
|
licenses:
|
246
244
|
- GPL-3.0
|
247
245
|
metadata:
|
248
|
-
previous_version: 0.20.
|
246
|
+
previous_version: 0.20.3
|
249
247
|
post_install_message:
|
250
248
|
rdoc_options: []
|
251
249
|
require_paths:
|
data/examples/add_numbers.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'tdl'
|
2
|
-
require 'logging'
|
3
|
-
|
4
|
-
Logging.logger.root.appenders = Logging.appenders.stdout
|
5
|
-
Logging.logger.root.level = :info
|
6
|
-
|
7
|
-
|
8
|
-
def run_client
|
9
|
-
client = TDL::Client.new( hostname: 'localhost', port: 61613, unique_id: 'julian@example.com')
|
10
|
-
include TDL::ClientActions
|
11
|
-
rules = TDL::ProcessingRules.new
|
12
|
-
rules.on('display_description').call(method(:display)).then(publish)
|
13
|
-
rules.on('sum').call(method(:sum)).then(publish)
|
14
|
-
rules.on('end_round').call(lambda { 'OK' }).then(publish_and_stop)
|
15
|
-
|
16
|
-
# puts processing_rules.to_yaml
|
17
|
-
|
18
|
-
client.go_live_with(rules)
|
19
|
-
end
|
20
|
-
|
21
|
-
def display(round, description)
|
22
|
-
puts "#{round} = #{description}"
|
23
|
-
'OK'
|
24
|
-
end
|
25
|
-
|
26
|
-
def sum(x, y)
|
27
|
-
x + y
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
run_client
|
data/lib/tdl/queue/client.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'stomp'
|
2
|
-
require 'logging'
|
3
|
-
|
4
|
-
require 'tdl/queue/transport/remote_broker'
|
5
|
-
require 'tdl/queue/processing_rules'
|
6
|
-
require 'tdl/queue/actions/stop_action'
|
7
|
-
|
8
|
-
require 'tdl/queue/serialization/json_rpc_serialization_provider'
|
9
|
-
|
10
|
-
module TDL
|
11
|
-
|
12
|
-
class Client
|
13
|
-
|
14
|
-
def initialize(hostname:, port: 61613, unique_id:, request_timeout_millis: 500)
|
15
|
-
@hostname = hostname
|
16
|
-
@port = port
|
17
|
-
@unique_id = unique_id
|
18
|
-
@request_timeout_millis = request_timeout_millis
|
19
|
-
@logger = Logging.logger[self]
|
20
|
-
@total_processing_time = nil
|
21
|
-
end
|
22
|
-
|
23
|
-
def get_request_timeout_millis
|
24
|
-
@request_timeout_millis
|
25
|
-
end
|
26
|
-
|
27
|
-
def go_live_with(processing_rules)
|
28
|
-
time1 = Time.now.to_f
|
29
|
-
begin
|
30
|
-
@logger.info 'Starting client.'
|
31
|
-
remote_broker = RemoteBroker.new(@hostname, @port, @unique_id, @request_timeout_millis)
|
32
|
-
remote_broker.subscribe(ApplyProcessingRules.new(processing_rules))
|
33
|
-
@logger.info 'Waiting for requests.'
|
34
|
-
remote_broker.join
|
35
|
-
@logger.info 'Stopping client.'
|
36
|
-
|
37
|
-
rescue Exception => e
|
38
|
-
# raise e if ENV['TDL_ENV'] == 'test'
|
39
|
-
@logger.error "There was a problem processing messages. #{e.message}"
|
40
|
-
@logger.error e.backtrace.join("\n")
|
41
|
-
end
|
42
|
-
time2 = Time.now.to_f
|
43
|
-
@total_processing_time = (time2 - time1) * 1000.00
|
44
|
-
end
|
45
|
-
|
46
|
-
def total_processing_time
|
47
|
-
@total_processing_time
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
#~~~~ Queue handling policies
|
52
|
-
|
53
|
-
class ApplyProcessingRules
|
54
|
-
|
55
|
-
def initialize(processing_rules)
|
56
|
-
@processing_rules = processing_rules
|
57
|
-
@logger = Logging.logger[self]
|
58
|
-
@audit = AuditStream.new
|
59
|
-
end
|
60
|
-
|
61
|
-
def process_next_request_from(remote_broker, request)
|
62
|
-
@audit.start_line
|
63
|
-
@audit.log(request)
|
64
|
-
|
65
|
-
# Obtain response from user
|
66
|
-
response = @processing_rules.get_response_for(request)
|
67
|
-
@audit.log(response)
|
68
|
-
|
69
|
-
# Obtain action
|
70
|
-
client_action = response.client_action
|
71
|
-
|
72
|
-
# Act
|
73
|
-
client_action.after_response(remote_broker, request, response)
|
74
|
-
@audit.log(client_action)
|
75
|
-
@audit.end_line
|
76
|
-
client_action.prepare_for_next_request(remote_broker)
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
# ~~~~ Utils
|
86
|
-
|
87
|
-
class AuditStream
|
88
|
-
|
89
|
-
def initialize
|
90
|
-
@logger = Logging.logger[self]
|
91
|
-
start_line
|
92
|
-
end
|
93
|
-
|
94
|
-
def start_line
|
95
|
-
@str = ''
|
96
|
-
end
|
97
|
-
|
98
|
-
def log(auditable)
|
99
|
-
text = auditable.audit_text
|
100
|
-
if not text.empty? and @str.length > 0
|
101
|
-
@str << ', '
|
102
|
-
end
|
103
|
-
|
104
|
-
@str << text
|
105
|
-
end
|
106
|
-
|
107
|
-
def end_line
|
108
|
-
@logger.info @str
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
end
|