Roger Meier | 5c819c0 | 2011-04-09 11:10:04 +0000 | [diff] [blame] | 1 | var thrift = require('thrift'), |
| 2 | ttransport = require('thrift/transport'); |
| 3 | |
| 4 | var UserStorage = require('./gen-nodejs/UserStorage'), |
| 5 | ttypes = require('./gen-nodejs/user_types'); |
| 6 | |
| 7 | var f_conn = thrift.createConnection('localhost', 9090), // default: framed |
| 8 | f_client = thrift.createClient(UserStorage, f_conn); |
| 9 | var b_conn = thrift.createConnection('localhost', 9091, {transport: ttransport.TBufferedTransport}), |
| 10 | b_client = thrift.createClient(UserStorage, b_conn); |
| 11 | var user1 = new ttypes.UserProfile({uid: 1, |
| 12 | name: "Mark Slee", |
| 13 | blurb: "I'll find something to put here."}); |
| 14 | var user2 = new ttypes.UserProfile({uid: 2, |
| 15 | name: "Satoshi Tagomori", |
| 16 | blurb: "ok, let's test with buffered transport."}); |
| 17 | |
| 18 | f_conn.on('error', function(err) { |
| 19 | console.error("framed:", err); |
| 20 | }); |
| 21 | |
| 22 | f_client.store(user1, function(err, response) { |
| 23 | if (err) { console.error(err); return; } |
| 24 | |
| 25 | console.log("stored:", user1.uid, " as ", user1.name); |
| 26 | b_client.retrieve(user1.uid, function(err, responseUser) { |
| 27 | if (err) { console.error(err); return; } |
| 28 | console.log("retrieved:", responseUser.uid, " as ", responseUser.name); |
| 29 | }); |
| 30 | }); |
| 31 | |
| 32 | b_client.store(user2, function(err, response) { |
| 33 | if (err) { console.error(err); return; } |
| 34 | |
| 35 | console.log("stored:", user2.uid, " as ", user2.name); |
| 36 | f_client.retrieve(user2.uid, function(err, responseUser) { |
| 37 | if (err) { console.error(err); return; } |
| 38 | console.log("retrieved:", responseUser.uid, " as ", responseUser.name); |
| 39 | }); |
| 40 | }); |