Пример #1
0
        public GrpcTransportProvider(IGrpcHostConfiguration hostConfiguration, IGrpcTopologyConfiguration topologyConfiguration)
        {
            _hostConfiguration     = hostConfiguration;
            _topologyConfiguration = topologyConfiguration;

            _messageFabric = new MessageFabric();

            _nodeCollection = new NodeCollection(this, _messageFabric);
            _clients        = new List <IGrpcClient>();

            var transport = new GrpcTransportService(this, _hostConfiguration, _nodeCollection);

            _server = new Server(GetChannelOptions())
            {
                Services = { TransportService.BindService(transport) },
                Ports    = { new ServerPort(hostConfiguration.BaseAddress.Host, hostConfiguration.BaseAddress.Port, ServerCredentials.Insecure) }
            };

            var serverPort = _server.Ports.First();

            HostAddress = new UriBuilder(_hostConfiguration.BaseAddress)
            {
                Host = serverPort.Host,
                Port = serverPort.BoundPort
            }.Uri;

            HostNodeContext = new HostNodeContext(HostAddress);

            _hostNode = new GrpcHostNode(_messageFabric, HostNodeContext);

            var observer = new NodeMessageFabricObserver(_nodeCollection, _hostNode);

            _messageFabric.ConnectMessageFabricObserver(observer);

            _startupTask = new Lazy <Task>(() => Task.Run(() => Startup()));
        }