Skip to content

Toro Cloud Dev Center


Consul

Martini uses the Ecwid/consul-api library to connect to a Consul server. The table below describes the related properties and their descriptions:

Property Default Description
consul.url URL of the Consul server. Example: http://127.0.0.1:8500. URL must use either http:// or https://. If the URL doesn't include a port, 8500 will be used.
consul.acl ACL token to use when making requests to Consul.
consul.read-timeout 600000 Timeout in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets. A timeout value of 0 is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).
consul.connection-timeout 10000 Timeout in milliseconds until a connection is established. A timeout value of 0 is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).
consul.services-interval 10 How often Consul will check the health of registered services with Martini, in seconds. Consul will check whether the service is available by requesting <martini-url>/esbapi/service-registry/available/(soap|rest)/<service|api-namespace>. Martini will return with a 200 if the service is available, or a 404 if it's not.
consul.services-deregister-after 60 How long Consul will wait before removing unavailable services, in seconds. You can read about this property in more detail here.
consul.leader-interval 10 How often Martini will renew the session it created for the purposes of leader election, in seconds.
consul.leader-ttl 15 Time to Live duration of the session Martini creates for the purposes of leader election (between 10 and 86400 seconds). The session is invalidated (and a new leader chosen) if it is not renewed before the TTL expires.
consul.leader-key martini-leader Name of the session Martini creates for the purposes of leader election. All instances competing for leadership must use the same key.

How to enable Consul in Martini

The bare minimum to have Martini work with Consul is to configure the consul.url property. If this property is not configured, Martini will not use any Consul-specific functionality.

When a Martini instance is connected to Consul and has gained leadership, Martini will log the following (if enabled):

1
INFO  [ConsulLeadershipElector] This node has become the leader, any non-replicated endpoints will now be started

Consul can be used as a DNS server for service discovery. When Martini registers Gloop APIs to Consul, any dots in the namespace of the API are replaced with hyphens. For example, if you have an API at my.api.HelloApi, you will be able to perform DNS lookups against Consul using the name my-api-helloapi. Note that DNS names are limited to 63 characters.