Beispiel #1
0
        public async Task ExecuteAsync()
        {
            var groupedCandidates = _selector.GetCandidatesMethodsOfGroupNameGrouped(_serviceProvider);

            using (var scope = _serviceProvider.CreateScope())
            {
                var provider = scope.ServiceProvider;

                var messageStore        = provider.GetService <ICapMessageStore>();
                var nextReceivedMessage = await messageStore.GetNextReceivedMessageToBeExcuted();

                if (nextReceivedMessage != null && groupedCandidates.ContainsKey(nextReceivedMessage.Group))
                {
                    try
                    {
                        await messageStore.ChangeReceivedMessageStateAsync(nextReceivedMessage, StatusName.Processing);

                        // If there are multiple consumers in the same group, we will take the first
                        var executeDescriptor = groupedCandidates[nextReceivedMessage.Group][0];
                        var consumerContext   = new ConsumerContext(executeDescriptor, nextReceivedMessage.ToMessageContext());
                        var invoker           = _consumerInvokerFactory.CreateInvoker(consumerContext);
                        await invoker.InvokeAsync();

                        await messageStore.ChangeReceivedMessageStateAsync(nextReceivedMessage, StatusName.Succeeded);
                    }
                    catch (Exception ex)
                    {
                        _logger.ReceivedMessageRetryExecutingFailed(nextReceivedMessage.KeyName, ex);
                    }
                }
            }
        }
Beispiel #2
0
        public void Start()
        {
            var groupingMatches = _selector.GetCandidatesMethodsOfGroupNameGrouped();

            foreach (var matchGroup in groupingMatches)
                Task.Factory.StartNew(() =>
                {
                    using (var client = _consumerClientFactory.Create(matchGroup.Key))
                    {
                        RegisterMessageProcessor(client);

                        client.Subscribe(matchGroup.Value.Select(x => x.Attribute.Name));

                        client.Listening(_pollingDelay, _cts.Token);
                    }
                }, _cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
            _compositeTask = Task.CompletedTask;
        }
Beispiel #3
0
        public void Start()
        {
            _cts = new CancellationTokenSource();

            var groupingMatches = _selector.GetCandidatesMethodsOfGroupNameGrouped();

            foreach (var matchGroup in groupingMatches)
            {
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        using (var client = _consumerClientFactory.Create(matchGroup.Key))
                        {
                            _serverAddress = client.ServersAddress;

                            RegisterMessageProcessor(client);

                            client.Subscribe(matchGroup.Value.Select(x => x.Attribute.Name));

                            client.Listening(_pollingDelay, _cts.Token);
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        //ignore
                    }
                    catch (BrokerConnectionException e)
                    {
                        _isHealthy = false;
                        _logger.LogError(e, e.Message);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, e.Message);
                    }
                }, _cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
            }

            _compositeTask = Task.FromResult(true);
        }
Beispiel #4
0
        public void Start()
        {
            var groupingMatchs = _selector.GetCandidatesMethodsOfGroupNameGrouped(_serviceProvider);

            foreach (var matchGroup in groupingMatchs)
            {
                Task.Factory.StartNew(() =>
                {
                    using (var client = _consumerClientFactory.Create(matchGroup.Key))
                    {
                        RegisterMessageProcessor(client);

                        foreach (var item in matchGroup.Value)
                        {
                            client.Subscribe(item.Attribute.Name);
                        }

                        client.Listening(_pollingDelay);
                    }
                }, _cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Current);
            }
            _compositeTask = Task.CompletedTask;
        }
Beispiel #5
0
 public void Start()
 {
     foreach (KeyValuePair <string, IReadOnlyList <ConsumerExecutorDescriptor> > matchGroup in _selector.GetCandidatesMethodsOfGroupNameGrouped())
     {
         for (int i = 0; i < _options.ConsumerThreadCount; i++)
         {
             Task.Factory.StartNew(delegate
             {
                 try
                 {
                     IConsumerClient consumerClient = _consumerClientFactory.Create(matchGroup.Key);
                     _serverAddress = consumerClient.BrokerAddress;
                     RegisterMessageProcessor(consumerClient);
                     consumerClient.Subscribe(Enumerable.Select <ConsumerExecutorDescriptor, string>((IEnumerable <ConsumerExecutorDescriptor>)matchGroup.Value, (Func <ConsumerExecutorDescriptor, string>)((ConsumerExecutorDescriptor x) => x.TopicName)));
                     consumerClient.Listening(_pollingDelay, _cts.Token);
                 }
                 catch (OperationCanceledException)
                 {
                 }
                 catch (BrokerConnectionException ex2)
                 {
                     _isHealthy = false;
                     _logger.LogError(ex2, ex2.Message);
                 }
                 catch (Exception ex3)
                 {
                     _logger.LogError(ex3, ex3.Message);
                 }
             }, _cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
         }
     }
     _compositeTask = Task.CompletedTask;
 }