| T Jake Luciani | 0c124bb | 2011-01-08 03:49:16 +0000 | [diff] [blame] | 1 | # Licensed to the Apache Software Foundation (ASF) under one |
| 2 | # or more contributor license agreements. See the NOTICE file |
| 3 | # distributed with this work for additional information |
| 4 | # regarding copyright ownership. The ASF licenses this file |
| 5 | # to you under the Apache License, Version 2.0 (the |
| 6 | # "License"); you may not use this file except in compliance |
| 7 | # with the License. You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, |
| 12 | # software distributed under the License is distributed on an |
| 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | # KIND, either express or implied. See the License for the |
| 15 | # specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | |
| 19 | NOTE: you must use the framed thrift transport, TFramedTransport in most |
| 20 | implementations, on the server side. Using a popular example, this is enabled |
| 21 | by default in Cassandra 0.7 (but configuration must be changed in Cassandra |
| 22 | 0.6.x and earlier). |
| 23 | |
| 24 | ## Install |
| 25 | |
| 26 | npm install thrift |
| 27 | |
| 28 | ## Thrift Compiler |
| 29 | |
| 30 | You can compile nodejs sources by running the following: |
| 31 | |
| 32 | thrift --gen js:node thrift_file |
| 33 | |
| 34 | ## Cassandra Client Example: |
| 35 | |
| 36 | Here is a Cassandra example: |
| 37 | |
| 38 | var thrift = require('thrift'), |
| 39 | Cassandra = require('./gen-nodejs/Cassandra') |
| 40 | ttypes = require('./gen-nodejs/cassandra_types'); |
| 41 | |
| 42 | var connection = thrift.createConnection("localhost", 9160), |
| 43 | client = thrift.createClient(Cassandra, connection); |
| 44 | |
| 45 | connection.on('error', function(err) { |
| 46 | console.error(err); |
| 47 | }); |
| 48 | |
| 49 | client.get_slice("Keyspace", "key", new ttypes.ColumnParent({column_family: "ExampleCF"}), new ttypes.SlicePredicate({slice_range: new ttypes.SliceRange({start: '', finish: ''})}), ttypes.ConsistencyLevel.ONE, function(err, data) { |
| 50 | if (err) { |
| 51 | // handle err |
| 52 | } else { |
| 53 | // data == [ttypes.ColumnOrSuperColumn, ...] |
| 54 | } |
| 55 | connection.end(); |
| 56 | }); |
| 57 | |
| 58 | ## Custom client and server example |
| 59 | |
| 60 | An example based on the one shown on the Thrift front page is included in the examples/ folder. |