Module: Moleculer
- Extended by:
- Moleculer
- Included in:
- Moleculer
- Defined in:
- lib/moleculer.rb,
lib/moleculer/node.rb,
lib/moleculer/broker.rb,
lib/moleculer/context.rb,
lib/moleculer/packets.rb,
lib/moleculer/version.rb,
lib/moleculer/registry.rb,
lib/moleculer/packets/req.rb,
lib/moleculer/packets/res.rb,
lib/moleculer/serializers.rb,
lib/moleculer/packets/base.rb,
lib/moleculer/packets/info.rb,
lib/moleculer/service/base.rb,
lib/moleculer/transporters.rb,
lib/moleculer/configuration.rb,
lib/moleculer/packets/event.rb,
lib/moleculer/service/event.rb,
lib/moleculer/service/action.rb,
lib/moleculer/service/remote.rb,
lib/moleculer/packets/discover.rb,
lib/moleculer/serializers/json.rb,
lib/moleculer/packets/heartbeat.rb,
lib/moleculer/support/hash_util.rb,
lib/moleculer/support/log_proxy.rb,
lib/moleculer/transporters/base.rb,
lib/moleculer/transporters/fake.rb,
lib/moleculer/packets/disconnect.rb,
lib/moleculer/transporters/redis.rb,
lib/moleculer/support/open_struct.rb,
lib/moleculer/support/string_util.rb,
lib/moleculer/errors/node_not_found.rb,
lib/moleculer/errors/action_not_found.rb,
lib/moleculer/errors/invalid_action_response.rb,
lib/moleculer/errors/transporter_already_started.rb,
lib/moleculer/errors/local_node_already_registered.rb
Overview
frozen_string_literal: true
Defined Under Namespace
Modules: Errors, Packets, Serializers, Service, Support, Transporters Classes: Broker, Configuration, Context, Node, Registry
Constant Summary collapse
- PROTOCOL_VERSION =
"3".freeze
- VERSION =
"0.3.0"
Instance Attribute Summary collapse
-
#broker ⇒ Moleculer::Broker
readonly
The Moleculer Broker instance.
-
#service_prefix ⇒ Symbol
The service prefix.
Instance Method Summary collapse
-
#call(action, params = {}, **kwargs) ⇒ Hash
Calls the given action.
- #config ⇒ Object
-
#configure {|self| ... } ⇒ Object
Allows configuration of moleculer.
-
#emit(event, data) ⇒ Object
Emits the given event to the Moleculer network.
-
#run ⇒ Object
Runs the moleculer broker.
-
#start ⇒ Object
Starts the moleculer broker.
-
#stop ⇒ Object
Stops the moleculer broker.
-
#wait_for_services(*services) ⇒ Object
Blocks the processes until the requested services have been registered on the network.
Instance Attribute Details
#broker ⇒ Moleculer::Broker (readonly)
Returns the Moleculer Broker instance. Only one broker can exist per node.
35 36 37 |
# File 'lib/moleculer.rb', line 35 def broker @broker ||= Broker.new(config) end |
#service_prefix ⇒ Symbol
Returns the service prefix. When used will prefix all services name with <service_prefix>.
, defaults
to nil
.
29 30 31 |
# File 'lib/moleculer.rb', line 29 def service_prefix @service_prefix end |
Instance Method Details
#call(action, params = {}, **kwargs) ⇒ Hash
Calls the given action. This method will block until the timeout is hit (default 5 seconds) or the action returns a response
48 49 50 51 52 |
# File 'lib/moleculer.rb', line 48 def call(action, params = {}, **kwargs) return broker.call(action.to_s, kwargs) if params.empty? broker.call(action.to_s, params, kwargs) end |
#config ⇒ Object
54 55 56 |
# File 'lib/moleculer.rb', line 54 def config @config ||= Configuration.new end |
#configure {|self| ... } ⇒ Object
Allows configuration of moleculer. For more information on configuration see the Readme
62 63 64 |
# File 'lib/moleculer.rb', line 62 def configure yield config end |
#emit(event, data) ⇒ Object
Emits the given event to the Moleculer network.
71 72 73 |
# File 'lib/moleculer.rb', line 71 def emit(event, data) broker.emit(event, data) end |
#run ⇒ Object
Runs the moleculer broker. This is synchronous and blocks.
77 78 79 |
# File 'lib/moleculer.rb', line 77 def run broker.run end |
#start ⇒ Object
Starts the moleculer broker. This is asynchronous and does not block.
83 84 85 |
# File 'lib/moleculer.rb', line 83 def start broker.start end |
#stop ⇒ Object
Stops the moleculer broker.
89 90 91 |
# File 'lib/moleculer.rb', line 89 def stop broker.stop end |
#wait_for_services(*services) ⇒ Object
Blocks the processes until the requested services have been registered on the network.
100 101 102 |
# File 'lib/moleculer.rb', line 100 def wait_for_services(*services) broker.wait_for_services(*services) end |