moleculer 0.1.1 → 0.2.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: adca17fdd330fd7afa3d94ffd7768e1b1c732b9a6ff106defd5dcd6b7437f9ab
4
- data.tar.gz: '097cb23699252db25857b462712f18279c4fb712ccb6b5873d846c897ae6447f'
3
+ metadata.gz: b336fe17152d5c0ebff7495c2fc7e5dd6ea4a5aa0a2cd29ee9f2f67f25fbe95f
4
+ data.tar.gz: 1f99f72bae588fa8544cf9635891ed9bc51408ec656658090eeded5756f45be3
5
5
  SHA512:
6
- metadata.gz: 476c7b017f50e95d1bbbba1b3ee933dc9b0168265a2386d250ec74cdba1989839753896f4a55e639e8e783ee2731d44e36cfa7e7f35cd1ca9c40971b176742bc
7
- data.tar.gz: 6c1ab62da8bb22d066adc09507ee3010112eeefc53f85f26d3d3d4c523ef7d0f2ec6909fe7d40b4831b0b5303e12b073357309fda66b09648ac512975e7080a6
6
+ metadata.gz: c9b52239d10c8aca09bae010e5193dfc56ebe3d4df72d8d5f70e497788c7274630951e0bfe1c641f82f57f26bc374772f7ff16d75af4ad093bb13f82b6333987
7
+ data.tar.gz: 90fa10f008f7807bf729e993bd48a2dab8718144477fe5d340373ac74c0151811376f121af63127c543e4f2693b1bc042e3e4641065197b5c40b532b8bf5facd
data/.codeclimate.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ version: "2"
3
+ plugins:
4
+ rubocop:
5
+ enabled: true
6
+ channel: rubocop-0-60 # Minimum version to support ruby 2.6
data/.rubocop.yml CHANGED
@@ -7,7 +7,7 @@ Layout/IndentHash:
7
7
  Layout/IndentationWidth:
8
8
  IgnoredPatterns: []
9
9
 
10
- Style/AlignHash:
10
+ Layout/AlignHash:
11
11
  EnforcedColonStyle: table
12
12
  EnforcedHashRocketStyle: table
13
13
 
@@ -23,6 +23,9 @@ Style/TrailingCommaInHashLiteral:
23
23
  Style/TrailingCommaInArrayLiteral:
24
24
  EnforcedStyleForMultiline: comma
25
25
 
26
+ Style/FrozenStringLiteralComment:
27
+ Enabled: true
28
+
26
29
  Style/StringLiterals:
27
30
  EnforcedStyle: "double_quotes"
28
31
 
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.6.3
data/.travis.yml CHANGED
@@ -8,10 +8,11 @@ rvm:
8
8
  - 2.3
9
9
  - 2.4
10
10
  - 2.5
11
+ - 2.6
11
12
  env:
12
13
  global:
13
14
  - CC_TEST_REPORTER_ID=270a7dd1c7f3f40fdb0d62c2403dd1f643e4cadbf6b8f5992e74b62ea4e6974b
14
- before_install: gem install bundler -v 1.17.1
15
+ before_install: gem install bundler -v 1.17.2
15
16
  before_script:
16
17
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
17
18
  - chmod +x ./cc-test-reporter
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
- # CHANGELOG
1
+ # 0.2.0
2
2
 
