Ejemplo n.º 1
0
        /// <summary>
        /// Perform polling on the queue
        /// </summary>
        /// <param name="args">Parameters object</param>
        private void Polling(object args)
        {
            var _args             = args as object[];
            var topic             = _args[0] as string;
            var cancellationToken = (CancellationToken)_args[1];

            while (true)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                try
                {
                    var queueUrl = _configuration.GetSection("AwsEventBus:Topics:" + topic + ":SqsUrl").Value;
                    var receiveMessageRequest = new ReceiveMessageRequest()
                    {
                        QueueUrl            = queueUrl,
                        WaitTimeSeconds     = 5,
                        MaxNumberOfMessages = 10
                    };

                    var receivedMessageResponse =
                        _amazonSqsClient.ReceiveMessageAsync(receiveMessageRequest, CancellationToken.None).Result;

                    foreach (var message in receivedMessageResponse.Messages)
                    {
                        _subscriptionsManager.ProcessEvent(topic,
                                                           new IntegrationEventReceivedNotificationDto(message, queueUrl));
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError($"Error on polling: {e.Message}, stacktrace: {e.StackTrace}");
                }
            }
        }