예제 #1
0
        public TransportClient(IMessageSender messageSender, IMessageListener messageListener,
                               IServiceExecutor serviceExecutor, ILogger logger)
        {
            var serviceExecutor1 = serviceExecutor;

            _messageSender   = messageSender;
            _messageListener = messageListener;
            _logger          = logger;

            messageListener.Received += async(sender, message) =>
            {
                if (!_resultDictionary.TryGetValue(message.Id, out var task))
                {
                    return;
                }

                if (message.IsInvokeResultMessage())
                {
                    var content = message.GetContent <RemoteInvokeResultMessage>();
                    if (!string.IsNullOrEmpty(content.ExceptionMessage))
                    {
                        task.TrySetException(new RpcRemoteException(content.ExceptionMessage));
                    }
                    else
                    {
                        task.SetResult(message);
                    }
                }

                if (serviceExecutor1 != null && message.IsInvokeMessage())
                {
                    await serviceExecutor1.ExecuteAsync(sender, message);
                }
            };
        }
예제 #2
0
 protected ServiceHostAbstract(IServiceExecutor serviceExecutor)
 {
     MessageListener.Received += async(sender, message) =>
     {
         await serviceExecutor.ExecuteAsync(sender, message);
     };
 }
예제 #3
0
 /// <summary>
 /// Inject dependent third-party components
 /// </summary>
 /// <param name="builder"></param>
 protected override void RegisterBuilder(ContainerBuilderWrapper builder)
 {
     base.RegisterBuilder(builder);
     builder.Register(provider =>
     {
         IServiceExecutor serviceExecutor = null;
         if (provider.IsRegistered(typeof(IServiceExecutor)))
         {
             serviceExecutor = provider.Resolve <IServiceExecutor>();
         }
         return(new ThriftTransportClientFactory(provider.Resolve <ITransportMessageCodecFactory>(),
                                                 provider.Resolve <IHealthCheckService>(),
                                                 provider.Resolve <ILogger <ThriftTransportClientFactory> >(),
                                                 serviceExecutor));
     }).As(typeof(ITransportClientFactory)).SingleInstance();
     builder.Register(provider =>
     {
         return(new DefaultThriftServiceEntryProvider(
                    provider.Resolve <IServiceEntryProvider>(),
                    provider.Resolve <ILogger <DefaultThriftServiceEntryProvider> >(),
                    provider.Resolve <CPlatformContainer>()
                    ));
     }).As(typeof(IThriftServiceEntryProvider)).SingleInstance();
     if (AppConfig.ServerOptions.Protocol == CommunicationProtocol.Tcp ||
         AppConfig.ServerOptions.Protocol == CommunicationProtocol.None)
     {
         RegisterDefaultProtocol(builder);
     }
 }
        public DotNettyTransportClientFactory(ITransportMessageCodecFactory codecFactory,
                                              IHealthCheckService healthCheckService, ILogger <DotNettyTransportClientFactory> logger,
                                              IServiceExecutor serviceExecutor)
        {
            _transportMessageEncoder = codecFactory.GetEncoder();
            _transportMessageDecoder = codecFactory.GetDecoder();
            _logger             = logger;
            _healthCheckService = healthCheckService;
            _serviceExecutor    = serviceExecutor;
            _bootstrap          = GetBootstrap();
            _bootstrap.Handler(new ActionChannelInitializer <ISocketChannel>(c =>
            {
                var pipeline = c.Pipeline;
                pipeline.AddLast(new LengthFieldPrepender(4));
                pipeline.AddLast(new LengthFieldBasedFrameDecoder(int.MaxValue, 0, 4, 0, 4));
                if (AppConfig.ServerOptions.EnableHealthCheck)
                {
                    pipeline.AddLast(new IdleStateHandler(0, AppConfig.ServerOptions.HealthCheckWatchIntervalInSeconds, 0));
                    pipeline.AddLast(DotNettyConstants.HeartBeatName, new HeartBeatHandler(_healthCheckService, this));
                }

                pipeline.AddLast(DotNettyConstants.TransportMessageAdapterName,
                                 new TransportMessageChannelHandlerAdapter(_transportMessageDecoder));
                pipeline.AddLast(DotNettyConstants.ClientChannelHandler,
                                 new DefaultChannelHandler(this, healthCheckService));
            }));
        }
