How to use the thrift.createConnection function in thrift

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
* 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 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 cdapio / cdap / server / api_wrapper.js View on Github external
req.on('end', function() {

			console.log('final file size: ' + body.length);

			var conn = thrift.createConnection('127.0.0.1', 45000, {
				transport: ttransport.TFramedTransport,
				protocol: tprotocol.TBinaryProtocol
			});
			conn.on('error', function (error) {
				console.log('FARService: THRIFT ERROR', error);
			});
			
			var FAR = thrift.createClient(FARService, conn);
			FAR.init(auth_token, new flowservices_types.ResourceInfo({
				'filename': filename,
				'size': body.length,
				'modtime': new Date().getTime()
			}), function (error, resource_identifier) {
				if (error) {

				} else {
github ripple / ripple-data-api / api / library / hbase / hbase-thrift / index.js View on Github external
function openNewSocket(i) {
    var server = self._servers[i || 0];

    //create new connection
    connection = thrift.createConnection(server.host, server.port, {
      transport : thrift.TFramedTransport,
      protocol  : thrift.TBinaryProtocol,
      timeout   : self._timeout
    });


    //handle errors
    connection.error = function (err) {
      this.connected = false;

      //execute any callbacks, then delete
      if (this.client) {
        for (var key in this.client._reqs) {
          this.client._reqs[key](err);
          delete (this.client._reqs[key]);
        }
github cinchapi / concourse / concourse-driver-node-js / src / client / index.js View on Github external
return new Promise((resolve, reject) => {
    Object.defineProperty(this, 'connection', {
      value: thrift.createConnection(this.host, this.port, {
        protocol: thrift.TBinaryProtocol,
        transport: thrift.TBufferedTransport
      })
    })
    this.connection.on('error', (error) => {
      error = new Client.ConnectionError({
        host: this.host,
        originalError: error,
        port: this.port
      })
      reject(error)
    })
    Object.defineProperty(this, 'client', {
      value: thrift.createClient(ConcourseThriftService.Client, this.connection)
    })
    this.connection.on('connect', () => {
github creditkarma / Mimic / packages / mimic-thrift / src / provider.ts View on Github external
iclient = (action, callback) => {
        try {
          const {request: {args, func, host, port}} = action;
          const connection = createConnection(host, port, {
            transport: ThriftProvider.transports[transport],
            protocol: ThriftProvider.protocols[protocol],
          });
          connection.on("error", (error) => {
            callback(error, action);
          });
          const client: any = createClient(api[service], connection);
          action.request.time = Date.now();
          client[func](args, (error: any, success: any) => {
            callback(null, {...action, response: {error, success, time: Date.now()}});
          });
        } catch (error) {
          callback(error, action);
        }
      };
    }