Skip to content
No description or website provided.
JavaScript Other
Latest commit 1db6bc9 Jul 1, 2016 @Raynos Raynos 3.8.0
Failed to load latest commit information.
as support baseAppHeaders in as/json and as/thrift May 27, 2016
benchmarks (c) 2016 Apr 4, 2016
bin (c) 2016 Apr 4, 2016
docs add docs Jun 14, 2016
examples (c) 2016 Apr 4, 2016
hyperbahn (c) 2016 Apr 4, 2016
lib (c) 2016 Apr 4, 2016
scripts (c) 2016 Apr 4, 2016
tcollector (c) 2016 Apr 4, 2016
test Renamed filePath to peerFile. Jun 13, 2016
trace (c) 2016 Apr 4, 2016
v1 (c) 2016 Apr 4, 2016
v2 (c) 2016 Apr 4, 2016
.eslintignore v2/tracing: fix lint Dec 14, 2015
.eslintrc eslint: add global to valid globals Jan 25, 2016
.gitignore Ignore all of re-rooted node Jul 22, 2015
.istanbul.yml be more lenient Sep 16, 2015
.travis.yml Revert "Merge pull request #124 from uber/write_buffer" Oct 26, 2015
CHANGELOG.md 3.7.0 May 16, 2016
CONTRIBUTION.md Add 'node/' from commit 'fd45eeb1ef28342613cad0f5567f2d4ed5f8427a' Feb 28, 2015
LICENSE Add 'node/' from commit 'fd45eeb1ef28342613cad0f5567f2d4ed5f8427a' Feb 28, 2015
MIGRATION.md update MIGRATION Sep 16, 2015
Makefile remove cruft from Makefile Sep 24, 2015
README.md docs: add stability badges everywhere Jun 20, 2015
argstream.js (c) 2016 Apr 4, 2016
channel.js Renamed filePath to peerFile. Jun 13, 2016
connection.js (c) 2016 Apr 4, 2016
docs.jsig Converge on serviceName over service for requests Apr 28, 2015
drain.js (c) 2016 Apr 4, 2016
endpoint-handler.js (c) 2016 Apr 4, 2016
errors.js (c) 2016 Apr 4, 2016
host-port.js (c) 2016 Apr 4, 2016
hyperbahn-client.js (c) 2016 Apr 4, 2016
hyperbahn.thrift Add thrift/discover query to Hyperbahn client Feb 16, 2016
in_request.js timeout should hold until last byte Jul 1, 2016
in_response.js (c) 2016 Apr 4, 2016
lazy_relay.js Add free guard to LazyRelayInReq#onTimeout Jun 3, 2016
mkdocs.yml docs work with github & readthedocs Sep 24, 2015
monitor.js (c) 2016 Apr 4, 2016
null-logger.js (c) 2016 Apr 4, 2016
operations.js (c) 2016 Apr 4, 2016
out_request.js timeout should hold until last byte Jul 1, 2016
out_response.js (c) 2016 Apr 4, 2016
package.json 3.8.0 Jul 1, 2016
peer-file-watcher.js Renamed filePath to peerFile. Jun 13, 2016
peer.js (c) 2016 Apr 4, 2016
peer_heap.js (c) 2016 Apr 4, 2016
peer_score_strategies.js (c) 2016 Apr 4, 2016
peers_base.js (c) 2016 Apr 4, 2016
publish.sh publish: support the CHANGELOG loop Dec 3, 2015
range.js (c) 2016 Apr 4, 2016
relay_handler.js (c) 2016 Apr 4, 2016
reqres_states.js (c) 2016 Apr 4, 2016
request-handler.js (c) 2016 Apr 4, 2016
request.js (c) 2016 Apr 4, 2016
retry-flags.js (c) 2016 Apr 4, 2016
root_peers.js (c) 2016 Apr 4, 2016
service-name-handler.js (c) 2016 Apr 4, 2016
services.js (c) 2016 Apr 4, 2016
stat-tags.js (c) 2016 Apr 4, 2016
streaming_in_request.js (c) 2016 Apr 4, 2016
streaming_in_response.js (c) 2016 Apr 4, 2016
streaming_out_request.js (c) 2016 Apr 4, 2016
streaming_out_response.js (c) 2016 Apr 4, 2016
sub_peers.js (c) 2016 Apr 4, 2016
tag.sh chmod +x tag.sh Oct 21, 2015
time_heap.js (c) 2016 Apr 4, 2016

README.md

TChannel

network multiplexing and framing protocol for RPC

Stability: stable

stable

Example

var TChannel = require('tchannel');

var server = new TChannel();
var client = new TChannel();

var serverChan = server.makeSubChannel({
    serviceName: 'server'
});

// normal response
serverChan.register('func1', function onReq(req, res, arg2, arg3) {
    console.log('func1 responding', { arg2: arg2.toString(), arg3: arg3.toString() });
    res.headers.as = 'raw';
    res.sendOk('result', 'indeed it did');
});

// err response
serverChan.register('func2', function onReq2(req, res) {
    res.headers.as = 'raw';
    res.sendNotOk(null, 'it failed');
});

server.listen(4040, '127.0.0.1', function onListen() {
    var clientChan = client.makeSubChannel({
        serviceName: 'server',
        peers: [server.hostPort],
        requestDefaults: {
            hasNoParent: true,
            headers: { 'as': 'raw', 'cn': 'example-client' }
        }
    });

    clientChan.request({
        serviceName: 'server',
        timeout: 1000
    }).send('func1', 'arg 1', 'arg 2', function onResp(err, res, arg2, arg3) {
        console.log('normal res:', { arg2: arg2.toString(), arg3: arg3.toString() });
    });

    clientChan.request({
        serviceName: 'server'
    }).send('func2', 'arg 1', 'arg 2', function onResp(err, res, arg2, arg3) {
        console.log('err res: ', { ok: res.ok, message: String(arg3) });
    });
});

This example registers two functions on the "server". "func 1" always works and "func 2" always returns an error. The client sends a request for each function, then prints the result.

Note that every instance is bidirectional. New connections are initiated on demand.

Overview

TChannel is a network protocol with the following goals:

  • request / response model
  • multiple requests multiplexed across the same TCP socket
  • out of order responses
  • streaming request and responses
  • all frames checksummed
  • transport arbitrary payloads
  • easy to implement in multiple languages
  • near-redis performance

This protocol is intended to run on datacenter networks for inter-process communication.

Protocol

TChannel frames have a fixed length header and 3 variable length fields. The underlying protocol does not assign meaning to these fields, but the included client/server implementation uses the first field to represent a unique endpoint or function name in an RPC model. The next two fields can be used for arbitrary data. Some suggested way to use the 3 fields are:

  • URI path, HTTP method and headers as JSON, body
  • function name, headers, thrift / protobuf

Note however that the only encoding supported by TChannel is UTF-8. If you want JSON, you'll need to stringify and parse outside of TChannel.

This design supports efficient routing and forwarding of data where the routing information needs to parse only the first or second field, but the 3rd field is forwarded without parsing.

There is no notion of client and server in this system. Every TChannel instance is capable of making or receiving requests, and thus requires a unique port on which to listen. This requirement may change in the future.

Performance

On a Macbook Pro, we see around 50,000 ops/sec from a single node process talking to one other node process.

Documentation

See the docs folder.

Further examples

See the examples folder

Installation

npm install tchannel

Tests

npm test

Contributors

  • mranney
  • jwolski
  • Raynos
  • jcorbin
  • kriskowal
  • shannili
  • rf

MIT Licenced

Something went wrong with that request. Please try again.