eventhub-processor2 1.19.0 → 1.21.0

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: '052794836cc75c8908c03f61cc5381717d5ed76985f7d3c949fa9dbe7d55b32f'
4
- data.tar.gz: b92271dc527b40b66b6005b7a0547c77b224b0e90be973ccadaa57705ab6789a
3
+ metadata.gz: ff9077a8af2791cd681fb21b96a3d60d06ba79e6721e721b814dcc1f3d344eb8
4
+ data.tar.gz: d05e33dfff330eb2523b2050c8d5fa2d299d6f14b320bce4eaa100b53a6a03e2
5
5
  SHA512:
6
- metadata.gz: 0d9aec7ca4a1f60f33ea8d07307d262e9999bedc5c285bb7369dc3667be2916e8e73b9597ab72a65837bf6a7a7de8c107e1a7f365cc17ae064f4f2e3453bf6f5
7
- data.tar.gz: ff0a4e5bb9a261838913fbd6265ac796901ed23285e9f0c3e167082a8eb1f16e457b79aaad697d97acf4293690ccad2e50d4da93ff411a13a25f730360c4cfbf
6
+ metadata.gz: 67729c0fa807676e90fb029ac97b08c2144f77b5fa22820736975b67a871dd63dd7a7fbeba2895f239312cb2a39527c25b8c8c501fcca97ba4de71a33d9a756d
7
+ data.tar.gz: '09cf7cfb606c0b36c5b2e5552ee33fce244d719a4f3b979159a0fceab157e6bc3b3c77dc4c5e89d202835bdc81476c9ebb71d07b904c79e1586941431a879a22'
@@ -5,7 +5,7 @@ updates:
5
5
  schedule:
6
6
  interval: "weekly"
7
7
  day: "saturday"
8
- time: "04:00"
8
+ time: "04:05"
9
9
  timezone: "Europe/Zurich"
10
10
 
11
11
  - package-ecosystem: "github-actions"
@@ -13,5 +13,5 @@ updates:
13
13
  schedule:
14
14
  interval: "weekly"
15
15
  day: "saturday"
16
- time: "04:00"
16
+ time: "04:05"
17
17
  timezone: "Europe/Zurich"
@@ -10,12 +10,12 @@ jobs:
10
10
 
11
11
  steps:
12
12
  - name: Checkout current code
13
- uses: actions/checkout@v3
13
+ uses: actions/checkout@v4
14
14
 
15
15
  - name: Set up Ruby
16
16
  uses: ruby/setup-ruby@v1
17
17
  with:
18
- ruby-version: '3.1'
18
+ ruby-version: '3.3'
19
19
  bundler-cache: true
20
20
  cache-version: 1
21
21
 
@@ -10,7 +10,7 @@ on:
10
10
  - "*"
11
11
 
12
12
  schedule:
13
- - cron: 0 2 * * 1,3,5,6
13
+ - cron: 0 2 * * 3,6
14
14
 
15
15
  # Allows you to run this workflow manually from the Actions tab
16
16
  workflow_dispatch:
@@ -23,11 +23,11 @@ jobs:
23
23
  strategy:
24
24
  fail-fast: false
25
25
  matrix:
26
- ruby: [ '3.2', '3.1', '3.0', '2.7', '2.6']
26
+ ruby: [ '3.3', '3.2', '3.1', '3.0', '2.7', '2.6']
27
27
 
28
28
  name: Ruby ${{ matrix.ruby }}
29
29
  steps:
30
- - uses: actions/checkout@v3
30
+ - uses: actions/checkout@v4
31
31
 
32
32
  - name: Set up Ruby
33
33
  uses: ruby/setup-ruby@v1
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.2.2
1
+ ruby 3.3.1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog of EventHub::Processor2
2
2
 
3
+ ## 1.21.0 / 2024-05-28
4
+
5
+ * Update dependencies
6
+ * Support Ruby 3.3.1
7
+ * Has http endpoint for health checks
8
+
9
+ ## 1.20.0 / 2023-12-28
10
+
11
+ * Update dependencies
12
+ * Support Ruby 3.3.0
13
+ * Have a console log only option
14
+
3
15
  ## 1.19.0 / 2023-04-23
4
16
 
5
17
  * 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
 
@@ -19,6 +20,7 @@ Processor2 is using Bunny http://rubybunny.info a feature complete RabbitMQ Clie
19
20
 
20
21
  Currently supported and tested ruby versions are:
21
22
 
23
+ - 3.3
22
24
  - 3.2
23
25
  - 3.1
24
26
  - 3.0
@@ -30,7 +32,7 @@ Currently supported and tested ruby versions are:
30
32
  Add this line to your application's Gemfile:
31
33
 
32
34
  ```ruby
33
- gem 'eventhub-processor2'
35
+ gem "eventhub-processor2"
34
36
  ```
35
37
 
36
38
  And then execute:
@@ -51,7 +53,7 @@ module EventHub
51
53
  class Example < Processor2
52
54
 
53
55
  def version
54
- '1.0.0' # define your version
56
+ "1.0.0" # define your version
55
57
  end
56
58
 
57
59
  def handle_message(message, args = {})
@@ -72,8 +74,8 @@ module EventHub
72
74
 
73
75
  # it is possible to publish a message during message processing but it's a
74
76
  # good style to return one or multiple messages at end of handle_message
75
- publish(message: 'your message as a string') # default exchange_name is 'event_hub.inbound'
76
- 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")
77
79
 
78
80
  # at the end return one of
79
81
  message_to_return = message.copy # return message if sucessfull processing