예제 #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Client, Hello World!");

            var host = new ServiceHostBuilder()
                       .RegisterServices(builder =>
            {
                builder.RegisterType <MessagePackTransportMessageCodecFactory>().As <ITransportMessageCodecFactory>().SingleInstance();
                builder.RegisterType(typeof(ClientExecutor)).As(typeof(IServiceExecutor)).SingleInstance();
                builder.Register(provider =>
                {
                    IServiceExecutor serviceExecutor = null;
                    if (provider.IsRegistered(typeof(IServiceExecutor)))      // 没有注册客户端接收消息执行器,因此一直为空
                    {
                        serviceExecutor = provider.Resolve <IServiceExecutor>();
                    }
                    return(new DotNettyTransportClientFactory(provider.Resolve <ITransportMessageCodecFactory>(),
                                                              provider.Resolve <ILogger <DotNettyTransportClientFactory> >(),
                                                              serviceExecutor));
                }).As(typeof(ITransportClientFactory)).SingleInstance();
            })
                       .UseStartup <Startup>()
                       .Build();

            using (host.Run())
            {
                Startup.Test();
            }
            Console.ReadLine();
        }
예제 #6
0
 public DotNettyTransportClient(IMessageSender messageSender, IMessageListener messageListener, ILogger logger, IServiceExecutor serviceExecutor)
 {
     _messageSender            = messageSender;
     _messageListener          = messageListener;
     _logger                   = logger;
     _serviceExecutor          = serviceExecutor;
     messageListener.Received += MessageListener_Received;
 }
예제 #7
0
 public TransportClient(IMessageSender messageSender, IMessageListener messageListener, ILogger logger, IServiceExecutor serviceExecutor)
 {
     _messageSender = messageSender;
     _messageListener = messageListener;
     _logger = logger;
     _serviceExecutor = serviceExecutor;
     messageListener.Received += MessageListener_Received;
 }
예제 #8
0
 public DotNettyTransportClientFactory(ISerializer <byte[]> serializer, ISerializer <object> objecSerializer, ILogger <DotNettyTransportClientFactory> logger, IServiceExecutor serviceExecutor)
 {
     _serializer      = serializer;
     _objecSerializer = objecSerializer;
     _logger          = logger;
     _serviceExecutor = serviceExecutor;
     _bootstrap       = GetBootstrap();
 }
 public ThriftTransportClientFactory(ITransportMessageCodecFactory codecFactory, IHealthCheckService healthCheckService, ILogger <ThriftTransportClientFactory> logger, IServiceExecutor serviceExecutor)
 {
     _transportMessageEncoder = codecFactory.GetEncoder();
     _transportMessageDecoder = codecFactory.GetDecoder();
     _logger             = logger;
     _healthCheckService = healthCheckService;
     _serviceExecutor    = serviceExecutor;
 }
예제 #10
0
 public DotNettyTransportClientFactory(ITransportMessageCodecFactory codecFactory, ILogger <DotNettyTransportClientFactory> logger, IServiceExecutor serviceExecutor)
 {
     _transportMessageEncoder = codecFactory.GetEncoder();
     _transportMessageDecoder = codecFactory.GetDecoder();
     _logger          = logger;
     _serviceExecutor = serviceExecutor;
     _bootstrap       = GetBootstrap();
 }
예제 #11
0
 public TransportClient(IMessageSender messageSender, IMessageListener messageListener, ILogger logger, ISerializer <object> objecSerializer, IServiceExecutor serviceExecutor)
 {
     _messageSender            = messageSender;
     _messageListener          = messageListener;
     _logger                   = logger;
     _objecSerializer          = objecSerializer;
     _serviceExecutor          = serviceExecutor;
     messageListener.Received += MessageListener_Received;
 }
예제 #12
0
 public RpcClientProxyInterceptor(IServiceIdGenerator serviceIdGenerator,
                                  IServiceEntryLocator serviceEntryLocator,
                                  ICurrentServiceKey currentServiceKey,
                                  IServiceExecutor serviceExecutor)
 {
     _serviceIdGenerator  = serviceIdGenerator;
     _serviceEntryLocator = serviceEntryLocator;
     _currentServiceKey   = currentServiceKey;
     _serviceExecutor     = serviceExecutor;
 }
