Exemplo 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();
        }
Exemplo 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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
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();
 }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
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.");
        }
Exemplo n.º 11
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();
        }