public IRpcChannel CreateChannel(RpcConnectionInfo connectionInfo, IRpcClientOptions?options)
        {
            var scheme = connectionInfo?.HostUrl?.Scheme;

            if (scheme == LightweightTcpScheme)
            {
                var proxyGenerator = LightweightProxyGenerator.Default;

                return(new TcpRpcConnection(
                           connectionInfo !,
                           this.authenticationOptions,
                           ImmutableRpcClientOptions.Combine(options, this.options),
                           proxyGenerator,
                           this.lightweightOpions));
            }

            if (scheme == WellKnownRpcSchemes.LightweightPipe)
            {
                var proxyGenerator = LightweightProxyGenerator.Default;

                return(new NamedPipeRpcConnection(
                           connectionInfo !,
                           ImmutableRpcClientOptions.Combine(options, this.options),
                           proxyGenerator,
                           this.lightweightOpions));
            }

            throw new ArgumentException("Unsupported connection info. Use CanCreateConnection to check whether a connection can be created.");
        }
Ejemplo n.º 2
0
 private static void AssertOptions(RpcClientOptions options, ImmutableRpcClientOptions actualOptions)
 {
     Assert.AreEqual(options.CallTimeout, actualOptions.CallTimeout);
     Assert.AreEqual(options.ReceiveMaxMessageSize, actualOptions.ReceiveMaxMessageSize);
     Assert.AreEqual(options.SendMaxMessageSize, actualOptions.SendMaxMessageSize);
     Assert.AreEqual(options.StreamingCallTimeout, actualOptions.StreamingCallTimeout);
     Assert.AreEqual(options.Serializer, actualOptions.Serializer);
 }
        public IRpcChannel CreateChannel(RpcConnectionInfo connectionInfo, IRpcClientOptions?options)
        {
            if (connectionInfo?.HostUrl?.Scheme == WellKnownRpcSchemes.Grpc)
            {
                var proxyGenerator = GrpcProxyGenerator.Default;

                return(new NetGrpcConnection(connectionInfo, ImmutableRpcClientOptions.Combine(this.options, options), proxyGenerator, this.channelOptions));
            }

            throw new ArgumentException("Unsupported connection info. Use CanCreateConnection to check whether a connection can be created.");
        }
Ejemplo n.º 4
0
        public void GlobalSetup()
        {
            var serverId            = RpcServerId.NewId();
            var definitionsProvider = new RpcServiceDefinitionsBuilder();
            // var serializer = new JsonRpcSerializer();
            var serializer    = new ProtobufRpcSerializer(RuntimeTypeModel.Create());
            var serverOptions = new RpcServerOptions {
                Serializer = serializer
            };

            this.clientOptions = new RpcClientOptions {
                Serializer = serializer
            }.AsImmutable();

            switch (this.ConnectionType)
            {
            //case RpcConnectionType.LightweightInproc:
            //    {
            //        var connector = new InprocRpcConnector(clientOptions);
            //        this.server = new LightweightRpcServer(serverId, definitionsProvider, null, serverOptions);
            //        this.server.AddEndPoint(connector.EndPoint);
            //        this.server.ServicePublisher.PublishSingleton<ISimpleService>(new SimpleServiceImpl());
            //        this.server.Start();

            //        //this.clientConnection = connector.Connection;
            //        //clientService = this.clientConnection.GetServiceSingleton<ISimpleServiceClient>();
            //        break;
            //    }
            case RpcConnectionType.LightweightTcp:
            {
                this.server = new LightweightRpcServer(serverId, definitionsProvider, null, serverOptions);
                this.server.AddEndPoint(new TcpRpcEndPoint("127.0.0.1", 50051, false));
                this.server.ServicePublisher.PublishSingleton <ISimpleService>(new SimpleServiceImpl());
                this.server.Start();

                this.connectionInfo = new RpcConnectionInfo(new Uri("lightweight.tcp://localhost:50051"));
                break;
            }

            case RpcConnectionType.LightweightNamedPipe:
            {
                this.server = new LightweightRpcServer(serverId, definitionsProvider, null, serverOptions);
                this.server.AddEndPoint(new NamedPipeRpcEndPoint("RpcBenchmark"));
                this.server.ServicePublisher.PublishSingleton <ISimpleService>(new SimpleServiceImpl());
                this.server.Start();

                this.connectionInfo = new RpcConnectionInfo(new Uri($"{WellKnownRpcSchemes.LightweightPipe}://./RpcBenchmark"));
                break;
            }
            }
        }
Ejemplo n.º 5
0
        protected override IRpcConnectionProvider CreateConnectionProvider(ImmutableRpcClientOptions options)
        {
            switch (this.ConnectionType)
            {
            case RpcConnectionType.LightweightTcp:
                return(new Rpc.Lightweight.Client.LightweightConnectionProvider(options));

            case RpcConnectionType.LightweightSslTcp:
                return(new Rpc.Lightweight.Client.LightweightConnectionProvider(TestCertificates.SslClientOptions, options));

            default:
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 6
0
 protected override IRpcConnectionProvider CreateConnectionProvider(ImmutableRpcClientOptions options)
 {
     return(new GrpcConnectionProvider(options));
 }
Ejemplo n.º 7
0
 protected abstract IRpcConnectionProvider CreateConnectionProvider(ImmutableRpcClientOptions options);