Exemplo n.º 1
0
        protected async Task SendRequest(BehaviorContext <TInstance> context, ConsumeContext consumeContext, TRequest requestMessage)
        {
            var pipe = new SendRequestPipe(consumeContext.ReceiveContext.InputAddress);

            var endpoint = await consumeContext.GetSendEndpoint(_request.Settings.ServiceAddress).ConfigureAwait(false);

            await endpoint.Send(requestMessage, pipe).ConfigureAwait(false);

            _request.SetRequestId(context.Instance, pipe.RequestId);

            if (_request.Settings.Timeout > TimeSpan.Zero)
            {
                var now            = DateTime.UtcNow;
                var expirationTime = now + _request.Settings.Timeout;

                RequestTimeoutExpired message = new TimeoutExpired(now, expirationTime, context.Instance.CorrelationId, pipe.RequestId);

                MessageSchedulerContext schedulerContext;
                if (_request.Settings.SchedulingServiceAddress != null)
                {
                    var scheduleEndpoint = await consumeContext.GetSendEndpoint(_request.Settings.SchedulingServiceAddress).ConfigureAwait(false);

                    await scheduleEndpoint.ScheduleSend(consumeContext.ReceiveContext.InputAddress, expirationTime, message).ConfigureAwait(false);
                }
                else if (consumeContext.TryGetPayload(out schedulerContext))
                {
                    await schedulerContext.ScheduleSend(expirationTime, message).ConfigureAwait(false);
                }
                else
                {
                    throw new ConfigurationException("A request timeout was specified but no message scheduler was specified or available");
                }
            }
        }
Exemplo n.º 2
0
        private void Handle(TimeoutExpired timeOutEvent)
        {
            //send a RejectClaimRequest command to the bus
            var reject = new RejectClaimRequest
            {
                ClaimRequestId = timeOutEvent.CorrelationId.ToString(),
                Reason         = string.Format("Rejected because the participant did not substantiate the claim within the time allowed.")
            };

            Bus.Publish(reject);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the Elapsed event of the Timer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ElapsedEventArgs"/> instance containing the event data.</param>
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            TimeoutExpired.Trigger(this, new EventArgs());

            resetEvent.Set();

            timer.Stop();
            IsSearching = false;

            lock (listeningClientLock)
            {
                if (listeningClient != null)
                {
                    listeningClient.Dispose();
                    listeningClient = null;
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sends an individual request to the specified service address and records the results.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="consumeContext"></param>
        /// <param name="requestMessage"></param>
        /// <param name="serviceAddress"></param>
        /// <returns></returns>
        protected async Task SendRequest(BehaviorContext <TInstance> context, ConsumeContext consumeContext, TRequest requestMessage, Uri serviceAddress)
        {
            var pipe = new SendRequestPipe(consumeContext.ReceiveContext.InputAddress);

            if (serviceAddress != null)
            {
                // specific service address specfied, send
                var endpoint = await consumeContext.GetSendEndpoint(serviceAddress).ConfigureAwait(false);

                await endpoint.Send(requestMessage, pipe).ConfigureAwait(false);
            }
            else
            {
                // no service address specified, publish
                await consumeContext.Publish(requestMessage, pipe).ConfigureAwait(false);
            }

            // add new state item
            request.Accessor.Insert(context, requestMessage, pipe.RequestId);

            // if a timeout is specified, schedule the timeout expired message
            if (request.Settings.Timeout > TimeSpan.Zero)
            {
                var now            = DateTime.UtcNow;
                var expirationTime = now + request.Settings.Timeout;

                var message = new TimeoutExpired <TRequest>(now, expirationTime, context.Instance.CorrelationId, pipe.RequestId);

                if (consumeContext.TryGetPayload <MessageSchedulerContext>(out var schedulerContext))
                {
                    await schedulerContext.ScheduleSend(expirationTime, message).ConfigureAwait(false);
                }
                else
                {
                    throw new ConfigurationException("A request timeout was specified but no message scheduler was specified or available.");
                }
            }
        }
Exemplo n.º 5
0
        public void Consume(TimeoutExpired message)
        {
            Action <TimeoutExpired> method = x => RemoveTimeoutFromListView(x.CorrelationId, x.Tag);

            BeginInvoke(method, new object[] { message });
        }
Exemplo n.º 6
0
 public void Consume(TimeoutExpired message)
 {
     _cache.Remove(message.CorrelationId);
 }