예제 #13
0
 public TransportClient(IMessageSender messageSender, IMessageListener messageListener, ILogger logger,
                        IServiceExecutor serviceExecutor)
 {
     _diagnosticListener       = new DiagnosticListener(DiagnosticListenerExtensions.DiagnosticListenerName);
     _messageSender            = messageSender;
     _messageListener          = messageListener;
     _logger                   = logger;
     _serviceExecutor          = serviceExecutor;
     messageListener.Received += MessageListener_Received;
 }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultHttpServiceHost" /> class.
 /// </summary>
 /// <param name="messageListenerFactory">The message listener factory.</param>
 /// <param name="serviceExecutor">The service executor.</param>
 /// <param name="httpMessageListener">The HTTP message listener.</param>
 public DefaultHttpServiceHost(Func <EndPoint, Task <IMessageListener> > messageListenerFactory,
                               IServiceExecutor serviceExecutor, HttpMessageListener httpMessageListener) : base(serviceExecutor)
 {
     _messageListenerFactory          = messageListenerFactory;
     _serverMessageListener           = httpMessageListener;
     _serverMessageListener.Received += async(sender, message) =>
     {
         await Task.Run(() => { MessageListener.OnReceived(sender, message); });
     };
 }
예제 #15
0
 public HttpMessageReceivedHandler(IParameterParser parameterParser,
                                   ISerializer serializer,
                                   IOptions <RpcOptions> rpcOptions,
                                   IServiceExecutor serviceExecutor)
     : base(parameterParser,
            serializer,
            rpcOptions,
            serviceExecutor)
 {
 }
예제 #16
0
 protected MessageReceivedHandlerBase(
     IParameterParser parameterParser,
     ISerializer serializer,
     IOptions <RpcOptions> rpcOptions,
     IServiceExecutor serviceExecutor)
 {
     _parameterParser = parameterParser;
     _serializer      = serializer;
     _serviceExecutor = serviceExecutor;
     _rpcOptions      = rpcOptions.Value;
 }
예제 #17
0
 public WsMessageReceivedHandler(IParameterParser parameterParser,
                                 ISerializer serializer,
                                 IOptions <RpcOptions> rpcOptions,
                                 IServiceExecutor serviceExecutor,
                                 IRemoteServiceInvoker remoteServiceInvoker,
                                 IOptions <GovernanceOptions> governanceOptions)
     : base(parameterParser,
            serializer,
            rpcOptions,
            serviceExecutor)
 {
 }
예제 #18
0
        public MoleculerService(ILogger <MoleculerService> logger, IApplicationLifetime appLifetime, ITransporter transporter, LocalActionServicesLoader localServices, IServiceExecutor executor, IServiceLocator serviceLocator)
        {
            _logger         = logger;
            _appLifetime    = appLifetime;
            _transporter    = transporter;
            _localServices  = localServices;
            _executor       = executor;
            _serviceLocator = serviceLocator;

            _serviceInfo = new ServiceInfo();
            FillHostInfo();
        }
예제 #19
0
 public DotNettyTransportClientFactory(ITransportMessageCodecFactory codecFactory, ILogger <DotNettyTransportClientFactory> logger, IServiceExecutor serviceExecutor)
 {
     _transportMessageEncoder = codecFactory.GetEncoder();
     _transportMessageDecoder = codecFactory.GetDecoder();
     _logger          = logger;
     _serviceExecutor = serviceExecutor;
     _bootstrap       = GetBootstrap();
     _bootstrap.Handler(new ActionChannelInitializer <ISocketChannel>(c =>
     {
         var pipeline = c.Pipeline;
         pipeline.AddLast(new LengthFieldPrepender(4));
         pipeline.AddLast(new LengthFieldBasedFrameDecoder(int.MaxValue, 0, 4, 0, 4));
         pipeline.AddLast(new TransportMessageChannelHandlerAdapter(_transportMessageDecoder));
         pipeline.AddLast(new DefaultChannelHandler(this));
     }));
 }
 public DotNettyTransportClientFactory(ITransportMessageCodecFactory codecFactory, ILogger <DotNettyTransportClientFactory> logger, IServiceExecutor serviceExecutor)
 {
     _transportMessageEncoder = codecFactory.GetEncoder();
     _transportMessageDecoder = codecFactory.GetDecoder();
     _logger          = logger;
     _serviceExecutor = serviceExecutor;
     //_bootstrap = GetBootstrap();
     //_bootstrap.Handler(new ActionChannelInitializer<ISocketChannel>(c =>
     //{
     //    var pipeline = c.Pipeline;
     //    pipeline.AddLast(
     //        new IdleStateHandler(0, 4, 0),
     //        this.idleStateTrigger,
     //        new ProtocolDecoder(),
     //        encoder,
     //        new TransportMessageChannelHandlerAdapter(_transportMessageDecoder),
     //        new DefaultChannelHandler(this));
     //}));
 }
