Exemple #1
0
        public async Task Consume(ConsumeContext <SetConcurrencyLimit> context)
        {
            if (_id == null || _id.Equals(context.Message.Id, StringComparison.OrdinalIgnoreCase))
            {
                if (context.Message.Timestamp >= _lastUpdated)
                {
                    try
                    {
                        await _router.SetConcurrencyLimit(context.Message.ConcurrencyLimit).ConfigureAwait(false);

                        _lastUpdated = context.Message.Timestamp;

                        await context.RespondAsync <ConcurrencyLimitUpdated>(new
                        {
                            Timestamp = DateTime.UtcNow,
                            context.Message.Id,
                            context.Message.ConcurrencyLimit
                        }).ConfigureAwait(false);

                        LogContext.Debug?.Log("Set Consumer Limit: {ConcurrencyLimit} ({CommandId})", context.Message.ConcurrencyLimit, context.Message.Id);
                    }
                    catch (Exception exception)
                    {
                        LogContext.Error?.Log(exception, "Set Consumer Limit failed: {ConcurrencyLimit} ({CommandId})", context.Message.ConcurrencyLimit,
                                              context.Message.Id);

                        throw;
                    }
                }
                else
                {
                    throw new CommandException("The concurrency limit was updated after the command was sent.");
                }
            }
        }
            public async Task Send(EventContext <CircuitBreakerOpened> context, IPipe <EventContext <CircuitBreakerOpened> > next)
            {
                await Console.Out.WriteLineAsync("Changing concurrency limit in response to circuit breaker");

                await _router.SetConcurrencyLimit(1);

                await next.Send(context);
            }
Exemple #3
0
        public async Task Consume(ConsumeContext <SetConcurrencyLimit> context)
        {
            if (_id == null || _id.Equals(context.Message.Id, StringComparison.OrdinalIgnoreCase))
            {
                if (context.Message.Timestamp >= _lastUpdated)
                {
                    try
                    {
                        await _router.SetConcurrencyLimit(context.Message.ConcurrencyLimit).ConfigureAwait(false);

                        _lastUpdated = context.Message.Timestamp;

                        await context.RespondAsync <ConcurrencyLimitUpdated>(new
                        {
                            Timestamp = DateTime.UtcNow,
                            context.Message.Id,
                            context.Message.ConcurrencyLimit
                        }).ConfigureAwait(false);

                        if (_log.IsDebugEnabled)
                        {
                            _log.Debug($"Set Consumer Limit: {context.Message.ConcurrencyLimit} ({context.Message.Id ?? ""})");
                        }
                    }
                    catch (Exception exception)
                    {
                        if (_log.IsErrorEnabled)
                        {
                            _log.Error($"Set Consumer Limit Failed: {context.Message.ConcurrencyLimit} ({context.Message.Id})", exception);
                        }

                        throw;
                    }
                }
                else
                {
                    throw new CommandException($"The concurrency limit was updated after the command was sent.");
                }
            }
        }