Ejemplo n.º 1
0
        public void ThrifTestMethod1()
        {
            //服务端:开始Thrift rpc服务
            new Thread(() =>
            {
                var processor1 = new HelloThrift.Processor(new HelloThriftHandler());
                TMultiplexedProcessor processor = new TMultiplexedProcessor();
                processor.RegisterProcessor("HelloThriftHandler", processor1);
                var serverTransport = new TServerSocket(9090);
                var server1         = new TThreadedServer(processor, serverTransport);
                Console.WriteLine("向客户端输出服务开启");
                server1.Serve();
            }).Start();

            //客户端:调用服务端的HelloThrift的HelloWorld方法
            TTransport           transport = new TSocket("localhost", 9090);
            TProtocol            protocol  = new TBinaryProtocol(transport);
            TMultiplexedProtocol mp1       = new TMultiplexedProtocol(protocol, "HelloThriftHandler");

            HelloThrift.Client client = new HelloThrift.Client(mp1);
            transport.Open();
            client.HelloWorld();
            client.adding(2, 3);
            Console.WriteLine(client.GetData(1));
            transport.Close();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("PaymentService RPC Server is lunched");

            var transport = new TServerSocket(8885);
            var processor = new PaymentService.Processor(new PaymentServiceImpl());

            var server = new TThreadedServer(processor, transport);

            server.Serve();
        }
        public MockThriftServer()
        {
            _handler = new Handler();
            var processor = new ThriftFlumeEventServer.Processor(_handler);

            _serverTransport = new TServerSocket(9090);
            _server          = new TThreadedServer(processor, _serverTransport);

            _serveOnSeparateThread = new Thread(_server.Serve);
            _serveOnSeparateThread.Start();
        }
Ejemplo n.º 4
0
        static void Main()
        {
            ServiceReal service = GetService();

            THRIFTService.Processor processor       = new THRIFTService.Processor(service);
            TServerTransport        serverTransport = new TServerSocket(9095);
            TServer server = new TThreadedServer(processor, serverTransport);

            Console.WriteLine("Created transport --- Starting server on port 9095");
            server.Serve();
        }
        public static void Main(string[] args)
        {
            Service serv = getService();

            ThriftService.Processor processor = new ThriftService.Processor(serv);
            TServerTransport        st        = new TServerSocket(9090);
            TServer server = new TThreadedServer(processor, st);

            Console.WriteLine("Starting server : listening on port 9090 ....");
            server.Serve();
        }
Ejemplo n.º 6
0
        static internal void Run(int port)
        {
            // check whether the port is free
            TServerTransport serverTransport = new TServerSocket(port);

            serverTransport.Listen();
            serverTransport.Close();
            serverTransport = new TServerSocket(port);

            // one processor to rule them all
            var multiplexProcessor = new TMultiplexedProcessor();

            // create protocol factory, default to "framed binary"
            TProtocolFactory  protocolFactory  = new TBinaryProtocol.Factory(true, true);
            TTransportFactory transportFactory = new TFramedTransport.Factory();

            // create handler/processor for the public service
            Handler handler = new Handler();

            Pizzeria.Processor pizzeria = new Pizzeria.Processor(handler);
            multiplexProcessor.RegisterProcessor(typeof(Pizzeria).Name, pizzeria);

            // create handler/processor for the internal service
            // handler = same
            PizzeriaCallback.Processor callback = new PizzeriaCallback.Processor(handler);
            multiplexProcessor.RegisterProcessor(typeof(PizzeriaCallback).Name, callback);

            // create handler/processor for the diagnostics service
            // handler = same
            Diagnostics.Diagnostics.Processor diagnose = new Diagnostics.Diagnostics.Processor(handler);
            multiplexProcessor.RegisterProcessor(typeof(Diagnostics.Diagnostics).Name, diagnose);

            // more processors as needed ...

            // complete internal setup
            Console.Title = Environment.MachineName + "-" + port.ToString();

            ReadinessHttpServer.Start(PizzaConfig.ReadinessPorts.Pizzeria);
            try
            {
                // return the server instance
                //var server = new TThreadPoolServer(multiplexProcessor, serverTransport, transportFactory, protocolFactory);
                var server = new TThreadedServer(multiplexProcessor, serverTransport, transportFactory, protocolFactory);
                //var server = new TSimpleServer(multiplexProcessor, serverTransport, transportFactory, protocolFactory);

                ReadinessHttpServer.Status = Readiness.AliveAndReady;
                server.Serve();
            }
            finally
            {
                ReadinessHttpServer.Stop();
            }
        }
