public ScopedServer(TProtocolFactory protocolFactory, object service) { ThriftServiceProcessor processor = new ThriftServiceProcessor(services: service); ThriftServerDef def = new ThriftServerDef(processor, protocolFactory, serverPort: 0); server = new NettyServerTransport(def, new NettyServerConfig(1, 1)); server.StartAsync().GetAwaiter().GetResult(); }
public ServerTester Invoke() { ThriftServiceProcessor processor = new ThriftServiceProcessor(loggerFactory: null, services: new SimpleService()); bossExecutor = new MultithreadEventLoopGroup(1); ioWorkerExecutor = new MultithreadEventLoopGroup(1); ThriftServerDef serverDef = new ThriftServerDef(processor, new TBinaryProtocol.Factory()); NettyServerConfig serverConfig = new NettyServerConfig(bossGroup: bossExecutor, workerGroup: ioWorkerExecutor); Server = new ThriftServer(serverConfig, serverDef); return(this); }
/// <summary> /// 服务启动 /// </summary> /// <returns></returns> internal Task <ThriftyServer> StartAsync() { Contract.Assert(this._config != null && this._config.Port != 0, "swifty server port is null"); Contract.Assert(this._serviceTypes != null && this._serviceTypes.Any(), "No service can be used to start swifty server."); Contract.Assert( this._state == ThriftyServerStatus.Init, "swifty server can not start, the state is out of control"); this._state = ThriftyServerStatus.Starting; Task task; try { ThriftCodecManager thriftCodecManager; thriftCodecManager = this._codescs == null ? new ThriftCodecManager() : new ThriftCodecManager(this._codescs); INiftyProcessor process = new ThriftServiceProcessor( this._serviceLocator, codecManager: thriftCodecManager, eventHandlers: this._handlers, serviceTypes: this._serviceTypes, loggerFactory: this._loggerFactory); this._server = new ThriftServer(process, this._config, _sslConfig, this._loggerFactory); String addres = String.IsNullOrWhiteSpace(_config.BindingAddress) ? "0.0.0.0" : _config.BindingAddress; this._logger.LogDebug($"server is ready for starting: {addres}:{_config.Port}"); task = this._server.StartAsync(); return(task.ContinueWith(t => { if (t.Exception == null) { this._state = ThriftyServerStatus.Running; } this._state = (t.Exception == null) ? ThriftyServerStatus.Running : ThriftyServerStatus.Error; return this; })); } catch (Exception e) { this._state = ThriftyServerStatus.Error; throw new ThriftyException(e.Message); } }
private static void StartServerByAnnotaions() { var factory = new LoggerFactory(); factory.AddConsole(LogLevel.Debug); var processor = new ThriftServiceProcessor(factory, new Thrifty.ScribeTest()); var config = new ThriftServerConfig() { BindingAddress = "0.0.0.0", Port = 9999, IdleConnectionTimeout = TimeSpan.FromMinutes(10), QueueTimeout = TimeSpan.FromMinutes(10), TaskExpirationTimeout = TimeSpan.FromMinutes(10) }; var server = new ThriftServer(processor, config, loggerFactory: factory); server.StartAsync(); }