summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/thrift/lib/nodejs/examples
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/thrift/lib/nodejs/examples
parentInitial commit. (diff)
downloadceph-upstream/16.2.11+ds.tar.xz
ceph-upstream/16.2.11+ds.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/thrift/lib/nodejs/examples')
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/Makefile24
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/README.md40
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/client.js49
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/client_multitransport.js58
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/hello.html65
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/hello.js63
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/hello.thrift27
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/httpClient.js23
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/httpServer.js31
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/httpServer.py20
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/parse.js46
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/server.js39
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/server_http.js53
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/server_multitransport.js46
-rw-r--r--src/jaegertracing/thrift/lib/nodejs/examples/user.thrift27
15 files changed, 611 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/Makefile b/src/jaegertracing/thrift/lib/nodejs/examples/Makefile
new file mode 100644
index 000000000..87157db63
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/Makefile
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# 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.
+all:
+ ../../../compiler/cpp/thrift --gen js:node user.thrift
+
+server: all
+ NODE_PATH=../lib:../lib/thrift:$(NODE_PATH) node server.js
+
+client: all
+ NODE_PATH=../lib:../lib/thrift:$(NODE_PATH) node client.js
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/README.md b/src/jaegertracing/thrift/lib/nodejs/examples/README.md
new file mode 100644
index 000000000..7350c10c9
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/README.md
@@ -0,0 +1,40 @@
+# Thrift Node.js Examples
+
+## License
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ 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.
+
+## Running the user example
+
+Generate the bindings:
+
+ ../../../compiler/cpp/thrift --gen js:node user.thrift
+ ../../../compiler/cpp/thrift --gen js:node --gen py hello.thrift
+
+To run the user example, first start up the server in one terminal:
+
+ NODE_PATH=../lib:../lib/thrift node server.js
+
+Now run the client:
+
+ NODE_PATH=../lib:../lib/thrift node client.js
+
+For an example using JavaScript in the browser to connect to
+a node.js server look at hello.html, hello.js and hello.thrift
+
+HTTP examples are provided also: httpClient.js and httpServer.js
+You can test HTTP cross platform with the httpServer.py Python server
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/client.js b/src/jaegertracing/thrift/lib/nodejs/examples/client.js
new file mode 100644
index 000000000..c83b34234
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/client.js
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * 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');
+
+var UserStorage = require('./gen-nodejs/UserStorage.js'),
+ ttypes = require('./gen-nodejs/user_types');
+
+var connection = thrift.createConnection('localhost', 9090),
+ client = thrift.createClient(UserStorage, connection);
+
+var user = new ttypes.UserProfile({uid: 1,
+ name: "Mark Slee",
+ blurb: "I'll find something to put here."});
+
+connection.on('error', function(err) {
+ console.error(err);
+});
+
+client.store(user, function(err, response) {
+ if (err) {
+ console.error(err);
+ } else {
+ console.log("client stored:", user.uid);
+ client.retrieve(user.uid, function(err, responseUser) {
+ if (err) {
+ console.error(err);
+ } else {
+ console.log("client retrieved:", responseUser.uid);
+ connection.end();
+ }
+ });
+ }
+});
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/client_multitransport.js b/src/jaegertracing/thrift/lib/nodejs/examples/client_multitransport.js
new file mode 100644
index 000000000..1e37de32f
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/client_multitransport.js
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * 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; }
+
+ console.log("stored:", user1.uid, " as ", user1.name);
+ b_client.retrieve(user1.uid, function(err, responseUser) {
+ if (err) { console.error(err); return; }
+ console.log("retrieved:", responseUser.uid, " as ", responseUser.name);
+ });
+});
+
+b_client.store(user2, function(err, response) {
+ if (err) { console.error(err); return; }
+
+ console.log("stored:", user2.uid, " as ", user2.name);
+ f_client.retrieve(user2.uid, function(err, responseUser) {
+ if (err) { console.error(err); return; }
+ console.log("retrieved:", responseUser.uid, " as ", responseUser.name);
+ });
+});
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/hello.html b/src/jaegertracing/thrift/lib/nodejs/examples/hello.html
new file mode 100644
index 000000000..fe85a7e9d
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/hello.html
@@ -0,0 +1,65 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * 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.
+-->
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Apache Thrift JavaScript Browser Client Demo</title>
+ <script src="thrift.js" type="text/javascript"></script>
+ <script src="gen-js/HelloSvc.js" type="text/javascript"></script>
+ <script src="gen-js/TimesTwo.js" type="text/javascript"></script>
+</head>
+<body>
+ <h1>Apache Thrift JavaScript Browser Client Demo</h1>
+ <p>This html file demonstrates Apache Thrift JavaScrpt RPC between a browser client to a node.js server. Clicking the buttons below will call the RPC functions hosted by the Apache Thrift server at localhost:8585. The file hello.js contains the JavaScript node.js server required. Here are the steps to get the example running:</p>
+ <ol>
+ <li>Install Node.js <pre><a href="http://nodejs.org">nodejs.org</a></pre></li>
+ <li>Install Apache Thrift for node (note that the node package manager will create the node_modules folder in the current directory so make sure to run npm from the same directory as hello.js so that the server can find the Thrift libraries. This example requires Apache Thrift 0.9.2+) <pre>$ npm install thrift</pre></li>
+ <li>Compile the hello.idl for JavaScript and Node.js (you'll need to have the Apache Thrift compiler installed for this step. This also needs to be executed in the same directory as hello.js because hello.js and hello.html look for the gen-nodejs and gen-js directories here.)<pre>$ thrift -gen js -gen js:node hello.thrift</pre></li>
+ <li>Run the node server in the directory with the hello.html file<pre>$ node hello.js</pre></li>
+ <li>Copy the Apache Thrift JavaScript library, thrift.js, into the directory with this html file.<pre>$ cp ...../thrift.js . (you should be able to use Bower to install the browser based Apache Thrift library in the near future.)</pre>
+ <li>Reload this page in a browser through the node server using using the URL: <pre>http://localhost:8585/hello.html</pre>then click a button below to make an RPC call</li>
+ </ol>
+ <button id="btn">Get Message from Node Server</button>
+ <button id="btnDbl">Double 25</button>
+ <script type="text/javascript">
+ document.getElementById("btn").addEventListener("click", getMessage, false);
+
+ function getMessage() {
+ var transport = new Thrift.TXHRTransport("http://localhost:8585/hello");
+ var protocol = new Thrift.TJSONProtocol(transport);
+ var client = new HelloSvcClient(protocol);
+ var msg = client.hello_func();
+ document.getElementById("output").innerHTML = msg;
+ }
+
+ document.getElementById("btnDbl").addEventListener("click", dblMessage, false);
+
+ function dblMessage() {
+ var transport = new Thrift.TXHRTransport("http://localhost:8585/dbl");
+ var protocol = new Thrift.TJSONProtocol(transport);
+ var client = new TimesTwoClient(protocol);
+ var val = client.dbl(25);
+ document.getElementById("output2").innerHTML = val;
+ }
+ </script>
+ <h2>Server Response: <div id="output"></div></h2>
+ <h2>Server Dbl: <div id="output2"></div></h2>
+</body>
+</html>
+
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/hello.js b/src/jaegertracing/thrift/lib/nodejs/examples/hello.js
new file mode 100644
index 000000000..8b7c4e4ea
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/hello.js
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * 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');
+var HelloSvc = require('./gen-nodejs/HelloSvc.js');
+var TimesTwoSvc = require('./gen-nodejs/TimesTwo.js');
+
+var helloHandler = {
+ hello_func: function(result) {
+ this.call_counter = this.call_counter || 0;
+ console.log("Client call: " + (++this.call_counter));
+ result(null, "Hello Apache Thrift for JavaScript " + this.call_counter);
+ }
+}
+
+var timesTwoHandler = {
+ dbl: function(val, result) {
+ console.log("Client call: " + val);
+ result(null, val * 2);
+ }
+}
+
+var helloService = {
+ transport: thrift.TBufferedTransport,
+ protocol: thrift.TJSONProtocol,
+ processor: HelloSvc,
+ handler: helloHandler
+};
+
+var dblService = {
+ transport: thrift.TBufferedTransport,
+ protocol: thrift.TJSONProtocol,
+ processor: TimesTwoSvc,
+ handler: timesTwoHandler
+};
+
+var ServerOptions = {
+ files: ".",
+ services: {
+ "/hello": helloService,
+ "/dbl": dblService,
+ }
+}
+
+var server = thrift.createWebServer(ServerOptions);
+var port = 8585;
+server.listen(port);
+console.log("Http/Thrift Server running on port: " + port);
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/hello.thrift b/src/jaegertracing/thrift/lib/nodejs/examples/hello.thrift
new file mode 100644
index 000000000..deaf5a5f9
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/hello.thrift
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * 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.
+ */
+service HelloSvc {
+ string hello_func(),
+}
+
+service TimesTwo {
+ i64 dbl(1: i64 val),
+}
+
+
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/httpClient.js b/src/jaegertracing/thrift/lib/nodejs/examples/httpClient.js
new file mode 100644
index 000000000..19cc0c362
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/httpClient.js
@@ -0,0 +1,23 @@
+var thrift = require('thrift');
+var helloSvc = require('./gen-nodejs/HelloSvc.js');
+
+var options = {
+ transport: thrift.TBufferedTransport,
+ protocol: thrift.TJSONProtocol,
+ path: "/hello",
+ headers: {"Connection": "close"},
+ https: false
+};
+
+var connection = thrift.createHttpConnection("localhost", 9090, options);
+var client = thrift.createHttpClient(helloSvc, connection);
+
+connection.on("error", function(err) {
+ console.log("Error: " + err);
+});
+
+client.hello_func(function(error, result) {
+ console.log("Msg from server: " + result);
+});
+
+
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/httpServer.js b/src/jaegertracing/thrift/lib/nodejs/examples/httpServer.js
new file mode 100644
index 000000000..acae1369a
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/httpServer.js
@@ -0,0 +1,31 @@
+var thrift = require('thrift');
+var helloSvc = require('./gen-nodejs/HelloSvc');
+
+//ServiceHandler: Implement the hello service
+var helloHandler = {
+ hello_func: function (result) {
+ console.log("Received Hello call");
+ result(null, "Hello from Node.js");
+ }
+};
+
+//ServiceOptions: The I/O stack for the service
+var helloSvcOpt = {
+ handler: helloHandler,
+ processor: helloSvc,
+ protocol: thrift.TJSONProtocol,
+ transport: thrift.TBufferedTransport
+};
+
+//ServerOptions: Define server features
+var serverOpt = {
+ services: {
+ "/hello": helloSvcOpt
+ }
+}
+
+//Create and start the web server
+var port = 9090;
+thrift.createWebServer(serverOpt).listen(port);
+console.log("Http/Thrift Server running on port: " + port);
+
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/httpServer.py b/src/jaegertracing/thrift/lib/nodejs/examples/httpServer.py
new file mode 100644
index 000000000..76e9f4aa3
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/httpServer.py
@@ -0,0 +1,20 @@
+import sys
+sys.path.append('gen-py')
+
+from hello import HelloSvc
+from thrift.protocol import TJSONProtocol
+from thrift.server import THttpServer
+
+
+class HelloSvcHandler:
+ def hello_func(self):
+ print("Hello Called")
+ return "hello from Python"
+
+
+processor = HelloSvc.Processor(HelloSvcHandler())
+protoFactory = TJSONProtocol.TJSONProtocolFactory()
+port = 9090
+server = THttpServer.THttpServer(processor, ("localhost", port), protoFactory)
+print "Python server running on port " + str(port)
+server.serve()
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/parse.js b/src/jaegertracing/thrift/lib/nodejs/examples/parse.js
new file mode 100644
index 000000000..168a1aeea
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/parse.js
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * 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.
+ */
+/**
+
+ This is a standalone deserialize/parse example if you just want to deserialize
+ thrift decoupled from cassandra server
+
+ 1. acquire thrift template specification files from who ever built it (eg: EXAMPLE.thrift)
+
+ 2. Install thrift on local machine
+
+ 3. generate thrift clients for nodejs using template specification files (#1)
+ thrift --gen js:node schema/EXAMPLE.thrift
+
+ This creates creates gen-node.js directory containing a new file, GENERATED.js
+
+ 4. Inside GENERATED.js is a class you will want to instanciate. Find this class name and plug
+ it into the example code below (ie, "YOUR_CLASS_NAME")
+ */
+
+function parseThrift(thriftEncodedData, callback) {
+ var thrift = require('thrift');
+ var transport = new thrift.TFramedTransport(thriftEncodedData);
+ var protocol = new thrift.TBinaryProtocol(transport);
+
+ var clientClass = require('../gen-nodejs/GENERATED').YOUR_CLASS_NAME;
+ var client = new clientClass();
+ client.read(protocol);
+ callback(null, client);
+}
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/server.js b/src/jaegertracing/thrift/lib/nodejs/examples/server.js
new file mode 100644
index 000000000..1c482fe71
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/server.js
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * 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');
+
+var UserStorage = require('./gen-nodejs/UserStorage.js'),
+ ttypes = require('./gen-nodejs/user_types');
+
+var users = {};
+
+var server = thrift.createServer(UserStorage, {
+ store: function(user, result) {
+ console.log("server stored:", user.uid);
+ users[user.uid] = user;
+ result(null);
+ },
+
+ retrieve: function(uid, result) {
+ console.log("server retrieved:", uid);
+ result(null, users[uid]);
+ },
+});
+
+server.listen(9090);
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/server_http.js b/src/jaegertracing/thrift/lib/nodejs/examples/server_http.js
new file mode 100644
index 000000000..ef2dc83a2
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/server_http.js
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * 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 connect = require('connect');
+var thrift = require('thrift');
+
+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_http = thrift.createHttpServer(UserStorage, {
+ store: store,
+ retrieve: retrieve
+});
+server_http.listen(9090);
+
+var server_connect = connect(thrift.httpMiddleware(UserStorage, {
+ store: store,
+ retrieve: retrieve
+}));
+server_http.listen(9091);
+
+var server_connect_json = connect(thrift.httpMiddleware(UserStorage, {
+ store: store,
+ retrieve: retrieve
+}, {protocol: thrift.TJSONProtocol}));
+server_connect_json.listen(9092);
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/server_multitransport.js b/src/jaegertracing/thrift/lib/nodejs/examples/server_multitransport.js
new file mode 100644
index 000000000..a348e6847
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/server_multitransport.js
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * 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 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);
diff --git a/src/jaegertracing/thrift/lib/nodejs/examples/user.thrift b/src/jaegertracing/thrift/lib/nodejs/examples/user.thrift
new file mode 100644
index 000000000..d087fd442
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/nodejs/examples/user.thrift
@@ -0,0 +1,27 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# 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.
+
+struct UserProfile {
+ 1: i32 uid,
+ 2: string name,
+ 3: string blurb
+}
+
+service UserStorage {
+ void store(1: UserProfile user),
+ UserProfile retrieve(1: i32 uid)
+}