Exemplo n.º 1
0
        /// <summary>
        /// Initial the response client
        /// </summary>
        /// <param name="azureResponseQueueUri">The response queue SAS Uri</param>
        /// <param name="azureResponseBlobUri">The response blob container SAS Uri</param>
        public void InitResponseClient(string azureResponseQueueUri, string azureResponseBlobUri)
        {
            if (!this.responseClientInitialized)
            {
                lock (this.responseClientLock)
                {
                    if (!this.responseClientInitialized)
                    {
                        this.responseQueue = new CloudQueue(new Uri(azureResponseQueueUri));
                        // exponential retry
                        this.responseQueue.ServiceClient.DefaultRequestOptions.RetryPolicy = DefaultRetryPolicy;

                        this.responseBlobContainer = new CloudBlobContainer(new Uri(azureResponseBlobUri));
                        // exponential retry
                        this.responseBlobContainer.ServiceClient.DefaultRequestOptions.RetryPolicy = DefaultRetryPolicy;

                        this.responseStorageClient = new AzureStorageClient(this.responseQueue, this.responseBlobContainer);
                        this.messageRetriever      = new MessageRetriever(this.responseStorageClient.Queue, RetrieverConcurrency, DefaultVisibleTimeout, this.HandleMessages, null);
                        this.receiveResponse       = this.ReceiveMessage;

                        this.semaphoreForResponse = new Semaphore(0, int.MaxValue);
                        this.semaphoreForWorker   = new Semaphore(MessageProcessWorker, MessageProcessWorker);

                        this.messageRetriever.Start();
                        this.messageProcessorTask = new Task(this.MessageProcessor);
                        this.messageProcessorTask.Start();

                        this.responseClientInitialized = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Cleanup current object.
        /// </summary>
        private void Cleanup()
        {
            foreach (var messageSender in this.messageSenders)
            {
                if (messageSender != null)
                {
                    try
                    {
                        messageSender.Close();
                    }
                    catch (Exception e)
                    {
                        SessionBase.TraceSource.TraceInformation(
                            SoaHelper.CreateTraceMessage(
                                "Proxy",
                                "Cleanup",
                                string.Format("Closing message retriever failed, {0}", e)));
                    }

                    // this.messageSenders = null;
                }
            }


            if (this.messageRetriever != null)
            {
                try
                {
                    this.messageRetriever.Close();
                }
                catch (Exception e)
                {
                    SessionBase.TraceSource.TraceInformation(
                        SoaHelper.CreateTraceMessage(
                            "Proxy",
                            "Cleanup",
                            string.Format("Closing message retrier failed, {0}", e)));
                }

                this.messageRetriever = null;
            }

            if (this.messageProcessorTask != null)
            {
                try
                {
                    this.messageProcessorTask.Dispose();
                }
                catch (Exception e)
                {
                    SessionBase.TraceSource.TraceInformation(
                        SoaHelper.CreateTraceMessage(
                            "Proxy",
                            "Cleanup",
                            string.Format("Disposing message processor task failed, {0}", e)));
                }

                this.messageProcessorTask = null;
            }

            if (this.semaphoreForResponse != null)
            {
                try
                {
                    this.semaphoreForResponse.Dispose();
                }
                catch (Exception e)
                {
                    SessionBase.TraceSource.TraceInformation(
                        SoaHelper.CreateTraceMessage(
                            "Proxy",
                            "Cleanup",
                            string.Format("Disposing semaphoreForRequest failed, {0}", e)));
                }

                this.semaphoreForResponse = null;
            }

            if (this.semaphoreForWorker != null)
            {
                try
                {
                    this.semaphoreForWorker.Dispose();
                }
                catch (Exception e)
                {
                    SessionBase.TraceSource.TraceInformation(
                        SoaHelper.CreateTraceMessage(
                            "Proxy",
                            "Cleanup",
                            string.Format("Disposing semaphoreForWorker failed, {0}", e)));
                }

                this.semaphoreForWorker = null;
            }

            foreach (var requestStorageClient in this.requestStorageClients)
            {
                if (requestStorageClient != null)
                {
                    try
                    {
                        requestStorageClient.Close();
                    }
                    catch (Exception e)
                    {
                        SessionBase.TraceSource.TraceInformation(
                            SoaHelper.CreateTraceMessage(
                                "Proxy",
                                "Cleanup",
                                string.Format("Disposing semaphoreForWorker failed, {0}", e)));
                    }

                    //requestStorageClients = null;
                }
            }


            if (this.responseStorageClient != null)
            {
                try
                {
                    this.responseStorageClient.Close();
                }
                catch (Exception e)
                {
                    SessionBase.TraceSource.TraceInformation(
                        SoaHelper.CreateTraceMessage(
                            "Proxy",
                            "Cleanup",
                            string.Format("Disposing responseStorageClient failed, {0}", e)));
                }

                this.responseStorageClient = null;
            }
        }