moleculer 0.1.0
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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +44 -0
- data/.travis.yml +23 -0
- data/.yardopts +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +57 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/benchmark_server.rb +21 -0
- data/examples/client-server/client.rb +13 -0
- data/examples/client-server/server.rb +25 -0
- data/lib/moleculer/broker.rb +318 -0
- data/lib/moleculer/configuration.rb +109 -0
- data/lib/moleculer/context.rb +24 -0
- data/lib/moleculer/errors/action_not_found.rb +6 -0
- data/lib/moleculer/errors/invalid_action_response.rb +11 -0
- data/lib/moleculer/errors/local_node_already_registered.rb +6 -0
- data/lib/moleculer/errors/node_not_found.rb +6 -0
- data/lib/moleculer/errors/transporter_already_started.rb +6 -0
- data/lib/moleculer/node.rb +105 -0
- data/lib/moleculer/packets/base.rb +47 -0
- data/lib/moleculer/packets/disconnect.rb +10 -0
- data/lib/moleculer/packets/discover.rb +10 -0
- data/lib/moleculer/packets/event.rb +37 -0
- data/lib/moleculer/packets/heartbeat.rb +18 -0
- data/lib/moleculer/packets/info.rb +97 -0
- data/lib/moleculer/packets/req.rb +57 -0
- data/lib/moleculer/packets/res.rb +43 -0
- data/lib/moleculer/packets.rb +25 -0
- data/lib/moleculer/registry.rb +325 -0
- data/lib/moleculer/serializers/json.rb +23 -0
- data/lib/moleculer/serializers.rb +10 -0
- data/lib/moleculer/service/action.rb +60 -0
- data/lib/moleculer/service/base.rb +117 -0
- data/lib/moleculer/service/event.rb +50 -0
- data/lib/moleculer/service/remote.rb +80 -0
- data/lib/moleculer/service.rb +2 -0
- data/lib/moleculer/support/hash_util.rb +48 -0
- data/lib/moleculer/support/log_proxy.rb +67 -0
- data/lib/moleculer/support/open_struct.rb +15 -0
- data/lib/moleculer/support/string_util.rb +25 -0
- data/lib/moleculer/support.rb +4 -0
- data/lib/moleculer/transporters/redis.rb +207 -0
- data/lib/moleculer/transporters.rb +22 -0
- data/lib/moleculer/version.rb +3 -0
- data/lib/moleculer.rb +103 -0
- data/moleculer.gemspec +50 -0
- metadata +238 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 585ff4890f2ecff42a4d8c52a3b1a5d564b573fe4d1a4f2b885d67c4474076cb
|
4
|
+
data.tar.gz: 40879caafedd0acb902f9ef45fac1e7523b9b151eb36adfa7dfa7f298f52a187
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe5cda825507a25095f432630c819c8c162868f24e13d0cdcc6415654b69e01a7117282a166fa9ecaca0c76cfb8a3f6c19298454da5133c763934e8d75a534ad
|
7
|
+
data.tar.gz: 91ca2bba2f49ed50c560a56361c2583e20f04abd5d9327e6737ef2e263b8e86a8562e6e36822590254285de4f871ccbb8a663559b24de09ca7c1ba4f6da1fce4
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Layout/ExtraSpacing:
|
2
|
+
ForceEqualSignAlignment: true
|
3
|
+
|
4
|
+
Layout/IndentHash:
|
5
|
+
EnforcedStyle: consistent
|
6
|
+
|
7
|
+
Layout/IndentationWidth:
|
8
|
+
IgnoredPatterns: []
|
9
|
+
|
10
|
+
Style/AlignHash:
|
11
|
+
EnforcedColonStyle: table
|
12
|
+
EnforcedHashRocketStyle: table
|
13
|
+
|
14
|
+
Style/ModuleFunction:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/TrailingCommaInArguments:
|
18
|
+
EnforcedStyleForMultiline: comma
|
19
|
+
|
20
|
+
Style/TrailingCommaInHashLiteral:
|
21
|
+
EnforcedStyleForMultiline: comma
|
22
|
+
|
23
|
+
Style/TrailingCommaInArrayLiteral:
|
24
|
+
EnforcedStyleForMultiline: comma
|
25
|
+
|
26
|
+
Style/StringLiterals:
|
27
|
+
EnforcedStyle: "double_quotes"
|
28
|
+
|
29
|
+
Metrics/LineLength:
|
30
|
+
Max: 120
|
31
|
+
IgnoreCopDirectives: true
|
32
|
+
|
33
|
+
Metrics/ModuleLength:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Metrics/MethodLength:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Metrics/BlockLength:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Metrics/ParameterLists:
|
43
|
+
Enabled: false
|
44
|
+
|
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
sudo: false
|
3
|
+
language: ruby
|
4
|
+
cache: bundler
|
5
|
+
services:
|
6
|
+
- redis-server
|
7
|
+
rvm:
|
8
|
+
- 2.3
|
9
|
+
- 2.4
|
10
|
+
- 2.5
|
11
|
+
env:
|
12
|
+
global:
|
13
|
+
- CC_TEST_REPORTER_ID=270a7dd1c7f3f40fdb0d62c2403dd1f643e4cadbf6b8f5992e74b62ea4e6974b
|
14
|
+
before_install: gem install bundler -v 1.16.6
|
15
|
+
before_script:
|
16
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
17
|
+
- chmod +x ./cc-test-reporter
|
18
|
+
- ./cc-test-reporter before-build
|
19
|
+
script:
|
20
|
+
- bundle exec rspec
|
21
|
+
after_script:
|
22
|
+
|
23
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup=markdown
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at therealfugu@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
moleculer (0.1.0)
|
5
|
+
awesome_print (~> 1.8)
|
6
|
+
concurrent-ruby (~> 1.0)
|
7
|
+
ougai (~> 1.7)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
awesome_print (1.8.0)
|
13
|
+
concurrent-ruby (1.1.5)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
docile (1.3.1)
|
16
|
+
json (2.1.0)
|
17
|
+
oj (3.7.11)
|
18
|
+
ougai (1.7.1)
|
19
|
+
oj (~> 3.4)
|
20
|
+
rake (10.5.0)
|
21
|
+
redis (4.0.1)
|
22
|
+
rspec (3.8.0)
|
23
|
+
rspec-core (~> 3.8.0)
|
24
|
+
rspec-expectations (~> 3.8.0)
|
25
|
+
rspec-mocks (~> 3.8.0)
|
26
|
+
rspec-core (3.8.0)
|
27
|
+
rspec-support (~> 3.8.0)
|
28
|
+
rspec-expectations (3.8.2)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.8.0)
|
31
|
+
rspec-mocks (3.8.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.8.0)
|
34
|
+
rspec-support (3.8.0)
|
35
|
+
simplecov (0.16.1)
|
36
|
+
docile (~> 1.1)
|
37
|
+
json (>= 1.8, < 3)
|
38
|
+
simplecov-html (~> 0.10.0)
|
39
|
+
simplecov-html (0.10.2)
|
40
|
+
timecop (0.9.1)
|
41
|
+
yard (0.9.18)
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
bundler (~> 1.16)
|
48
|
+
moleculer!
|
49
|
+
rake (~> 10.0)
|
50
|
+
redis (~> 4.0)
|
51
|
+
rspec (~> 3.0)
|
52
|
+
simplecov (~> 0.16)
|
53
|
+
timecop (~> 0.9.1)
|
54
|
+
yard (~> 0.9.11)
|
55
|
+
|
56
|
+
BUNDLED WITH
|
57
|
+
1.17.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 fugufish
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Moleculer
|
2
|
+
[](https://travis-ci.org/moleculer-ruby/moleculer)
|
3
|
+
[](https://codeclimate.com/github/moleculer-ruby/moleculer/maintainability)
|
4
|
+
[](https://codeclimate.com/github/moleculer-ruby/moleculer/test_coverage)
|
5
|
+
|
6
|
+
Moleculer is a fast, modern and powerful microservices framework for originally written for [Node.js](). It helps you to
|
7
|
+
build efficient, reliable & scalable services. Moleculer provides many features for building and managing your
|
8
|
+
microservices.
|
9
|
+
|
10
|
+
|
11
|
+
## Features
|
12
|
+
- request-reply concept
|
13
|
+
- event-driven architecture with balancing
|
14
|
+
- built-in service registry & dynamic service discovery
|
15
|
+
- load balanced requests & events (round-robin, random(wip), cpu-usage(wip), latency(wip))
|
16
|
+
- supports versioned services
|
17
|
+
- built-in caching solution (memory, Redis)
|
18
|
+
- pluggable transporters (TCP, NATS, MQTT, Redis, NATS Streaming, Kafka)
|
19
|
+
- pluggable serializers (JSON, Avro, MsgPack, Protocol Buffers, Thrift)
|
20
|
+
- pluggable validator
|
21
|
+
- multiple services on a node/server
|
22
|
+
- all nodes are equal, no master/leader node
|
23
|
+
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
Moleculer is configured through the Moleculer::config method. Example:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Moleculer.config do |c|
|
31
|
+
c.log_level :debug
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
### Configuration Options
|
36
|
+
|
37
|
+
#### log_level (default: debug)
|
38
|
+
Sets the log level of the node. defaults to `:debug`. Can be one of `:trace`, `:debug`, `:info`, `:warn`, `:error`,
|
39
|
+
`:fatal`.
|
40
|
+
|
41
|
+
#### node_id (default: \<hostname\>-\<pid\>)
|
42
|
+
The node id. Node IDs are required to be unique. In Moleculer-ruby all node ids are suffixed with the PID of the
|
43
|
+
running process, allowing multiple copies of the same node to be run on the same machine. When using a containerized
|
44
|
+
environment (i.e. Docker), it is suggested that the node_id also include a random set of characters as there is a chance
|
45
|
+
that does running in separate containers can have the same PID.
|
46
|
+
|
47
|
+
#### serializer (default: :json)
|
48
|
+
Which serializer to use. For more information serializers see [Serialization](https://moleculer.services/docs/0.13/networking.html#Serialization)
|
49
|
+
|
50
|
+
#### service_prefix (default: nil)
|
51
|
+
The service prefix. This will be prefixed to all services. For example if `service_prefix` were to be `foo` then a
|
52
|
+
service whose `service_name` is set to `users` would get the full `service_name` of `foo.users`.
|
53
|
+
|
54
|
+
#### timeout (default: 5)
|
55
|
+
The Moleculer system timeout. This is used to determine how long a moleculer `call` will wait for a response until it
|
56
|
+
times out and throws an error.
|
57
|
+
|
58
|
+
#### transporter (default: redis://localhost)
|
59
|
+
The transporter Moleculer should use. For more information on transporters see [Transporters](https://moleculer.services/docs/0.13/networking.html#Transporters)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "moleculer/ruby"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../lib/moleculer"
|
4
|
+
|
5
|
+
##
|
6
|
+
# Users is a class for benmarking speed vs Moleculer Node apps
|
7
|
+
class Users < Moleculer::Service::Base
|
8
|
+
service_name "users"
|
9
|
+
action "empty", :empty
|
10
|
+
|
11
|
+
def empty(_context)
|
12
|
+
{}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Moleculer.config do |c|
|
17
|
+
c.services << Users
|
18
|
+
c.log_level = :info
|
19
|
+
end
|
20
|
+
|
21
|
+
Moleculer.run
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "benchmark"
|
2
|
+
require_relative "../../lib/moleculer"
|
3
|
+
Moleculer.configure do |c|
|
4
|
+
c.log_level = :trace
|
5
|
+
end
|
6
|
+
Moleculer.start
|
7
|
+
|
8
|
+
Moleculer.wait_for_services("math")
|
9
|
+
|
10
|
+
result = Moleculer.call("math.add", a: 1, b: 2)
|
11
|
+
Moleculer.emit("echo.event", test: true)
|
12
|
+
|
13
|
+
puts result
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "../../lib/moleculer"
|
2
|
+
|
3
|
+
class Server < Moleculer::Service::Base
|
4
|
+
service_name "math"
|
5
|
+
action "add", :add
|
6
|
+
event "echo.event", :echo
|
7
|
+
|
8
|
+
def add(ctx)
|
9
|
+
{
|
10
|
+
count: ctx.params.count,
|
11
|
+
res: ctx.params["a"].to_i + ctx.params["b"].to_i,
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def echo(data)
|
16
|
+
broker.emit("reply.event", data)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Moleculer.configure do |c|
|
21
|
+
c.log_level = :trace
|
22
|
+
c.services << Server
|
23
|
+
end
|
24
|
+
|
25
|
+
Moleculer.run
|