@@ -101,7 +103,7 @@ Usage: example [options]
101
103
  -e, --environment ENVIRONMENT Define environment (default development)
102
104
  -d, --detached Run processor detached as a daemon
103
105
  -c, --config CONFIG Define configuration file
104
-
106
+ --console-log-only Logs to console only (E.g. containers)
105
107
 
106
108
  bundle exec ruby example.rb
107
109
  I, [2018-02-09T15:22:35.649646 #37966] INFO -- : example (1.1.0): has been started
@@ -131,7 +133,12 @@ If --config option is not provided processor tries to load config/{class_name}.j
131
133
  "tls_key": null,
132
134
  "tls_ca_certificates": [],
133
135
  "verify_peer": false,
134
- "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
+ }
135
142
  },
136
143
  "processor": {
137
144
  "listener_queues": [
@@ -144,6 +151,7 @@ If --config option is not provided processor tries to load config/{class_name}.j
144
151
  }
145
152
  }
146
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.
147
155
 
148
156
  More details about TLS configuration for underlying Bunny gem can be found here: http://rubybunny.info/articles/tls.html.
149
157
 
@@ -176,9 +184,9 @@ Processor2 symbolizes keys and sub-keys from configuration files automatically.
176
184
 
177
185
  # If you need strings instead of symbols you can do
178
186
  database = stringify_keys(EventHub::Configuration.database)
179
- database['user'] # => "guest"
180
- database['password'] # => "secret"
181
- database['name']['subname'] # => "value"
187
+ database["user"] # => "guest"
188
+ database["password"] # => "secret"
189
+ database["name"]["subname"] # => "value"
182
190
  ```
183
191
 
184
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,9 +23,11 @@ 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"
30
+ spec.add_dependency "base64", "~> 0.2.0"
29
31
 
30
32
  spec.add_development_dependency "bundler", "~> 2.3"
31
33
  spec.add_development_dependency "rake", "~> 13.0"
@@ -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
@@ -10,6 +10,7 @@ module EventHub
10
10
  attr_reader :environment # environment the processor is running
11
11
  attr_reader :detached # run processor run as a daemon
12
12
  attr_reader :config_file # name of configuration file
13
+ attr_reader :console_log_only # only log to console
13
14
  attr_reader :config_data # data from configuration file
14
15
 
15
16
  @name = "undefined"
@@ -29,6 +30,7 @@ module EventHub
29
30
  @detached = false
30
31
  @config_file = File.join(Dir.getwd, "config", "#{@name}.json")
31
32
  @config_data = {}
33
+ @console_log_only = false
32
34
  end
33
35
 
34
36
  # parse options from argument list
@@ -45,6 +47,10 @@ module EventHub
45
47
  @detached = true
46
48
  end
47
49
 
50
+ opts.on(nil, "--console-log-only", "Only log to console (containers)") do
51
+ @console_log_only = true
52
+ end
53
+
48
54
  note = "Define configuration file"
49
55
  opts.on("-c", "--config CONFIG", note) do |config|
50
56
  @config_file = config
@@ -130,7 +136,12 @@ module EventHub
130
136
  tls_key: nil,
131
137
  tls_ca_certificates: [],
132
138
  verify_peer: false,
133
- show_bunny_logs: false
139
+ show_bunny_logs: false,
140
+ heartbeat: {
141
+ bind_address: "localhost",
142
+ port: 8080,
143
+ path: "/svc/#{@name}/heartbeat"
144
+ }
134
145
  },
135
146
  processor: {
136
147
  heartbeat_cycle_in_s: 300,
@@ -4,10 +4,13 @@ module EventHub
4
4
  unless defined?(@logger)
5
5
  @logger = ::EventHub::Components::MultiLogger.new
6
6
  @logger.add_device(Logger.new($stdout))
7
- @logger.add_device(
8
- EventHub::Components::Logger.logstash(Configuration.name,
9
- Configuration.environment)
10
- )
7
+
8
+ unless Configuration.console_log_only
9
+ @logger.add_device(
10
+ EventHub::Components::Logger.logstash(Configuration.name,
11
+ Configuration.environment)
12
+ )
13
+ end
11
14
  end
12
15
  @logger
13
16
  end
@@ -32,7 +32,7 @@ module EventHub
32
32
  self.header.get(header)
33
33
  end
34
34
 
35
- define_method("#{name}=") do |value|
35
+ define_method(:"#{name}=") do |value|
36
36
  self.header.set(header, value)
37
37
  end
38
38
  end
@@ -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.19.0".freeze
2
+ VERSION = "1.21.0".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.19.0
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: 2023-04-23 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
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '2.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: base64
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.0
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: bundler
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -167,11 +195,13 @@ files:
167
195
  - example/config/receiver.json
168
196
  - example/config/router.json
169
197
  - example/crasher.rb
198
+ - example/example.rb
170
199
  - example/publisher.rb
171
200
  - example/receiver.rb
172
201
  - example/router.rb
173
202
  - lib/eventhub/actor_heartbeat.rb
174
- - lib/eventhub/actor_listener.rb
203
+ - lib/eventhub/actor_listener_amqp.rb
204
+ - lib/eventhub/actor_listener_http.rb
175
205
  - lib/eventhub/actor_publisher.rb
176
206
  - lib/eventhub/actor_watchdog.rb
177
207
  - lib/eventhub/base.rb
@@ -206,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
236
  - !ruby/object:Gem::Version
207
237
  version: '0'
208
238
  requirements: []
209
- rubygems_version: 3.3.26
239
+ rubygems_version: 3.5.9
210
240
  signing_key:
211
241
  specification_version: 4
212
242
  summary: Next generation gem to build ruby based eventhub processor