eventhub-processor2 1.20.0 → 1.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.tool-versions +1 -1
- data/CHANGELOG.md +6 -0
- data/README.md +16 -9
- data/eventhub-processor2.gemspec +1 -0
- data/example/example.rb +21 -0
- data/lib/eventhub/{actor_listener.rb → actor_listener_amqp.rb} +4 -4
- data/lib/eventhub/actor_listener_http.rb +49 -0
- data/lib/eventhub/actor_publisher.rb +1 -1
- data/lib/eventhub/base.rb +2 -1
- data/lib/eventhub/configuration.rb +6 -1
- data/lib/eventhub/processor2.rb +5 -4
- data/lib/eventhub/version.rb +1 -1
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff9077a8af2791cd681fb21b96a3d60d06ba79e6721e721b814dcc1f3d344eb8
|
4
|
+
data.tar.gz: d05e33dfff330eb2523b2050c8d5fa2d299d6f14b320bce4eaa100b53a6a03e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67729c0fa807676e90fb029ac97b08c2144f77b5fa22820736975b67a871dd63dd7a7fbeba2895f239312cb2a39527c25b8c8c501fcca97ba4de71a33d9a756d
|
7
|
+
data.tar.gz: '09cf7cfb606c0b36c5b2e5552ee33fce244d719a4f3b979159a0fceab157e6bc3b3c77dc4c5e89d202835bdc81476c9ebb71d07b904c79e1586941431a879a22'
|
data/.tool-versions
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby 3.3.
|
1
|
+
ruby 3.3.1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,8 @@ Processor2 has currently the following sub-components implemented
|
|
11
11
|
* Heartbeater - send hearbeats to EventHub dispatcher every x minutes
|
12
12
|
* Publisher - responsible for message publishing
|
13
13
|
* Watchdog - Checks regularly broker connection and defined listener queue(s)
|
14
|
-
* Listener - Listens to defined queues, parses recevied message into a EventHub::Message instance and calls handle_message method as defined in derived class.
|
14
|
+
* Listener AMQP - Listens to defined AMQP queues, parses recevied message into a EventHub::Message instance and calls handle_message method as defined in derived class.
|
15
|
+
* Listener HTTP - Provides an http endpoint for health checks (Exp. /svc/{class_name}/heartbeat)
|
15
16
|
|
16
17
|
Processor2 is using Bunny http://rubybunny.info a feature complete RabbitMQ Client to interact with message broker. Processor2 can deal with long running message processing.
|
17
18
|
|
@@ -31,7 +32,7 @@ Currently supported and tested ruby versions are:
|
|
31
32
|
Add this line to your application's Gemfile:
|
32
33
|
|
33
34
|
```ruby
|
34
|
-
gem
|
35
|
+
gem "eventhub-processor2"
|
35
36
|
```
|
36
37
|
|
37
38
|
And then execute:
|
@@ -52,7 +53,7 @@ module EventHub
|
|
52
53
|
class Example < Processor2
|
53
54
|
|
54
55
|
def version
|
55
|
-
|
56
|
+
"1.0.0" # define your version
|
56
57
|
end
|
57
58
|
|
58
59
|
def handle_message(message, args = {})
|
@@ -73,8 +74,8 @@ module EventHub
|
|
73
74
|
|
74
75
|
# it is possible to publish a message during message processing but it's a
|
75
76
|
# good style to return one or multiple messages at end of handle_message
|
76
|
-
publish(message:
|
77
|
-
publish(message:
|
77
|
+
publish(message: "your message as a string") # default exchange_name is 'event_hub.inbound'
|
78
|
+
publish(message: "your message as string", exchange_name: "your_specfic_exchange")
|
78
79
|
|
79
80
|
# at the end return one of
|
80
81
|
message_to_return = message.copy # return message if sucessfull processing
|
@@ -132,7 +133,12 @@ If --config option is not provided processor tries to load config/{class_name}.j
|
|
132
133
|
"tls_key": null,
|
133
134
|
"tls_ca_certificates": [],
|
134
135
|
"verify_peer": false,
|
135
|
-
"show_bunny_logs": false
|
136
|
+
"show_bunny_logs": false,
|
137
|
+
"heartbeat": {
|
138
|
+
"bind_address": "localhost",
|
139
|
+
"port": 8080,
|
140
|
+
"path": "/svc/{class_name}/heartbeat"
|
141
|
+
}
|
136
142
|
},
|
137
143
|
"processor": {
|
138
144
|
"listener_queues": [
|
@@ -145,6 +151,7 @@ If --config option is not provided processor tries to load config/{class_name}.j
|
|
145
151
|
}
|
146
152
|
}
|
147
153
|
```
|
154
|
+
Default configuration will dynamically resolve {class_name}. Exp. if your class is called MyClass and is derived from Processor2, value of {class_name} would be "my_class". You can overwrite config settings as needed.
|
148
155
|
|
149
156
|
More details about TLS configuration for underlying Bunny gem can be found here: http://rubybunny.info/articles/tls.html.
|
150
157
|
|
@@ -177,9 +184,9 @@ Processor2 symbolizes keys and sub-keys from configuration files automatically.
|
|
177
184
|
|
178
185
|
# If you need strings instead of symbols you can do
|
179
186
|
database = stringify_keys(EventHub::Configuration.database)
|
180
|
-
database[
|
181
|
-
database[
|
182
|
-
database[
|
187
|
+
database["user"] # => "guest"
|
188
|
+
database["password"] # => "secret"
|
189
|
+
database["name"]["subname"] # => "value"
|
183
190
|
```
|
184
191
|
|
185
192
|
Version 1.17 and newer allows you to load and merge more configuration files programmatically. It is expected that load! is called once (implicit during class initialization) and then load_more! zero, one, or multiple times. All additional files loaded with load_more! are hash deep merged into one configuration structure. Exceptions while loading of files will be catched and shown as warnings.
|
data/eventhub-processor2.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
25
|
spec.add_dependency "celluloid", "~> 0.18"
|
26
|
+
spec.add_dependency "webrick", "~> 1.8"
|
26
27
|
spec.add_dependency "bunny", "~> 2.20"
|
27
28
|
spec.add_dependency "eventhub-components", "~> 0.2"
|
28
29
|
spec.add_dependency "uuidtools", "~> 2.1"
|
data/example/example.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "../lib/eventhub/base"
|
2
|
+
|
3
|
+
module EventHub
|
4
|
+
class Example < Processor2
|
5
|
+
def version
|
6
|
+
"1.0.0" # define your version
|
7
|
+
end
|
8
|
+
|
9
|
+
def handle_message(message, args = {})
|
10
|
+
# deal with your parsed EventHub message
|
11
|
+
# message.class => EventHub::Message
|
12
|
+
puts message.process_name # or whatever you need to do
|
13
|
+
|
14
|
+
# or if there is no message to return to event_hub.inbound queue
|
15
|
+
nil # [] works as well
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# start your processor instance
|
21
|
+
EventHub::Example.new.start
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# EventHub module
|
2
2
|
module EventHub
|
3
3
|
# Listner Class
|
4
|
-
class
|
4
|
+
class ActorListenerAmqp
|
5
5
|
include Celluloid
|
6
6
|
include Helper
|
7
7
|
finalizer :cleanup
|
@@ -15,14 +15,14 @@ module EventHub
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def start
|
18
|
-
EventHub.logger.info("Listener is starting...")
|
18
|
+
EventHub.logger.info("Listener amqp is starting...")
|
19
19
|
EventHub::Configuration.processor[:listener_queues].each_with_index do |queue_name, index|
|
20
20
|
async.listen(queue_name: queue_name, index: index)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
def restart
|
25
|
-
raise "Listener is restarting..."
|
25
|
+
raise "Listener amqp is restarting..."
|
26
26
|
end
|
27
27
|
|
28
28
|
def listen(args = {})
|
@@ -109,7 +109,7 @@ module EventHub
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def cleanup
|
112
|
-
EventHub.logger.info("Listener is cleaning up...")
|
112
|
+
EventHub.logger.info("Listener amqp is cleaning up...")
|
113
113
|
# close all open connections
|
114
114
|
return unless @connections
|
115
115
|
@connections.values.each do |connection|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "webrick"
|
2
|
+
|
3
|
+
# EventHub module
|
4
|
+
module EventHub
|
5
|
+
# Listner Class
|
6
|
+
class ActorListenerHttp
|
7
|
+
include Celluloid
|
8
|
+
finalizer :cleanup
|
9
|
+
|
10
|
+
def initialize(args = {})
|
11
|
+
@host = args[:bind_address] || EventHub::Configuration.server.dig(:heartbeat, :bind_address)
|
12
|
+
@port = args[:port] || EventHub::Configuration.server.dig(:heartbeat, :port)
|
13
|
+
@path = args[:path] || EventHub::Configuration.server.dig(:heartbeat, :path)
|
14
|
+
start
|
15
|
+
end
|
16
|
+
|
17
|
+
def start
|
18
|
+
EventHub.logger.info("Listener http is starting [#{@host}, #{@port}], #{@path}...")
|
19
|
+
@async_server = Thread.new do
|
20
|
+
@server = WEBrick::HTTPServer.new(
|
21
|
+
BindAddress: @host,
|
22
|
+
Port: @port,
|
23
|
+
Logger: WEBrick::Log.new("/dev/null"),
|
24
|
+
AccessLog: []
|
25
|
+
)
|
26
|
+
@server.mount_proc @path do |req, res|
|
27
|
+
handle_request(req, res)
|
28
|
+
end
|
29
|
+
@server.start
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def handle_request(req, res)
|
34
|
+
case req.request_method
|
35
|
+
when "GET"
|
36
|
+
res.status = 200
|
37
|
+
res.body = "OK"
|
38
|
+
else
|
39
|
+
res.status = 405
|
40
|
+
res.body = "Method Not Allowed"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def cleanup
|
45
|
+
EventHub.logger.info("Listener http is cleaning up...")
|
46
|
+
@async_server&.kill
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/eventhub/base.rb
CHANGED
@@ -22,7 +22,8 @@ require_relative "consumer"
|
|
22
22
|
require_relative "actor_heartbeat"
|
23
23
|
require_relative "actor_watchdog"
|
24
24
|
require_relative "actor_publisher"
|
25
|
-
require_relative "
|
25
|
+
require_relative "actor_listener_amqp"
|
26
|
+
require_relative "actor_listener_http"
|
26
27
|
require_relative "processor2"
|
27
28
|
|
28
29
|
Celluloid.logger = nil
|
@@ -136,7 +136,12 @@ module EventHub
|
|
136
136
|
tls_key: nil,
|
137
137
|
tls_ca_certificates: [],
|
138
138
|
verify_peer: false,
|
139
|
-
show_bunny_logs: false
|
139
|
+
show_bunny_logs: false,
|
140
|
+
heartbeat: {
|
141
|
+
bind_address: "localhost",
|
142
|
+
port: 8080,
|
143
|
+
path: "/svc/#{@name}/heartbeat"
|
144
|
+
}
|
140
145
|
},
|
141
146
|
processor: {
|
142
147
|
heartbeat_cycle_in_s: 300,
|
data/lib/eventhub/processor2.rb
CHANGED
@@ -60,7 +60,7 @@ module EventHub
|
|
60
60
|
# pass message as string like: '{ "header": ... , "body": { .. }}'
|
61
61
|
# and optionally exchange_name: 'your exchange name'
|
62
62
|
def publish(args = {})
|
63
|
-
Celluloid::Actor[:
|
63
|
+
Celluloid::Actor[:actor_listener_amqp].publish(args)
|
64
64
|
rescue => error
|
65
65
|
EventHub.logger.error("Unexpected exeption while publish: #{error}")
|
66
66
|
raise
|
@@ -87,7 +87,8 @@ module EventHub
|
|
87
87
|
def start_supervisor
|
88
88
|
@config = Celluloid::Supervision::Configuration.define([
|
89
89
|
{type: ActorHeartbeat, as: :actor_heartbeat, args: [self]},
|
90
|
-
{type:
|
90
|
+
{type: ActorListenerAmqp, as: :actor_listener_amqp, args: [self]},
|
91
|
+
{type: ActorListenerHttp, as: :actor_listener_http, args: []}
|
91
92
|
])
|
92
93
|
|
93
94
|
sleeper = @sleeper
|
@@ -116,8 +117,8 @@ module EventHub
|
|
116
117
|
EventHub.logger.info("Configuration file reloaded")
|
117
118
|
|
118
119
|
# restart listener when actor is known
|
119
|
-
if Celluloid::Actor[:
|
120
|
-
Celluloid::Actor[:
|
120
|
+
if Celluloid::Actor[:actor_listener_amqp]
|
121
|
+
Celluloid::Actor[:actor_listener_amqp].async.restart
|
121
122
|
else
|
122
123
|
EventHub.logger.info("Was unable to get a valid listener actor to restart... check!!!")
|
123
124
|
end
|
data/lib/eventhub/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventhub-processor2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steiner, Thomas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.18'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: webrick
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bunny
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -181,11 +195,13 @@ files:
|
|
181
195
|
- example/config/receiver.json
|
182
196
|
- example/config/router.json
|
183
197
|
- example/crasher.rb
|
198
|
+
- example/example.rb
|
184
199
|
- example/publisher.rb
|
185
200
|
- example/receiver.rb
|
186
201
|
- example/router.rb
|
187
202
|
- lib/eventhub/actor_heartbeat.rb
|
188
|
-
- lib/eventhub/
|
203
|
+
- lib/eventhub/actor_listener_amqp.rb
|
204
|
+
- lib/eventhub/actor_listener_http.rb
|
189
205
|
- lib/eventhub/actor_publisher.rb
|
190
206
|
- lib/eventhub/actor_watchdog.rb
|
191
207
|
- lib/eventhub/base.rb
|
@@ -220,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
236
|
- !ruby/object:Gem::Version
|
221
237
|
version: '0'
|
222
238
|
requirements: []
|
223
|
-
rubygems_version: 3.5.
|
239
|
+
rubygems_version: 3.5.9
|
224
240
|
signing_key:
|
225
241
|
specification_version: 4
|
226
242
|
summary: Next generation gem to build ruby based eventhub processor
|