Ejemplo n.º 7
0
 static void Main(string[] args)
 {
     //开始Thrift rpc服务
     new Thread(() =>
     {
         var processor1 = new HelloThrift.Processor(new HelloThriftHandler());
         TMultiplexedProcessor processor = new TMultiplexedProcessor();
         processor.RegisterProcessor("HelloThriftHandler", processor1);
         var serverTransport = new TServerSocket(9090);
         var server1         = new TThreadedServer(processor, serverTransport);
         Console.WriteLine("向客户端输出服务开启");
         server1.Serve();
     }).Start();
 }
Ejemplo n.º 8
0
        static void Main()
        {
            //TServerSocket serverTransport = new TServerSocket(new System.Net.Sockets.TcpListener(IPAddress.Parse("192.168.43.1"), 25000));
            TServerSocket serverTransport = new TServerSocket(25001, 0, false);
            //异步IO,需要使用TFramedTransport,它将分块缓存读取
            var tfactory = new TFramedTransport.Factory();
            //使用高密度二进制协议
            var pfactory = new TCompactProtocol.Factory();
            TMultiplexedProcessor processor = new TMultiplexedProcessor();

            com.msunsoft.service.calculator.Processor calcProcessor = new com.msunsoft.service.calculator.Processor(new Server());
            processor.RegisterProcessor("test-server-rpc$com.msunsoft.service.calculator$2.0", calcProcessor);
            TThreadedServer server = new TThreadedServer(processor, serverTransport, tfactory, pfactory);

            Console.WriteLine("Starting server on port 25001 ...");
            server.Serve();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            // ITeledonServices service = new Service(new AngajatiDBRepository(), new CazuriDBRepository(), new DonatiiDBRepository(), new DonatoriDBRepository(), new ValidatorCazuri(), new ValidatorDonatii(), new ValidatorDonator());

            /* TeledonServer server = new TeledonServer("127.0.0.1", 55555, service);
             * server.Start();
             * Console.ReadLine();*/
            Console.WriteLine("starting server...");
            RequestHandler teledonHndler = new RequestHandler();

            TeledonService.Processor processor       = new TeledonService.Processor(teledonHndler);
            TServerTransport         serverTransport = new TServerSocket(9090);
            TServer server = new TThreadedServer(processor, serverTransport);

            Console.WriteLine("ready");
            server.Serve();
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            Console.WriteLine("[Welcome] TestService RPC Server is lanuched...");
            TServerTransport transport = new TServerSocket(port);
            var     processor          = new TestService.Processor(new TestServiceImpl());
            TServer server             = new TThreadedServer(processor, transport);

            //多个服务
            //var processor1 = new TestService.Processor(new TestServiceImpl());
            //var processor2 = new Test2ServiceProcessor(new Test2ServiceImpl());
            //var processorMulti = new Thrift.Protocol.TMultiplexedProcessor();
            //processorMulti.RegisterProcessor("Service1", processor1);
            //processorMulti.RegisterProcessor("Service2", processor2);
            //TServer server = new TThreadedServer(processorMulti, transport);

            // lanuch
            server.Serve();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            try
            {
                BirdHandler      handler         = new BirdHandler();
                Flappy.Processor processor       = new Flappy.Processor(handler);
                TServerTransport serverTransport = new TServerSocket(9090);
                TServer          server          = new TThreadedServer(processor, serverTransport);

                // Use this for a multithreaded server
                // server = new TThreadPoolServer(processor, serverTransport);

                Console.WriteLine("Starting the server...");
                server.Serve();
            }
            catch (Exception x)
            {
                Console.WriteLine(x.StackTrace);
            }
            Console.WriteLine("done.");
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            //Start the background mock trade generator thread
            (new Thread(TradeEventGenerator.ThreadProc)).Start();

            //Create the Service Handler and Processor
            TradeStreamHandler handler = new TradeStreamHandler();

            PNWF.TradeStream.Processor proc = new PNWF.TradeStream.Processor(handler);

            //Setup the I/O stack factories
            TServerTransport  trans    = new TNamedPipeServerTransport("TradeStream");
            TTransportFactory transFac = new TTransportFactory();
            TProtocolFactory  protoFac = new TCompactProtocol.Factory();

            //Setup the server and register the event handler
            TServer server = new TThreadedServer(proc, trans, transFac, protoFac);

            server.setEventHandler(new TradeServerEventHandler());
            server.Serve();
        }
