Beispiel #1
0
        public IObservable <TResponse> CreateRequestResponseOperation <TRequest, TResponse>(string operationName, TRequest request, bool waitForSuitableService = false)
        {
            return(Observable.Create <TResponse>(o =>
            {
                _log.Info("Creating request response operation");
                var disposables = new CompositeDisposable();
                disposables.Add(
                    // we only take one as once we've found a service we use that for the remainder of the operation,
                    // if there are errors, a higher level service will deal with how to retry
                    _serviceInstanceStreamCache.GetServiceWithMinLoad(waitForSuitableService)
                    .Take(1)
                    .Subscribe(serviceInstanceStatus =>
                {
                    if (!serviceInstanceStatus.IsConnected)
                    {
                        o.OnError(new InvalidOperationException("Disconnected"));
                    }

                    var remoteProcedure = $"{serviceInstanceStatus.ServiceId}.{operationName}";
                    _log.Info($"Will use service instance [{serviceInstanceStatus}] for request response operation");
                    disposables.Add(
                        _connection
                        .RequestResponse <TRequest, TResponse>(remoteProcedure, request)
                        .Subscribe(o)
                        );
                }, o.OnError)
                    );
                return disposables;
            }));
        }