How to use thrift - 10 common examples

To help you get started, we’ve selected a few thrift examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apache / thrift / test / nodejs / client.js View on Github external
* under the License.
 */

//Client test for the following I/O stack:
//    TBinaryProtocol
//    TFramedTransport
//    TSocket

var assert = require('assert');
var thrift = require('thrift');
var TFramedTransport = require('thrift/transport').TFramedTransport;
var ThriftTest = require('./gen-nodejs/ThriftTest');
var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;

var connection = thrift.createConnection('localhost', 9090, { transport: TFramedTransport} );
var client = thrift.createClient(ThriftTest, connection);

connection.on('error', function(err) {
  assert(false, err);
});

ThriftTestDriver(client, function (status) {
  console.log(status);
  connection.end();
});

// to make it also run on expresso
exports.expressoTest = function() {};
github apache / thrift / test / nodejs / client.js View on Github external
* specific language governing permissions and limitations
 * under the License.
 */

//Client test for the following I/O stack:
//    TBinaryProtocol
//    TFramedTransport
//    TSocket

var assert = require('assert');
var thrift = require('thrift');
var TFramedTransport = require('thrift/transport').TFramedTransport;
var ThriftTest = require('./gen-nodejs/ThriftTest');
var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;

var connection = thrift.createConnection('localhost', 9090, { transport: TFramedTransport} );
var client = thrift.createClient(ThriftTest, connection);

connection.on('error', function(err) {
  assert(false, err);
});

ThriftTestDriver(client, function (status) {
  console.log(status);
  connection.end();
});

// to make it also run on expresso
exports.expressoTest = function() {};
github apache / thrift / test / nodejs / multiplex_client.js View on Github external
* Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var thrift = require('thrift');
var ttransport = require('transport');
var assert = require('assert');

var ThriftTest = require('./gen-nodejs/ThriftTest'),
    SecondService = require('./gen-nodejs/SecondService'),
    ttypes = require('./gen-nodejs/ThriftTest_types');

var connection = thrift.createConnection('localhost', 9090, {
    'transport': ttransport.TFramedTransport
});

var mp = new thrift.Multiplexer();

client = mp.createClient("ThriftTest", ThriftTest, connection);
secondclient = mp.createClient("SecondService", SecondService, connection);

connection.on('error', function(err) {
    assert(false, err);
});

// deepEqual doesn't work with fields using node-int64

