resilient-consul
resilient.js HTTP client middleware for Consul.
Via this middleware you can use Consul as compatible discovery server in Resilient HTTP clients.
Works with Consul HTTP API v1
and resilient.js +0.3
Name | consul |
Type | discovery |
Resilient | +0.3 |
Environments | node.js / browsers |
Installation
Node.js
npm install resilient-consul --save
Browser
Via Bower:
bower install resilient-consul --save
Via Component:
component install h2non/resilient-consul
Or loading the script directly:
Usage
var Resilient = var consul = var client = client // Test requestclient
Browser usage
If you're running Resilient in the browser, you must enable CORS headers in Consul. To do that you can define additional response HTTP headers in the Consul config file:
"http_api_response_headers": {
"Access-Control-Allow-Origin": "*"
}
Options
- service
string
- Consul service. Required - servers
array<string>
- List of Consul servers URLs. Required - discoveryService
string
- Consul discovery service for self discovery (e.g: consul) - datacenter
string
- Custom datacenter to use. If not defined the default one will be used - tag
string
- Use a specific tag for the service - onlyHealthy
boolean
- Use Consul's health check endpoint instead of the catalog to retrieve only services with passing health checks. Default tofalse
- protocol
string
- Transport URI protocol. Default tohttp
- mapServers
function
- Custom function for creating the list of service addresses based on the Consul response
Additionally you can pass any of the supported Resilient discovery options via this middleware
License
MIT - Tomas Aparicio