예제 #21
0
        public static object Create(IServiceExecutor client, Type serviceType)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (!serviceType.IsInterface)
            {
                throw new Exception("Only interface allowed.");
            }

            var gen   = new ProxyGenerator();
            var proxy = gen.CreateInterfaceProxyWithoutTarget(
                serviceType,
                Type.EmptyTypes,
                new ServiceActionInterceptor(client, serviceType));

            return(proxy);
        }
        public static IServiceBuilder UseDotNettyTransport(this IServiceBuilder builder)
        {
            var services = builder.Services;

            services.Register(provider =>
            {
                IServiceExecutor serviceExecutor = null;
                if (provider.IsRegistered(typeof(IServiceExecutor)))
                {
                    serviceExecutor = provider.Resolve <IServiceExecutor>();
                }
                return(new DotNettyTransportClientFactory(provider.Resolve <ITransportMessageCodecFactory>(),
                                                          provider.Resolve <ILogger <DotNettyTransportClientFactory> >(),
                                                          serviceExecutor));
            }).As(typeof(ITransportClientFactory)).SingleInstance();
            if (AppConfig.ServerOptions.Protocol == CommunicationProtocol.Tcp ||
                AppConfig.ServerOptions.Protocol == CommunicationProtocol.None)
            {
                RegisterDefaultProtocol(services);
            }
            return(builder);
        }
예제 #23
0
 public DefaultServiceHost(Func<EndPoint, Task<IMessageListener>> messageListenerFactory, IServiceExecutor serviceExecutor) : base(serviceExecutor)
 {
     _messageListenerFactory = messageListenerFactory;
 }
 public ServiceFactoryConvention(IServiceExecutor executor)
 {
     _executor = executor;
 }
 public TradeFacade()
 {
     this.serviceExecutor = new ServiceExecutor();
 }
예제 #26
0
 public SimpleTransportClientFactory(ITransportMessageCodecFactory transportMessageCodecFactory, ILogger<SimpleTransportClientFactory> logger, IServiceExecutor serviceExecutor)
 {
     _transportMessageCodecFactory = transportMessageCodecFactory;
     _logger = logger;
     _serviceExecutor = serviceExecutor;
 }
예제 #27
0
 public CrudEventsExecutor(IServiceExecutor serviceExecutor, Func <string, Type> typeResolver) : base(serviceExecutor, typeResolver)
 {
 }
 public LoginFacade()
 {
     this.serviceExecutor = new ServiceExecutor();
 }
예제 #29
0
 public RpcGateway(ServiceStackHost appHost, IServiceExecutor executor)
 {
     AppHost  = appHost ?? throw new ArgumentNullException(nameof(appHost));
     Executor = executor ?? throw new ArgumentNullException(nameof(executor));
 }
예제 #30
0
 protected ServiceHostAbstract(IServiceExecutor serviceExecutor)
 {
     _serviceExecutor = serviceExecutor;
     MessageListener.Received += MessageListener_Received;
 }
예제 #31
0
 public DotNettyServiceHost(IServiceExecutor serviceExecutor, ILogger <DotNettyServiceHost> logger, ISerializer <byte[]> serializer) : base(serviceExecutor)
 {
     _logger     = logger;
     _serializer = serializer;
 }
 public ProductListingHandler(ILogger <ProductListingHandler> logger,
                              IServiceExecutor serviceExecutor)
 {
     _logger          = logger;
     _serviceExecutor = serviceExecutor;
 }
예제 #33
0
 public ServiceActionInterceptor(IServiceExecutor executor, Type serviceType)
 {
     _executor    = executor;
     _serviceType = serviceType;
 }
예제 #34
0
 public FileTransfer(IServiceExecutor<IFileTransferService> serviceExecutor)
 {
     _serviceExecutor = serviceExecutor;
 }
예제 #35
0
 public SimpleTransportClientFactory(ITransportMessageCodecFactory transportMessageCodecFactory, ILogger <SimpleTransportClientFactory> logger, IServiceExecutor serviceExecutor)
 {
     _transportMessageCodecFactory = transportMessageCodecFactory;
     _logger          = logger;
     _serviceExecutor = serviceExecutor;
 }