How to use the thrift.createServer 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 MZMonster / node-thrift-service / lib / server.js View on Github external
}).then(() => {

        // after inital all and start thrift server
        self._server = thrift.createServer(self._innerThriftProcessor, self._innerHandler, self._serverOptions || {});
        self._server.listen(self._port);

        // inital service
        if (self._custom) {
          return self._publish(options.thrift.alias,
            {host: self._host, port: self._port, actions: false},
            utils.TTL);
        } else {
          self.add = self._add;
          // inital service
          return self._add(options.services);
        }

      }).then(() => {
        // emit listening
github apache / thrift / test / nodejs / server.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 Thrift = thrift.Thrift;
var ttransport = require('transport');

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


var server = thrift.createServer(ThriftTest, {
  testVoid: function(result) {
    console.log('testVoid()');
    result(null);
  },

  testString: function(thing, result) {
    console.log('testString(\'' + thing + '\')');
    result(null, thing);
  },

  testByte: function(thing, result) {
    console.log('testByte(' + thing + ')');
    result(null, thing);
  },

  testI32: function(thing, result) {
github aaalgo / donkey / demo / qbic-node / thriftServer.js View on Github external
var thrift = require("thrift");
var Donkey = require('./gen-nodejs/Donkey');
var ttypes = require('./gen-nodejs/donkey_types');

var server = thrift.createServer(Donkey, {
    search: 
    function(q, result) {
console.log("@thrift server search: "+JSON.stringify(q));
        var now=new Date();
        var time=now.toTimeString()+" ";
        var data = [];
        if(q.url=="error"){
		
            var ex=new ttypes.Exception();
                ex.what=0;
    ex.why="intended error";
            result(ex);
        }else{
            for(i=0;i<500;i++){
		var hit=new ttypes.Hit();
		hit.key=time+i;
github ruijieguo / firtex2 / external / thrift / lib / nodejs / examples / server_multitransport.js View on Github external
var UserStorage = require('./gen-nodejs/UserStorage'),
    ttypes = require('./gen-nodejs/user_types');

var users = {};

var store = function(user, result) {
  console.log("stored:", user.uid);
  users[user.uid] = user;
  result(null);
};
var retrieve = function(uid, result) {
  console.log("retrieved:", uid);
  result(null, users[uid]);
};

var server_framed = thrift.createServer(UserStorage, {
  store: store,
  retrieve: retrieve
});
server_framed.listen(9090);
var server_buffered = thrift.createServer(UserStorage, {
 store: store,
 retrieve: retrieve
}, {transport: ttransport.TBufferedTransport});
server_buffered.listen(9091);
github apache / thrift / tutorial / nodejs / NodeServer.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 Calculator = require("./gen-nodejs/Calculator");
var ttypes = require("./gen-nodejs/tutorial_types");
var SharedStruct = require("./gen-nodejs/shared_types").SharedStruct;

var data = {};

var server = thrift.createServer(Calculator, {
  ping: function(result) {
    console.log("ping()");
    result(null);
  },

  add: function(n1, n2, result) {
    console.log("add(", n1, ",", n2, ")");
    result(null, n1 + n2);
  },

  calculate: function(logid, work, result) {
    console.log("calculate(", logid, ",", work, ")");

    var val = 0;
    if (work.op == ttypes.Operation.ADD) {
      val = work.num1 + work.num2;
github wadey / node-thrift / examples / server.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 UserStorage = require('./gen-nodejs/UserStorage.js'),
    ttypes = require('./gen-nodejs/user_types');

var users = {};

var server = thrift.createServer(UserStorage, {
  store: function(user, success) {
    console.log("server stored:", user.uid);
    users[user.uid] = user;
    success();
  },

  retrieve: function(uid, success) {
    console.log("server retrieved:", uid);
    success(users[uid]);
  },
});

server.listen(9090);
github facebook / fbthrift / thrift / perf / node / MultiplexServer.js View on Github external
newdata = "";
    for (var i=0; i < bytes; i++) {
      newdata.concat("x");
    }
    callback(null, newdata);
  },
  echo : function(data, callback) {
    callback(null, data);
  },
  add : function(a, b, callback) {
    callback(null, a + b);
  }
};

if (options.server == "multiplex") {
  var app = thrift.createServer(
    LoadTest,
    methods,
    {transport: ttransport.TFramedTransport}
  );
  app.on('error', function(error) {
    console.warn(error);
  });
  app.listen(options.port, '::');
} else if (options.server == "cpp") {
  var server = new ThriftServer(LoadTest, methods);
  if (options.ssl_cert && options.ssl_key) {
    var config = new ThriftServer.SSLConfig();
    config.certPath = options.ssl_cert;
    config.keyPath = options.ssl_key;
    if (options.ticket_file) {
      config.ticketFilePath = options.ticket_file;
github ruijieguo / firtex2 / external / thrift / lib / nodejs / examples / server_multitransport.js View on Github external
var store = function(user, result) {
  console.log("stored:", user.uid);
  users[user.uid] = user;
  result(null);
};
var retrieve = function(uid, result) {
  console.log("retrieved:", uid);
  result(null, users[uid]);
};

var server_framed = thrift.createServer(UserStorage, {
  store: store,
  retrieve: retrieve
});
server_framed.listen(9090);
var server_buffered = thrift.createServer(UserStorage, {
 store: store,
 retrieve: retrieve
}, {transport: ttransport.TBufferedTransport});
server_buffered.listen(9091);
github thecolorblue / Murray-CMS / examples / combo / interfaces / thrift / index.js View on Github external
module.exports = function(settings) {
	var server = thrift.createServer(Address, module.exports.methods);

	server.listen(settings.port);
};
github creditkarma / thrift-server / packages / thrift-integration / src / apache-calculator-service.ts View on Github external
},
        fetchThing(): CommonStruct {
            return new CommonStruct({
                code: new Code({ status: 5 }),
                value: 'test',
            })
        },
        fetchUnion(): CommonUnion {
            return new CommonUnion({ option1: 'test' })
        },
        broken(): void {
            throw new Error(`Yeah, this didn't work`)
        },
    }

    return thrift.createServer(
        Calculator.Processor,
        impl,
        {
            transport: thrift.TFramedTransport,
        },
    )
}