Ejemplo n.º 13
0
        public static bool Execute(string[] args)
        {
            try
            {
                bool                 useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false;
                ServerType           serverType           = ServerType.TSimpleServer;
                ProcessorFactoryType processorFactoryType = ProcessorFactoryType.TSingletonProcessorFactory;
                int    port = 9090;
                string pipe = null;
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "-pipe")  // -pipe name
                    {
                        pipe = args[++i];
                    }
                    else if (args[i].Contains("--port="))
                    {
                        port = int.Parse(args[i].Substring(args[i].IndexOf("=") + 1));
                    }
                    else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
                    {
                        useBufferedSockets = true;
                    }
                    else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed")
                    {
                        useFramed = true;
                    }
                    else if (args[i] == "--compact" || args[i] == "--protocol=compact")
                    {
                        compact = true;
                    }
                    else if (args[i] == "--json" || args[i] == "--protocol=json")
                    {
                        json = true;
                    }
                    else if (args[i] == "--threaded" || args[i] == "--server-type=threaded")
                    {
                        serverType = ServerType.TThreadedServer;
                    }
                    else if (args[i] == "--threadpool" || args[i] == "--server-type=threadpool")
                    {
                        serverType = ServerType.TThreadPoolServer;
                    }
                    else if (args[i] == "--prototype" || args[i] == "--processor=prototype")
                    {
                        processorFactoryType = ProcessorFactoryType.TPrototypeProcessorFactory;
                    }
                    else if (args[i] == "--ssl")
                    {
                        useEncryption = true;
                    }
                }

                // Transport
                TServerTransport trans;
                if (pipe != null)
                {
                    trans = new TNamedPipeServerTransport(pipe);
                }
                else
                {
                    if (useEncryption)
                    {
                        string certPath = "../keys/server.p12";
                        trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2(certPath, "thrift"), null, null, SslProtocols.Tls);
                    }
                    else
                    {
                        trans = new TServerSocket(port, 0, useBufferedSockets);
                    }
                }

                TProtocolFactory proto;
                if (compact)
                {
                    proto = new TCompactProtocol.Factory();
                }
                else if (json)
                {
                    proto = new TJSONProtocol.Factory();
                }
                else
                {
                    proto = new TBinaryProtocol.Factory();
                }

                TProcessorFactory processorFactory;
                if (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory)
                {
                    processorFactory = new TPrototypeProcessorFactory <ThriftTest.Processor, TestHandler>();
                }
                else
                {
                    // Processor
                    TestHandler          testHandler   = new TestHandler();
                    ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler);
                    processorFactory = new TSingletonProcessorFactory(testProcessor);
                }

                TTransportFactory transFactory;
                if (useFramed)
                {
                    transFactory = new TFramedTransport.Factory();
                }
                else
                {
                    transFactory = new TTransportFactory();
                }

                TServer serverEngine;
                switch (serverType)
                {
                case ServerType.TThreadPoolServer:
                    serverEngine = new TThreadPoolServer(processorFactory, trans, transFactory, proto);
                    break;

                case ServerType.TThreadedServer:
                    serverEngine = new TThreadedServer(processorFactory, trans, transFactory, proto);
                    break;

                default:
                    serverEngine = new TSimpleServer(processorFactory, trans, transFactory, proto);
                    break;
                }

                //Server event handler
                TradeServerEventHandler serverEvents = new TradeServerEventHandler();
                serverEngine.setEventHandler(serverEvents);

                // Run it
                string where = (pipe != null ? "on pipe " + pipe : "on port " + port);
                Console.WriteLine("Starting the " + serverType.ToString() + " " + where +
                                  (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory ? " with processor prototype factory " : "") +
                                  (useBufferedSockets ? " with buffered socket" : "") +
                                  (useFramed ? " with framed transport" : "") +
                                  (useEncryption ? " with encryption" : "") +
                                  (compact ? " with compact protocol" : "") +
                                  (json ? " with json protocol" : "") +
                                  "...");
                serverEngine.Serve();
            }
            catch (Exception x)
            {
                Console.Error.Write(x);
                return(false);
            }
            Console.WriteLine("done.");
            return(true);
        }