Пример #1
0
        public void Request(Envelope <TRequest> envelope, IResponseReceiver <TResponse> request)
        {
            var thread = _workerPool.GetDispatcher(_threadId, false);

            if (thread == null)
            {
                request.SetNoResponse();
                return;
            }

            var responseWaiter = new DispatchableRequest <TRequest, TResponse>(_func, envelope, Id, request);

            thread.DispatchAction(responseWaiter);
        }
Пример #2
0
        public void Request <TRequest, TResponse>(string topic, Envelope <TRequest> envelope, IResponseReceiver <TResponse> request)
        {
            Assert.ArgumentNotNull(envelope, nameof(envelope));
            Assert.ArgumentNotNull(request, nameof(request));

            var topicEnvelope = envelope.RedirectToTopic(topic);
            var listener      = _store.GetListener <TRequest, TResponse>(topic);

            if (listener == null)
            {
                _logger.Debug($"No listener configured for RequestType={typeof(TRequest).Name} ResponseType={typeof(TResponse).Name} Topic={topic}");
                request.SetNoResponse();
                return;
            }
            if (!listener.CanHandle(envelope))
            {
                request.SetNoResponse();
                return;
            }

            _logger.Debug("Requesting RequestType={0} ResponseType={1} Topic={2} to listener Id={3}", typeof(TRequest).FullName, typeof(TResponse).FullName, envelope.Topics.FirstOrDefault(), listener.Id);
            try
            {
                listener.Request(topicEnvelope, request);
            }
            catch (Exception e)
            {
                _logger.Error($"Error on request Type={typeof(TRequest).FullName}, {typeof(TResponse).FullName} Topic={topic}, Listener Id={listener.Id}: {e.Message}\n{e.StackTrace}");
                request.SetError(e);
            }

            if (listener.ShouldStopListening)
            {
                _store.RemoveListener(topic, listener);
            }
        }
 public void SetNoResponse()
 {
     _inner.SetNoResponse();
 }