예제 #1
0
        public override void Bootstrap()
        {
            ImportFirst <IBackgroundErrorLogger>(BackgroundErrorLogger.SetCurrent);
            ImportFirst <IBackgroundErrorLogFactory>(BackgroundErrorLogger.SetBackgroundErrorLogFactory);

            ImportFirst <IApplicationIdProvider>(ApplicationId.SetCurrent);

            ImportFirst <IResolverConstructorSelector>(AutoContainer.SetDefaultResolverConstructorSelector);

            ImportFirst <IConvertsTo <IDictionary <string, string> > >(ToDictionaryOfStringToStringExtension.SetConverter);
            ImportFirst <IConvertsTo <ExpandoObject> >(ToExpandoObjectExtension.SetConverter);

            ImportFirst <IKeyValueStore>(TempStorage.SetKeyValueStore, "TempStorage");

            ImportFirst <ISerializer>(DefaultBinarySerializer.SetCurrent, "BinarySerializer");
            ImportFirst <IEndpointDetector>(DefaultEndpointDetector.SetCurrent);
            ImportFirst <IEndpointSelector>(DefaultEndpointSelector.SetCurrent);
            ImportFirst <IHttpClientFactory>(DefaultHttpClientFactory.SetCurrent);
            ImportFirst <ISerializer>(DefaultJsonSerializer.SetCurrent, "JsonSerializer");
            ImportFirst <ISerializer>(DefaultXmlSerializer.SetCurrent, "XmlSerializer");

            BackgroundErrorLogger.UnlockCurrent();
            BackgroundErrorLogger.UnlockBackgroundErrorLogFactory();
        }
예제 #2
0
        protected override void OnError(string message, Exception exception, ImportInfo import)
        {
            BackgroundErrorLogger.Log(exception, "Static Dependency Injection - " + message, "Rock.Messaging", "ImportInfo:\r\n" + import);

            base.OnError(message, exception, import);
        }
예제 #3
0
        private void DoStuff()
        {
            while (!_stopped)
            {
                var receiveMessageRequest = new ReceiveMessageRequest
                {
                    MaxNumberOfMessages   = _maxMessages,
                    QueueUrl              = _queueUrl,
                    MessageAttributeNames = new List <string> {
                        "*"
                    }
                };

                ReceiveMessageResponse response = null;
                Exception exception             = null;

                for (int i = 0; i < _maxReceiveAttempts; i++)
                {
                    try
                    {
                        response = Sync.OverAsync(() => _sqs.ReceiveMessageAsync(receiveMessageRequest));

                        if (response.HttpStatusCode == HttpStatusCode.OK)
                        {
                            exception = null;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                }

                if (exception != null || response == null || response.HttpStatusCode != HttpStatusCode.OK)
                {
#if ROCKLIB
                    Trace.TraceError($"Unable to receive SQS messages from AWS. Additional Information - {GetAdditionalInformation(response, null)}");
#else
                    BackgroundErrorLogger.Log(
                        exception,
                        "Unable to receive SQS messages from AWS.",
                        "Rock.Messaging.SQS",
                        GetAdditionalInformation(response, null));
#endif
                    continue;
                }

                if (_parallelHandling)
                {
                    Parallel.ForEach(response.Messages, Handle);
                }
                else
                {
                    foreach (var message in response.Messages)
                    {
                        Handle(message);
                    }
                }
            }
        }
예제 #4
0
        private void Handle(Message message)
        {
            if (_stopped)
            {
                return;
            }

            var handler = MessageReceived;

            if (handler != null)
            {
                var receiptHandle = message.ReceiptHandle;

                Action acknowledge =
                    () =>
                {
                    Exception             deleteException = null;
                    DeleteMessageResponse deleteResponse  = null;

                    for (int i = 0; i < _maxAcknowledgeAttempts; i++)
                    {
                        try
                        {
                            deleteException = null;
                            deleteResponse  = null;

                            deleteResponse = Sync.OverAsync(() => _sqs.DeleteMessageAsync(new DeleteMessageRequest
                            {
                                QueueUrl      = _queueUrl,
                                ReceiptHandle = receiptHandle
                            }));

                            if (deleteResponse.HttpStatusCode == HttpStatusCode.OK)
                            {
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            deleteException = ex;
                        }
                    }

#if ROCKLIB
                    Trace.TraceError($"Unable to delete SQS message. Additional Information - {GetAdditionalInformation(deleteResponse, receiptHandle)}");
#else
                    BackgroundErrorLogger.Log(
                        deleteException,
                        "Unable to delete SQS message.",
                        "Rock.Messaging.SQS",
                        GetAdditionalInformation(deleteResponse, receiptHandle));
#endif
                };

                try
                {
                    handler(this, new MessageReceivedEventArgs(new SQSReceiverMessage(message, acknowledge)));
                }
                finally
                {
                    if (_autoAcknwoledge)
                    {
                        acknowledge();
                    }
                }
            }
        }