Example #1
0
        public async Task <ExecutionResult <EventChannel> > CreateChannel(string name, bool fifo, int maxLifeTimeSubscriber, int maxLifeTimeMessage)
        {
            if (_diagnosticSource.IsEnabled($"{nameof(CreateChannel)}"))
            {
                _diagnosticSource.Write($"{nameof(CreateChannel)}", name);
            }

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                return(await _eventChannelRepository.RegisterChannelAsync(new EventChannel
                {
                    Name = name,
                    Key = Guid.NewGuid().ToString(),
                    MaxLifeTimeMessage = maxLifeTimeMessage,
                    MaxLifeTimeSubscriber = maxLifeTimeSubscriber,
                    IsFifo = fifo
                }));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"{nameof(CreateChannel)} {name} failed");
                throw;
            }
            finally
            {
                stopwatch.Stop();
                _logger.LogTrace($"{nameof(CreateChannel)}:Ends in {stopwatch.Elapsed}");
            }
        }
        public static EventChannel AddChannel(IEventChannelService channelService, int timeout = 30)
        {
            EventChannel channel;

            //Act
            var executionGetResult = channelService.GetChannelAsync(x => x.Name == "TestChannel").Result;

            executionGetResult.Should().NotBeNull();
            executionGetResult.IsSuccessful.Should().BeTrue();

            if (executionGetResult.Result == null)
            {
                var executionResult = channelService.RegisterChannelAsync(new EventChannel
                {
                    IsFifo                = true,
                    Key                   = Guid.NewGuid().ToString(),
                    Name                  = "TestChannel",
                    MaxLifeTimeMessage    = timeout,
                    MaxLifeTimeSubscriber = timeout
                }).Result;

                executionResult.Should().NotBeNull();
                executionResult.IsSuccessful.Should().BeTrue();

                channel = executionResult.Result;
            }
            else
            {
                channel = executionGetResult.Result;
            }

            channel.Should().NotBeNull();

            return(channel);
        }