3
- ## 0.1.1
3
+ ### Features
4
+
5
+ * **actions:** ability to process errors that occur when executing actions
6
+ ([9a3f36d](https://github.com/moleculer-ruby/moleculer/commit/9a3f36d))
7
+ * **events:** add ability to rescue from event errors and handle
8
+ ([0f2cf1a](https://github.com/moleculer-ruby/moleculer/commit/0f2cf1a))
9
+ * **fake transporter:** add fake transporter that can be used without dependencies on an actual connected transporter
10
+ * **broker:** add the ability to check if a borker is started through the `#started` method
11
+
12
+ ### Bugfixes
13
+ * fix `concurrent_ruby` version requirement to ensure at least `1.1` is required
14
+ * fix an issue where heartbeats back up in the queue and cause errors when consumed
15
+
16
+ # 0.1.1
17
+
18
+ ### Bugfixes
4
19
  * fixes bug where event publishing uses the wrong method name to look up local events
5
20
  * fixes condition where events may double publish when multiple events are registered
data/Gemfile.lock CHANGED
@@ -1,22 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moleculer (0.1.1)
4
+ moleculer (0.2.0)
5
5
  awesome_print (~> 1.8)
6
- concurrent-ruby (~> 1.0)
6
+ concurrent-ruby (~> 1.1)
7
7
  ougai (~> 1.7)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
+ ast (2.4.0)
12
13
  awesome_print (1.8.0)
13
14
  concurrent-ruby (1.1.5)
14
15
  diff-lcs (1.3)
15
16
  docile (1.3.1)
17
+ jaro_winkler (1.5.2)
16
18
  json (2.1.0)
17
19
  oj (3.7.12)
18
20
  ougai (1.7.1)
19
21
  oj (~> 3.4)
22
+ parallel (1.17.0)
23
+ parser (2.6.3.0)
24
+ ast (~> 2.4.0)
25
+ rainbow (3.0.0)
20
26
  rake (10.5.0)
21
27
  redis (4.0.1)
22
28
  rspec (3.8.0)
@@ -32,12 +38,21 @@ GEM
32
38
  diff-lcs (>= 1.2.0, < 2.0)
33
39
  rspec-support (~> 3.8.0)
34
40
  rspec-support (3.8.0)
41
+ rubocop (0.69.0)
42
+ jaro_winkler (~> 1.5.1)
43
+ parallel (~> 1.10)
44
+ parser (>= 2.6)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 1.4.0, < 1.7)
48
+ ruby-progressbar (1.10.0)
35
49
  simplecov (0.16.1)
36
50
  docile (~> 1.1)
37
51
  json (>= 1.8, < 3)
38
52
  simplecov-html (~> 0.10.0)
39
53
  simplecov-html (0.10.2)
40
54
  timecop (0.9.1)
55
+ unicode-display_width (1.6.0)
41
56
  yard (0.9.18)
42
57
 
43
58
  PLATFORMS
@@ -49,9 +64,10 @@ DEPENDENCIES
49
64
  rake (~> 10.0)
50
65
  redis (~> 4.0)
51
66
  rspec (~> 3.0)
67
+ rubocop (~> 0.69)
52
68
  simplecov (~> 0.16)
53
69
  timecop (~> 0.9.1)
54
70
  yard (~> 0.9.11)
55
71
 
56
72
  BUNDLED WITH
57
- 1.17.1
73
+ 1.17.2
data/README.md CHANGED
@@ -10,20 +10,6 @@ build efficient, reliable & scalable services. Moleculer provides many features
10
10
  microservices.
11
11
 
12
12
 
13
- ## Features
14
- - request-reply concept
15
- - event-driven architecture with balancing
16
- - built-in service registry & dynamic service discovery
17
- - load balanced requests & events (round-robin, random(wip), cpu-usage(wip), latency(wip))
18
- - supports versioned services
19
- - built-in caching solution (memory, Redis)
20
- - pluggable transporters (TCP, NATS, MQTT, Redis, NATS Streaming, Kafka)
21
- - pluggable serializers (JSON, Avro, MsgPack, Protocol Buffers, Thrift)
22
- - pluggable validator
23
- - multiple services on a node/server
24
- - all nodes are equal, no master/leader node
25
-
26
-
27
13
  ## Getting Started
28
14
  ### Install the Gem
29
15
 
@@ -100,3 +86,23 @@ times out and throws an error.
100
86
 
101
87
  #### transporter (default: redis://localhost)
102
88
  The transporter Moleculer should use. For more information on transporters see [Transporters](https://moleculer.services/docs/0.13/networking.html#Transporters)
89
+
90
+
91
+ ## Roadmap
92
+
93
+ ### 0.1 (COMPLETE)
94
+ Initial release
95
+
96
+ * Redis transporter
97
+ * Round robin load balancing
98
+ * Service registry & dynamic service discovery
99
+ * JSON serializer
100
+
101
+ ### 0.2 (IN PROGRESS)
102
+ * Fake transporter (for testing)
103
+ * Error handling, (ability to use Airbrake, etc.)
104
+ * Event grouping
105
+
106
+ ### 0.3 (PENDING)
107
+ * NATS transporter
108
+ * Built in caching solution (Redis, Memory)
@@ -93,7 +93,7 @@ module Moleculer
93
93
 
94
94
  def start
95
95
  @logger.info "starting"
96
- @transporter.connect
96
+ @transporter.start
97
97
  register_local_node
98
98
  start_subscribers
99
99
  publish_discover
@@ -105,7 +105,7 @@ module Moleculer
105
105
  def stop
106
106
  @logger.info "stopping"
107
107
  publish(:disconnect)
108
- @transporter.disconnect
108
+ @transporter.stop
109
109
  exit 0
110
110
  end
111
111
 
@@ -172,6 +172,18 @@ module Moleculer
172
172
  )
173
173
  end
174
174
 
175
+ ##
176
+ # @return [Proc] returns the rescue_action if defined on the configuration
177
+ def rescue_action
178
+ config.rescue_action
179
+ end
180
+
181
+ ##
182
+ # @return [Proc] returns the rescue_event if defined on the configuration
183
+ def rescue_event
184
+ config.rescue_event
185
+ end
186
+
175
187
  private
176
188
 
177
189
  def handle_signal(sig)
@@ -74,6 +74,8 @@ module Moleculer
74
74
  config_accessor :serializer, :json
75
75
  config_accessor :node_id, "#{Socket.gethostname.downcase}-#{Process.pid}"
76
76
  config_accessor :service_prefix
77
+ config_accessor :rescue_action
78
+ config_accessor :rescue_event
77
79
 
78
80
  attr_accessor :broker
79
81
 
@@ -29,15 +29,20 @@ module Moleculer
29
29
  end
30
30
 
31
31
  ##
32
- # @param context [Moleculer::Context] the execution contextd
32
+ # @param context [Moleculer::Context] the execution context
33
33
  #
34
34
  # @return [Moleculer::Support::Hash] returns a hash which will be converted into json for the response.
35
+ # @raise [Errors::InvalidActionResponse] thrown when the result of calling the action does not return a hash
35
36
  def execute(context, broker)
36
37
  response = @service.new(broker).public_send(@method, context)
37
- # rubocop:disable Style/RaiseArgs
38
- raise Errors::InvalidActionResponse.new(response) unless response.is_a? Hash
38
+ # rubocop disabled because in this case we need a specific error handling format
39
+ raise Errors::InvalidActionResponse.new(response) unless response.is_a? Hash # rubocop:disable Style/RaiseArgs
39
40
 
40
41
  response
42
+ rescue StandardError => e
43
+ raise e unless broker.rescue_action
44
+
45
+ broker.rescue_action.call(e)
41
46
  end
42
47
 
43
48
  def node
@@ -28,8 +28,13 @@ module Moleculer
28
28
  ##
29
29
  # Executes the event
30
30
  # @param data [Hash] the event data
31
+ # @param broker [Moleculer::Broker] the moleculer broker
31
32
  def execute(data, broker)
32
33
  @service.new(broker).public_send(@method, data)
34
+ rescue StandardError => e
35
+ raise e unless broker.rescue_event
36
+
37
+ broker.rescue_event.call(e)
33
38
  end
34
39
 
35
40
  ##
@@ -0,0 +1,45 @@
1
+ module Moleculer
2
+ ##
3
+ # A transporter is the method by which moleculer transports information from one service to the next. Transporters can
4
+ # be created using any over-the-wire bus that can be made to support some level of queueing (i.e. Redis, NATS, Kafka)
5
+ module Transporters
6
+ ##
7
+ # All transporters inherit from this class. The Base class simply defines an interface that transporters should
8
+ # adhere to.
9
+ class Base
10
+ ##
11
+ # @param config [Moleculer::Configuration] the transporter configuration.
12
+ def initialize(config)
13
+ @config = config
14
+ end
15
+
16
+ ##
17
+ # Subscribes to the given channel on the transporter's message bus
18
+ # @param channel [String] the channel to which to subscribe
19
+ def subscribe(_channel, &_block)
20
+ raise NotImplementedError
21
+ end
22
+
23
+ ##
24
+ # Publishes the provided packet to the transporter's message bus. The publish method is expected to implement the
25
+ # method of translating the packet data into the channel information on which to publish.
26
+ # @param packet [Moleculer::Packet::Base] the packet to publish to the network.
27
+ def publish(_packet)
28
+ raise NotImplementedError
29
+ end
30
+
31
+ ##
32
+ # Starts the transporter, and activates all of the subscriptions. The subscriptions should not start consuming
33
+ # until the start method has been called.
34
+ def start
35
+ raise NotImplementedError
36
+ end
37
+
38
+ ##
39
+ # Stops the transporter, and stops all subscriptions from consuming
40
+ def stop
41
+ raise NotImplementedError
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "base"
2
+
3
+ module Moleculer
4
+ module Transporters
5
+ ##
6
+ # The fake transporter is designed to be used in testing. It is simply an in memory queue and should not be used
7
+ # in production.
8
+ class Fake < Base
9
+ def initialize(config)
10
+ super(config)
11
+ # in this case we want to use a class var as this needs to behave like a singleton to mimic how a global
12
+ # transporter functions
13
+ @@subscriptions ||= {} # rubocop:disable Style/ClassVars
14
+ end
15
+
16
+ def subscribe(channel, &block)
17
+ @@subscriptions[channel] = block
18
+ end
19
+
20
+ def publish(packet)
21
+ @@subscriptions[packet.topic].call(packet)
22
+ end
23
+
24
+ def start
25
+ true
26
+ end
27
+
28
+ def stop
29
+ true
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,4 +1,5 @@
1
1
  require "redis"
2
+ require_relative "base"
2
3
 
3
4
  # frozen_string_literal: true
4
5
 
@@ -6,7 +7,7 @@ module Moleculer
6
7
  module Transporters
7
8
  ##
8
9
  # The Moleculer Redis transporter
9
- class Redis
10
+ class Redis < Base
10
11
  ##
11
12
  # @private
12
13
  # Represents the publisher connection
@@ -21,7 +22,7 @@ module Moleculer
21
22
  # Publishes the packet to the packet's topic
22
23
  def publish(packet)
23
24
  topic = packet.topic
24
- @logger.trace "publishing packet to '#{topic}'", packet.as_json
25
+ @logger.debug "publishing packet to '#{topic}'", packet.as_json
25
26
  connection.publish(topic, @serializer.serialize(packet))
26
27
  end
27
28
 
@@ -155,6 +156,7 @@ module Moleculer
155
156
  @uri = config.transporter
156
157
  @logger = config.logger.get_child("[REDIS.TRANSPORTER]")
157
158
  @subscriptions = Concurrent::Array.new
159
+ @started = false
158
160
  end
159
161
 
160
162
  def subscribe(channel, &block)
@@ -163,13 +165,25 @@ module Moleculer
163
165
  channel: channel,
164
166
  block: block,
165
167
  config: @config,
166
- ).connect
168
+ )
169
+
170
+ @subscriptions.last.connect if started?
167
171
  end
168
172
 
169
173
  def disconnect
170
174
  @logger.debug "disconnecting subscriptions"
171
175
  @subscriptions.each(&:disconnect)
172
176
  end
177
+
178
+ def connect
179
+ @logger.debug "connecting subscriptions"
180
+ @subscriptions.each(&:connect)
181
+ @started = true
182
+ end
183
+
184
+ def started?
185
+ @started
186
+ end
173
187
  end
174
188
 
175
189
  def initialize(config)
@@ -184,11 +198,12 @@ module Moleculer
184
198
  publisher.publish(packet)
185
199
  end
186
200
 
187
- def connect
201
+ def start
188
202
  publisher.connect
203
+ subscriber.connect
189
204
  end
190
205
 
191
- def disconnect
206
+ def stop
192
207
  publisher.disconnect
193
208
  subscriber.disconnect
194
209
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Moleculer
2
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
3
5
  end
data/moleculer.gemspec CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
37
  spec.require_paths = ["lib"]
38
38
 
39
- spec.add_dependency "concurrent-ruby", "~> 1.0"
39
+ spec.add_dependency "concurrent-ruby", "~> 1.1"
40
40
  spec.add_dependency "ougai", "~> 1.7"
41
41
  spec.add_dependency "awesome_print", "~> 1.8"
42
42
 
@@ -45,6 +45,7 @@ Gem::Specification.new do |spec|
45
45
  spec.add_development_dependency "rake", "~> 10.0"
46
46
  spec.add_development_dependency "redis", "~> 4.0"
47
47
  spec.add_development_dependency "rspec", "~> 3.0"
48
+ spec.add_development_dependency "rubocop", "~> 0.69"
48
49
  spec.add_development_dependency "simplecov", "~> 0.16"
49
50
  spec.add_development_dependency "timecop", "~> 0.9.1"
50
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moleculer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fugufish
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-13 00:00:00.000000000 Z
11
+ date: 2019-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '1.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '1.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ougai
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.69'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.69'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: simplecov
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -157,9 +171,11 @@ executables: []
157
171
  extensions: []
158
172
  extra_rdoc_files: []
159
173
  files:
174
+ - ".codeclimate.yml"
160
175
  - ".gitignore"
161
176
  - ".rspec"
162
177
  - ".rubocop.yml"
178
+ - ".ruby-version"
163
179
  - ".travis.yml"
164
180
  - ".yardopts"
165
181
  - CHANGELOG.md
@@ -207,6 +223,8 @@ files:
207
223
  - lib/moleculer/support/open_struct.rb
208
224
  - lib/moleculer/support/string_util.rb
209
225
  - lib/moleculer/transporters.rb
226
+ - lib/moleculer/transporters/base.rb
227
+ - lib/moleculer/transporters/fake.rb
210
228
  - lib/moleculer/transporters/redis.rb
211
229
  - lib/moleculer/version.rb
212
230
  - moleculer.gemspec
@@ -231,8 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
249
  - !ruby/object:Gem::Version
232
250
  version: '0'
233
251
  requirements: []
234
- rubyforge_project:
235
- rubygems_version: 2.7.7
252
+ rubygems_version: 3.0.3
236
253
  signing_key:
237
254
  specification_version: 4
238
255
  summary: This is a Ruby implementation of the Moleculer framework.