Middleware based proxy for cluster or table based routing.
Middleware based proxy for table or cluster based routing.
Carbon support many types of middlware. The bundled middlware is specifically for different types of balancing techniques. You can find other middleware projects by following the links below.
module.exportnode compatible webserver, start
nprocesses and balance traffic. (Psuedo-clustering)
$ npm install carbon
To get the basics, you can also check out the
Carbon allow you to build your own routing logic. In this really basic example,
all traffic to port
8080 will be routed to port
var proxy = require'carbon'listen8080;proxyusenext8081;;// for websocketsproxywsusenext8081;;
The Carbon ProxyTable middleware makes it easy to route any traffic for a specific host to a different host, port, or set of host/ports.
var proxy = require'carbon'listen8080;// Single port proxy tableproxyusecarbonproxyTablehostname: 'localhost:8080'port: 8081;// Balanced proxyTableproxyusecarbonproxyTablehostname: 'proxytable.com'dest: 'localhost:9091' 9191 'ec2-10-10-10-10:9090';
The proxyTable middleware takes an array of object definitions. If an array of
dest is provided, requests will be round-robin
balanced for each.
Carbon Balancer middleware will take any node compatible http server (http, connect, express, ect..) and spawn up several node processes and balance traffic between them. Instead of using node's clusting component, carbon will find open ports available on the system and instruct the webserver to listen on that port.
To use, ensure the the server is the primary
module.export for a given file, and pass that file to the balancer middleware.
var carbon = require'carbon'proxy = carbonlisten8080;var balancer = carbonbalancerpathjoin__dirname 'app.js'host: 'localhost' // requiredwatch: true // optional (defaults to true)maxWorkers: 4 // optional (defaults to hardware cpu count);// for http requestsproxyusebalancermiddleware;// for websocket requestsproxywsbalancermiddleware;
In this example, any traffic that goes to
localhost:8080 will be balanced between several instances of
app.js. Balancer defaults to
the number of CPU cores available on the current machine, but can be adjusted with options. Balancer also, by default, will watch
for changes and restart a new set of workers with no downtime. You can turn this off with the option
Carbon has integrated the fantastic debug module to allow for descriptive debugging. When starting any file that requires
carbon, include the
DEBUG environment variable to get robust CLI output:
DEBUG=carbon:* node proxy.js
Interested in contributing? Fork to get started. Contact @logicalparadox if you are interested in being regular contributor.
Carbon was inspired by these modules:
(The MIT License)
Copyright (c) 2012 Jake Luer firstname.lastname@example.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.