Beispiel #1
0
        public static void FistTest()
        {
            Console.WriteLine("Thrift2 Demo");
            Console.WriteLine("This demo assumes you have a table called \"example\" with a column family called \"family1\"");

            String host    = "hserver";
            int    port    = 9090;
            int    timeout = 10000;
            var    framed  = false;

            TTransport transport = new TSocket(host, port, timeout);

            if (framed)
            {
                transport = new TFramedTransport(transport);
            }
            TProtocol protocol = new TBinaryProtocol(transport);

            // This is our thrift client.
            THBaseService.Iface client = new THBaseService.Client(protocol);

            // open the transport
            transport.Open();

            var table = "t1".ToBytes();

            TPut put = new TPut();

            put.Row = ("row1".ToBytes());

            for (var i = 0; i < 1000; i++)
            {
                TColumnValue columnValue = new TColumnValue();
                columnValue.Family    = ("f1".ToBytes());
                columnValue.Qualifier = ("qualifier" + i).ToBytes();
                columnValue.Value     = ("value" + i).ToBytes();
                List <TColumnValue> columnValues = new List <TColumnValue>();
                columnValues.Add(columnValue);
                put.ColumnValues = columnValues;

                client.put(table, put);
            }

            TGet get = new TGet();

            get.Row = ("row1".ToBytes());

            TResult result = client.get(table, get);

            Console.WriteLine("row = " + result.Row.ToStr());
            foreach (TColumnValue resultColumnValue in result.ColumnValues)
            {
                Console.WriteLine("family = " + resultColumnValue.Family.ToStr());
                Console.WriteLine("qualifier = " + resultColumnValue.Qualifier.ToStr());
                Console.WriteLine("value = " + resultColumnValue.Value.ToStr());
                Console.WriteLine("timestamp = " + resultColumnValue.Timestamp);
            }

            transport.Close();
        }
Beispiel #2
0
        static async Task RunClient()
        {
            TClientTransport clientTransport = null;

            try
            {
                CancellationToken token = new CancellationToken();
                clientTransport = new TSocketClientTransport(IPAddress.Loopback, 9090);
                TProtocol protocol = new TBinaryProtocol(clientTransport);
                var       client   = new THBaseService.Client(protocol);
                await client.OpenTransportAsync(token);

                byte[] table = Encoding.UTF8.GetBytes("test");
                byte[] row1  = Encoding.UTF8.GetBytes("row1");
                byte[] cos   = Encoding.UTF8.GetBytes("a");
                TGet   get   = new TGet();
                get.Row = row1;
                var regs = await client.getAllRegionLocationsAsync(table, new CancellationToken());

                var rlist = await client.getMultipleAsync(table, new List <TGet> {
                    new TGet(row1)
                }, new CancellationToken());

                TResult reslut = await client.getAsync(table, get, new CancellationToken());

                //print results
                Console.WriteLine("RowKey:\n{0}", Encoding.UTF8.GetString(reslut.Row));
                foreach (var k in reslut.ColumnValues)
                {
                    Console.WriteLine("Family:Qualifier:" + "\n" + Encoding.UTF8.GetString(k.Family) + ":" + Encoding.UTF8.GetString(k.Qualifier));
                    Console.WriteLine("Value:" + Encoding.UTF8.GetString(k.Value));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                clientTransport?.Close();
            }
        }