clusterduck-http
The HTTP extension for Clusterduck which includes:
- HTTP/WebSocket health checks
- Balancer: HAProxy integration with seamless hot restarting.
Table Of Contents
Installation
Clusterduck is required.
npm i -g clusterduck-http
Configuration
Let's define a HTTP cluster named my_web_cluster
:
# clusters:
my_http_cluster:
type: clusterduck-http
Nodes
Then let's define some nodes:
# List of nodes
nodes:
- addr: 1.1.1.1:80
- addr: 2.2.2.2:80
Note that you can omit this altogether if you want to only add nodes dynamically.
Health checks
If you do not want to use health checks, use:
pass_without_checks: true
Otherwise, define the health_checks
array:
health_checks:
WebSocket
- type: websocket
timeout: 5s
every: 10s
url: wss://your-domain/websocket/
every: 1000s
timeout: 20s
flow:
- type: expect_json # Expect a JSON packet
skip_forward: true # Ignore prior unexpected packets
match: # Match conditions [path, eq|exists, ?right]
- [ response.text, eq, "Knock-knock."]
- [ timestamp ] # 'timestamp' field exists
- type: send_json
body: {query: {text: "Who's there?"}}
- type: expect_json
match:
- [ response.text, eq, "Amish."]
- type: send_json
body: {query: {text: "Amish who?"}}
- type: expect_json
match:
- [ response.text, eq, "Really? You don’t look like a shoe!"]
Note that DNS lookups get overridden, so
your-domain
will be resolved to an IP-address corresponding to one of the nodes in your cluster. However,Host
header will be set toyour-domain
.
HAProxy balancer
HAProxy is required to be installed.
Let's write up a config:
balancers:
my_balancer:
type: haproxy
listen: 0.0.0.0:443
Note:
clusterduck
will runhaproxy
with an according configuration. Hot restarting works out-of-box so thatHAProxy
is always kept in sync withclusterduck
. It requires no middleware or additional configuration.
Debug
For debugging purposes use DEBUG
environmental variable:
DEBUG=haproxy clusterduck
Dependencies
- clusterduck
HAProxy balancer
License
LGPL 3.0 or later.