0.1.8 • Published 4 years ago

clusterduck-http v0.1.8

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
4 years ago

clusterduck-http total downloads of clusterduck-http

clusterduck-http's License latest version of clusterduck-http

The HTTP extension for Clusterduck which includes:

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 to your-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 run haproxy with an according configuration. Hot restarting works out-of-box so that HAProxy is always kept in sync with clusterduck. It requires no middleware or additional configuration.

Debug

For debugging purposes use DEBUG environmental variable: DEBUG=haproxy clusterduck

Dependencies

HAProxy balancer

License

LGPL 3.0 or later.