]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/tutorial/nodejs/NodeClient.js
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / tutorial / nodejs / NodeClient.js
CommitLineData
f67539c2
TL
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20var thrift = require('thrift');
21var Calculator = require('./gen-nodejs/Calculator');
22var ttypes = require('./gen-nodejs/tutorial_types');
23const assert = require('assert');
24
25var transport = thrift.TBufferedTransport;
26var protocol = thrift.TBinaryProtocol;
27
28var connection = thrift.createConnection("localhost", 9090, {
29 transport : transport,
30 protocol : protocol
31});
32
33connection.on('error', function(err) {
34 assert(false, err);
35});
36
37// Create a Calculator client with the connection
38var client = thrift.createClient(Calculator, connection);
39
40
41client.ping(function(err, response) {
42 console.log('ping()');
43});
44
45
46client.add(1,1, function(err, response) {
47 console.log("1+1=" + response);
48});
49
50
51work = new ttypes.Work();
52work.op = ttypes.Operation.DIVIDE;
53work.num1 = 1;
54work.num2 = 0;
55
56client.calculate(1, work, function(err, message) {
57 if (err) {
58 console.log("InvalidOperation " + err);
59 } else {
60 console.log('Whoa? You know how to divide by zero?');
61 }
62});
63
64work.op = ttypes.Operation.SUBTRACT;
65work.num1 = 15;
66work.num2 = 10;
67
68client.calculate(1, work, function(err, message) {
69 console.log('15-10=' + message);
70
71 client.getStruct(1, function(err, message){
72 console.log('Check log: ' + message.value);
73
74 //close the connection once we're done
75 connection.end();
76 });
77});