function checkRecursively(map1, map2) {
    if (typeof map1 !== 'function' && typeof map2 !== 'function') {
github wadey / node-thrift / examples / client_multitransport.js View on Github external
var thrift = require('thrift'),
    ttransport = require('thrift/transport');

var UserStorage = require('./gen-nodejs/UserStorage'),
    ttypes = require('./gen-nodejs/user_types');

var f_conn = thrift.createConnection('localhost', 9090), // default: framed
    f_client = thrift.createClient(UserStorage, f_conn);
var b_conn = thrift.createConnection('localhost', 9091, {transport: ttransport.TBufferedTransport}),
    b_client = thrift.createClient(UserStorage, b_conn);
var user1 = new ttypes.UserProfile({uid: 1,
                                    name: "Mark Slee",
                                    blurb: "I'll find something to put here."});
var user2 = new ttypes.UserProfile({uid: 2,
                                    name: "Satoshi Tagomori",
                                    blurb: "ok, let's test with buffered transport."});

f_conn.on('error', function(err) {
  console.error("framed:", err);
});

f_client.store(user1, function(err, response) {
  if (err) { console.error(err); return; }

  console.log("stored:", user1.uid, " as ", user1.name);
  b_client.retrieve(user1.uid, function(err, responseUser) {
github wadey / node-thrift / examples / client_multitransport.js View on Github external
var thrift = require('thrift'),
    ttransport = require('thrift/transport');

var UserStorage = require('./gen-nodejs/UserStorage'),
    ttypes = require('./gen-nodejs/user_types');

var f_conn = thrift.createConnection('localhost', 9090), // default: framed
    f_client = thrift.createClient(UserStorage, f_conn);
var b_conn = thrift.createConnection('localhost', 9091, {transport: ttransport.TBufferedTransport}),
    b_client = thrift.createClient(UserStorage, b_conn);
var user1 = new ttypes.UserProfile({uid: 1,
                                    name: "Mark Slee",
                                    blurb: "I'll find something to put here."});
var user2 = new ttypes.UserProfile({uid: 2,
                                    name: "Satoshi Tagomori",
                                    blurb: "ok, let's test with buffered transport."});

f_conn.on('error', function(err) {
  console.error("framed:", err);
});

f_client.store(user1, function(err, response) {
  if (err) { console.error(err); return; }

  console.log("stored:", user1.uid, " as ", user1.name);
github cdapio / cdap / web-app / server / common / node_modules / thrift / examples / client_multitransport.js View on Github external
*   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var thrift = require('thrift'),
    ttransport = require('thrift/transport');

var UserStorage = require('./gen-nodejs/UserStorage'),
    ttypes = require('./gen-nodejs/user_types');

var f_conn = thrift.createConnection('localhost', 9090), // default: framed
    f_client = thrift.createClient(UserStorage, f_conn);
var b_conn = thrift.createConnection('localhost', 9091, {transport: ttransport.TBufferedTransport}),
    b_client = thrift.createClient(UserStorage, b_conn);
var user1 = new ttypes.UserProfile({uid: 1,
                                    name: "Mark Slee",
                                    blurb: "I'll find something to put here."});
var user2 = new ttypes.UserProfile({uid: 2,
                                    name: "Satoshi Tagomori",
                                    blurb: "ok, let's test with buffered transport."});

f_conn.on('error', function(err) {
  console.error("framed:", err);
});

f_client.store(user1, function(err, response) {
  if (err) { console.error(err); return; }
github apache / thrift / tutorial / nodejs / NodeClient.js View on Github external
* software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

var thrift = require('thrift');
var Calculator = require('./gen-nodejs/Calculator');
var ttypes = require('./gen-nodejs/tutorial_types');


var transport = thrift.TBufferedTransport;
var protocol = thrift.TBinaryProtocol;

var connection = thrift.createConnection("localhost", 9090, {
  transport : transport,
  protocol : protocol
});

connection.on('error', function(err) {
  assert(false, err);
});

// Create a Calculator client with the connection
var client = thrift.createClient(Calculator, connection);


client.ping(function(err, response) {
  console.log('ping()');
});
github node-pinus / pinus / packages / pinus-rpc / sample / thrift / client.js View on Github external
* Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

var thrift = require('thrift');
// var ThriftTransports = require('thrift/transport');
// var ThriftProtocols = require('thrift/protocol');
var Calculator = require('./gen-nodejs/Calculator');
var ttypes = require('./gen-nodejs/tutorial_types');


transport = thrift.TBufferedTransport()
protocol = thrift.TBinaryProtocol()

var connection = thrift.createConnection("127.0.0.1", 9090, {
  transport : transport,
  protocol : protocol
});

connection.on('error', function(err) {
  console.error(false, err);
});

// Create a Calculator client with the connection
var client = thrift.createClient(Calculator, connection);

var num_requests = 20000;
var times = 0;
github moleculerjs / moleculer / src / serializers / thrift.js View on Github external
init(broker) {
		super.init(broker);

		try {
			const Thrift = require("thrift");
			this.TBufferedTransport = Thrift.TBufferedTransport;
			this.TBinaryProtocol = Thrift.TBinaryProtocol;

			const transport = new Thrift.TBufferedTransport(null, (res) => this.serialized = res);
			this.protocol = new Thrift.TBinaryProtocol(transport);

		} catch(err) {
			/* istanbul ignore next */
			this.broker.fatal("The 'thrift' package is missing! Please install it with 'npm install thrift --save' command!", err, true);
		}

		this.packets = require("./thrift/gen-nodejs/packets_types.js");
	}
github cdapio / cdap / web-app / server / common / node_modules / thrift / examples / client_multitransport.js View on Github external
* Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var thrift = require('thrift'),
    ttransport = require('thrift/transport');

var UserStorage = require('./gen-nodejs/UserStorage'),
    ttypes = require('./gen-nodejs/user_types');

var f_conn = thrift.createConnection('localhost', 9090), // default: framed
    f_client = thrift.createClient(UserStorage, f_conn);
var b_conn = thrift.createConnection('localhost', 9091, {transport: ttransport.TBufferedTransport}),
    b_client = thrift.createClient(UserStorage, b_conn);
var user1 = new ttypes.UserProfile({uid: 1,
                                    name: "Mark Slee",
                                    blurb: "I'll find something to put here."});
var user2 = new ttypes.UserProfile({uid: 2,
                                    name: "Satoshi Tagomori",
                                    blurb: "ok, let's test with buffered transport."});

f_conn.on('error', function(err) {
  console.error("framed:", err);
});

f_client.store(user1, function(err, response) {
  if (err) { console.error(err); return; }

  console.log("stored:", user1.uid, " as ", user1.name);