eventhub-processor2 1.20.0 → 1.21.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81ac3772f42a5064c4adec4b688a3c67be1c77cdc687dad104fcd818da41fd22
4
- data.tar.gz: 197ccdbe4e559c6f5111b4c085159a48af4bc741f4f3e0003d28e3b78bd30f61
3
+ metadata.gz: d710f5c1be16b00186cdea6a07087583ac41315454da81e707812be328fd4bd5
4
+ data.tar.gz: edc2b06c90031d9caddefaa6f13ac90724c9065a6229f169221ebb362d289b4e
5
5
  SHA512:
6
- metadata.gz: 230c1ae1e50dcead275b6394b0cd3817ad412dead817d0efd3337199444cdb8ed8f5648035f30b29cbd3c575f5aaa2281fbe3d2c8b050d6dded187713b8987d5
7
- data.tar.gz: 7993add1980e3b8dc57be6eb9b86b0048fe43dd64abca332fbe048d7fe065bf07974ea8284cf9b04ac05db5932a9aea19da2bb72a04536cfc131b89f33242883
6
+ metadata.gz: 2db6c73d157b0b54e4a94257f13e444e392c10f36fdd65b76004fe5293da686d35fe93cb71bc2d8873b7bea1c0ae572a6d6e4aa5e443cdac92add6edc83b4b5e
7
+ data.tar.gz: 96e0f041c7076c9f712bfc15c4ccc818785012ea57818bc10116134579b44577a8df17c9c975c6b7a7443be04870fb3f4457d14b2e896528797e7f656f015a31
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.3.0
1
+ ruby 3.3.1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog of EventHub::Processor2
2
2
 
3
+ ## 1.21.1 / 2024-05-28
4
+
5
+ * Update dependencies
6
+ * Support Ruby 3.3.1
7
+ * Has http endpoint for health checks
8
+
3
9
  ## 1.20.0 / 2023-12-28
4
10
 
5
11
  * Update dependencies
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 'eventhub-processor2'
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
- '1.0.0' # define your version
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: 'your message as a string') # default exchange_name is 'event_hub.inbound'
77
- publish(message: 'your message as string', exchange_name: 'your_specfic_exchange')
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['user'] # => "guest"
181
- database['password'] # => "secret"
182
- database['name']['subname'] # => "value"
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.
@@ -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"
@@ -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 ActorListener
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
@@ -1,6 +1,6 @@
1
1
  # EventHub module
2
2
  module EventHub
3
- # Heartbeat class
3
+ # Publisher class
4
4
  class ActorPublisher
5
5
  include Celluloid
6
6
  include Helper
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 "actor_listener"
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,
@@ -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[:actor_listener].publish(args)
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: ActorListener, as: :actor_listener, args: [self]}
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[:actor_listener]
120
- Celluloid::Actor[:actor_listener].async.restart
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
@@ -1,3 +1,3 @@
1
1
  module EventHub
2
- VERSION = "1.20.0".freeze
2
+ VERSION = "1.21.1".freeze
3
3
  end
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.20.0
4
+ version: 1.21.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steiner, Thomas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-28 00:00:00.000000000 Z
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/actor_listener.rb
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.3
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