Rak v0.1.2 Rak.App
Rak Game Server Maker
The top level module is used to define how your server will be composed. In here, we define which services to use, and how they will connect to each other.
lib/my_app.ex
defmodule MyApp do
use Rak.App,
metrics: Rak.Metrics.Prometheus,
service: MyApp.Service,
module: :auto,
discovery: Rak.Discovery.Consul,
connector: [
module: Rak.Connector.Web,
message: Rak.Message.Raw,
session: Rak.Session.Basic
]
end
Components groups are started in the following order:
[
metrics: "Metrics system",
service: "Top-level application service",
module: "Application module",
session: "Session module",
discovery: "Discovery and clustering (optional)",
connector: "Network connector for clients to connect to the server"
]
While components groups are in a fixed order, and components within a group will be started in the order they are provided in.
You may also specify multiple entries for each components, or remove them if you do not use them.
lib/my_app.ex
defmodule MyApp do
use Rak.App,
service: MyApp.Service
metrics: Rak.Metrics.Prometheus,
metrics: Rak.Metrics.CollectD,
end
For instance, in this case metrics
components will be started before
the service
component, but the Prometheus metrics
component will always
start before the CollectD
one.
module: :auto
is a wildcard configuration entry that lets
Rak know to load all top-level modules automatically. Note that
module: :auto
can be used alongside a set module load order:
lib/my_app.ex
defmodule MyApp do
use Rak.App,
module: MyApp.LoadThisFirstModule,
module: MyApp.LoadThisSecondModule,
module: :auto,
module: MyApp.LoadThisLastModule
end
You may want to configure which modules to start depending
on the environment you are running. For instance, you may not
want to start the discovery service when developing locally. In
such cases, you may move the configuration to your config/config.exs
and override it depending on the environment.
lib/my_app.ex
defmodule MyApp do
use Rak.App
end
config/config.exs
use Mix.Config
config MyApp,
rak: [
metrics: Rak.Metrics.Prometheus,
service: MyApp.Service,
module: :auto,
discovery: Rak.Discovery.Consul,
connector: [
module: Rak.Connector.Web,
message: Rak.Message.Raw,
session: Rak.Session.Basic
]
]