Moleculer is a fast, modern and powerful microservices framework for originally written for Node.js. It helps you to build efficient, reliable & scalable services. Moleculer provides many features for building and managing your microservices.
gem install "moleculer-ruby"
or add to your Gemfile:
gem "moleculer-ruby", "~>0.3"
class SimpleService < Moleculer::Service::Base
action :get_user, :get_user
def get_user
# .. usery getting stuff
end
end
Moleculer.config do |c|
c.services << SimpleService
end
Moleculer.start
Moleculer is configured through the Moleculer::config method. Example:
Moleculer.configure do |c|
c.log_level = :debug
end
Some Moleculer configuration values can also be set through environment variables.
Sets an error handler that ties into the infrastructure of Moleculer instructing it how to handle errors of the specified
class. This allows things like Airbrake to easily tie in to exception handling. By default Moleculer rescues from
StandardError
and simply logs it out.
Sets the moleculer log_file. This value can also be set by setting the MOLECULER_LOG_FILE
environment variable.
Sets the moleculer logger. The logger must be an instance of Moleculer::Support::LogProxy
. The log proxy supports any
ruby logger that supports the ruby Logger
interface.
Example:
c.logger = Moleculer::Support::Logger.new(Rails.logger)
In the case that the logger is set to something other than the default, the log level set for moleculer is ignored, and the level of the passed logger is used.
Sets the log level of the node. defaults to :debug
. Can be one of :trace
, :debug
, :info
, :warn
, :error
,
:fatal
. This value can also be set by setting the MOLECULER_LOG_LEVEL
environment variable.
The interval in which to send heartbeats. This value can also be set by setting the MOLECULER_HEARTBEAT
environment variable.
The node id. Node IDs are required to be unique. In Moleculer-ruby all node ids are suffixed with the PID of the running process, allowing multiple copies of the same node to be run on the same machine. When using a containerized environment (i.e. Docker), it is suggested that the node_id also include a random set of characters as there is a chance that does running in separate containers can have the same PID.
Which serializer to use. For more information serializers see Serialization
The service prefix. This will be prefixed to all services. For example if service_prefix
were to be foo
then a
service whose service_name
is set to users
would get the full service_name
of foo.users
.
The Moleculer system timeout. This is used to determine how long a moleculer call
will wait for a response until it
times out and throws an error. This value can also be set by setting the MOLECULER_TIMEOUT
environment variable.
The transporter Moleculer should use. For more information on transporters see Transporters
This value can also be set by setting the MOLECULER_TRANSPORTER
environment variable.
Initial release
- Redis transporter
- Round robin load balancing
- Service registry & dynamic service discovery
- JSON serializer
- Fake transporter (for testing)
- Error handling, (ability to use Airbrake, etc.)
- Service versioning
- Environment variable based configuration
- Protobuf serializer
- Add MessagePack serializer
- Circuit Breaker support
- Retry support
- Bulkhead support
- Fallback support
- Nested call support