/// <summary> /// Gets called by the provider to notify this subscriber about a new item retrieved from the queue. /// </summary> /// <param name="item">The queue item retrieved from the source queue.</param> public void OnNext(XDocument item) { Guard.ArgumentNotNull(item, "item"); var callToken = TraceManager.WorkerRoleComponent.TraceIn(item.Root.Name); try { string transformName = ResolveTransformName(item); if (!String.IsNullOrEmpty(transformName)) { XDocument transformedDoc = this.transformService.ApplyTransform(transformName, item); using (ICloudQueueStorage outputQueue = this.storageProviderExtension.GetQueueStorage(this.configSettingsExtension.Settings.CloudStorageAccount)) { outputQueue.Put <XDocument>(this.configSettingsExtension.Settings.OutputQueue, transformedDoc); } } else { throw new CloudApplicationException(String.Format(CultureInfo.InstalledUICulture, ExceptionMessages.UnableToResolveTransformName, item.Root.Name, this.configSettingsExtension.Settings.HandlingPolicyName)); } } finally { TraceManager.WorkerRoleComponent.TraceOut(callToken); } }
public void PutLargeXmlMessage() { string testFileName = Path.Combine(testMessageFolder, "InventoryReport_2.xml"); using (ICloudBlobStorage blobStorage = GetCloudBlobStorage()) using (ICloudQueueStorage queueStorage = GetCloudQueueStorage()) { LargeQueueMessageInfo largeMsgInfo = LargeQueueMessageInfo.Create(testQueueName); XDocument testMessage = XDocument.Load(testFileName); queueStorage.Clear(testQueueName); queueStorage.Put <XDocument>(testQueueName, testMessage); int blobCount = blobStorage.GetCount(largeMsgInfo.ContainerName); XDocument msgFromQueue = queueStorage.Get <XDocument>(testQueueName); Assert.IsNotNull(msgFromQueue, "Unable to find message on the queue"); Assert.IsTrue(String.Compare(testMessage.ToString(), msgFromQueue.ToString(), false) == 0, "Message content is different"); Assert.IsTrue(blobCount == 1, "Blob storage must contain the message data"); bool deleted = queueStorage.Delete <XDocument>(msgFromQueue); int queueLength = queueStorage.GetCount(testQueueName); Assert.IsTrue(deleted, "Message has not been deleted by some reasons"); Assert.IsTrue(queueLength == 0, "Queue is not empty by some reasons"); blobCount = blobStorage.GetCount(largeMsgInfo.ContainerName); Assert.IsTrue(blobCount == 0, "Blob storage is not empty by some reasons"); } }
private void DequeueXmlDataTaskMain(DequeueXmlDataTaskState state) { Guard.ArgumentNotNull(state, "state"); using (ICloudQueueStorage workItemQueue = state.StorageProvider.GetQueueStorage(state.Settings.CloudStorageAccount)) using (SqlAzurePersistenceQueue dbQueue = new SqlAzurePersistenceQueue()) { dbQueue.Open(WellKnownDatabaseName.PersistenceQueue); using (XmlReader xmlReader = dbQueue.DequeueXmlData(state.QueueItemInfo.QueueItemId, state.HeaderSegments, state.BodySegments, state.FooterSegments, state.NamespaceManager)) { if (xmlReader != null) { XDocument batch = XDocument.Load(xmlReader); // Check for presence of any items in the batch. bool batchFound = (batch.XPathSelectElement(state.ItemDetectionXPath) != null); if (batchFound) { workItemQueue.Put <XDocument>(state.Settings.DestinationQueue, batch); } } } } }
public static void ReliableCloudQueueStorageTestsCleanup() { using (ICloudQueueStorage queueStorage = GetCloudQueueStorage()) { queueStorage.DeleteQueue(testQueueName); } }
/// <summary> /// Notifies this extension component that it has been unregistered from the owner's collection of extensions. /// </summary> /// <param name="owner">The extensible owner object that aggregates this extension.</param> public void Detach(IExtensibleCloudServiceComponent owner) { var callToken = TraceManager.WorkerRoleComponent.TraceIn(this.queueLocation.StorageAccount, this.queueLocation.QueueName); try { // Communicate a request for cancellation of all running dequeue tasks. cancellationSignal.Cancel(); foreach (var task in this.dequeueTasks) { var taskStopScopeStart = TraceManager.WorkerRoleComponent.TraceStartScope(String.Format(CultureInfo.CurrentCulture, TraceLogMessages.ScopeCloudQueueListenerExtensionStopDequeueTask, task.Id, task.Status), callToken); try { // Block until the task completes (if it's running). if (task.Status != TaskStatus.Canceled && task.Status != TaskStatus.Faulted && task.Status != TaskStatus.RanToCompletion) { task.Wait(); } } catch (AggregateException) { // Should ensure a safe stop, just ignore this exception and don't let it damage the rest of the Detach logic. } catch (OperationCanceledException) { // Should ensure a safe stop, just ignore this exception and don't let it damage the rest of the Detach logic. } catch (Exception ex) { // Should ensure a safe stop, just log an exception and don't let it damage the rest of the Detach logic. TraceManager.WorkerRoleComponent.TraceError(ex); } finally { TraceManager.WorkerRoleComponent.TraceEndScope(String.Format(CultureInfo.CurrentCulture, TraceLogMessages.ScopeCloudQueueListenerExtensionStopDequeueTask, task.Id, task.Status), taskStopScopeStart, callToken); task.Dispose(); } } if (this.subscriptions != null) { this.subscriptions.Dispose(); this.subscriptions = null; } if (this.queueStorage != null) { this.queueStorage.Dispose(); this.queueStorage = null; } } finally { TraceManager.WorkerRoleComponent.TraceOut(callToken); } }
public CloudQueueListenerDequeueTaskState(IEnumerable <QueueSubscriptionInfo <TItem> > subscriptions, CancellationToken cancellationToken, CloudQueueLocation queueLocation, ICloudQueueStorage queueStorage) { Guard.ArgumentNotNull(subscriptions, "subscriptions"); Guard.ArgumentNotNull(cancellationToken, "cancellationToken"); Guard.ArgumentNotNull(queueLocation, "queueLocation"); Guard.ArgumentNotNull(queueStorage, "queueStorage"); this.subscriptions = subscriptions; this.cancellationToken = cancellationToken; this.queueLocation = queueLocation; this.queueStorage = queueStorage; }
/// <summary> /// Notifies this extension component that it has been registered in the owner's collection of extensions. /// </summary> /// <param name="owner">The extensible owner object that aggregates this extension.</param> public void Attach(IExtensibleCloudServiceComponent owner) { var callToken = TraceManager.WorkerRoleComponent.TraceIn(this.queueLocation.StorageAccount, this.queueLocation.QueueName); try { owner.Extensions.Demand <ICloudStorageProviderExtension>(); if (!this.queueLocation.IsDiscoverable) { var queueLocationResolvers = owner.Extensions.FindAll <ICloudQueueLocationResolverExtension>(); foreach (ICloudQueueLocationResolverExtension locationResolver in queueLocationResolvers) { this.queueLocation = locationResolver.GetQueueLocation(this.queueLocation.QueueName); if (this.queueLocation.IsDiscoverable) { break; } } } if (this.queueLocation.IsDiscoverable) { ICloudStorageProviderExtension storageProvider = owner.Extensions.Find <ICloudStorageProviderExtension>(); this.queueStorage = storageProvider.GetQueueStorage(this.queueLocation.StorageAccount); // Ensure that the queue is available, create a new queue if one doesn't exist. this.queueStorage.CreateQueue(this.queueLocation.QueueName); } else { throw new CloudApplicationException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.CloudQueueNotDiscoverable, this.queueLocation.QueueName)); } } finally { TraceManager.WorkerRoleComponent.TraceOut(callToken); } }
public void PutLargeBinaryMessage() { int largeMessageSize = 2 * 1024 * 1024; var largeMessage = new byte[largeMessageSize]; randGenerator.NextBytes(largeMessage); using (ICloudBlobStorage blobStorage = GetCloudBlobStorage()) using (ICloudQueueStorage queueStorage = GetCloudQueueStorage()) { LargeQueueMessageInfo largeMsgInfo = LargeQueueMessageInfo.Create(testQueueName); queueStorage.Clear(testQueueName); queueStorage.Put <byte[]>(testQueueName, largeMessage); int blobCount = blobStorage.GetCount(largeMsgInfo.ContainerName); byte[] msgFromQueue = queueStorage.Get <byte[]>(testQueueName); Assert.IsNotNull(msgFromQueue, "Unable to find message on the queue"); var matchedBytes = msgFromQueue.Where((value, index) => { return(largeMessage[index] == value); }); Assert.IsTrue(matchedBytes.Count() == largeMessageSize, "Message content is different"); Assert.IsTrue(blobCount == 1, "Blob storage must contain the message data"); bool deleted = queueStorage.Delete <byte[]>(msgFromQueue); int queueLength = queueStorage.GetCount(testQueueName); Assert.IsTrue(deleted, "Message has not been deleted by some reasons"); Assert.IsTrue(queueLength == 0, "Queue is not empty by some reasons"); blobCount = blobStorage.GetCount(largeMsgInfo.ContainerName); Assert.IsTrue(blobCount == 0, "Blob storage is not empty by some reasons"); } }
/// <summary> /// Notifies this extension component that it has been unregistered from the owner's collection of extensions. /// </summary> /// <param name="owner">The extensible owner object that aggregates this extension.</param> public void Detach(IExtensibleCloudServiceComponent owner) { if (this.defaultBlobStorage != null) { lock (this.syncRoot) { if (this.defaultBlobStorage != null) { this.defaultBlobStorage.Dispose(); this.defaultBlobStorage = null; } } } if (this.defaultQueueStorage != null) { lock (this.syncRoot) { if (this.defaultQueueStorage != null) { this.defaultQueueStorage.Dispose(); this.defaultQueueStorage = null; } } } if (this.defaultTableStorage != null) { lock (this.syncRoot) { if (this.defaultTableStorage != null) { this.defaultTableStorage.Dispose(); this.defaultTableStorage = null; } } } }
/// <summary> /// Constructs with DI. /// </summary> /// <param name="notificationScheduleQueue"></param> /// <param name="tableConfiguration"></param> public NotificationPoolRouter(ICloudQueueStorage notificationScheduleQueue, ITableConfiguration tableConfiguration) { _cloudQueueStorage = notificationScheduleQueue; _tableConfiguration = tableConfiguration; }
/// <summary> /// Constructs with DI. /// </summary> /// <param name="cloudQueueStorage"></param> /// <param name="tableConfiguration"></param> public NotificationController(ICloudQueueStorage cloudQueueStorage, ITableConfiguration tableConfiguration) { _cloudQueueStorage = cloudQueueStorage; _tableConfiguration = tableConfiguration; }
/// <summary> /// Constructs with DI. /// </summary> /// <param name="cloudQueueStorage"></param> /// <param name="notificationPoolRouter"></param> public ScheduleProcessor(ICloudQueueStorage cloudQueueStorage, INotificationPoolRouter notificationPoolRouter) { _cloudQueueStorage = cloudQueueStorage; _notificationPoolRouter = notificationPoolRouter; }
public void Init() { _cloudQueue = Substitute.For<ICloudQueueStorage>(); _queue = new AzureSimpleQueue<INotificationService>(_cloudQueue); }
/// <summary> /// Initializes a new instance of the trace listener using the specified configuration settings. /// </summary> /// <param name="diagnosticServiceEndpoint">The name of the Service Bus endpoint definition that corresponds to the on-premises hosted diagnostic service.</param> /// <param name="diagnosticStorageAccount">The name of the storage account in which diagnostic data will be queued before relayed to the on-premises hosted diagnostic service.</param> /// <param name="inMemoryQueueCapacity">The maximum capacity of the non-durable in-memory queue in which trace events are being stored before they are persisted into an Azure queue.</param> /// <param name="inMemoryQueueListenerSleepTimeout">The interval in milliseconds during which a dequeue thread is waiting for new events in the in-memory queue.</param> /// <param name="diagQueueEventBatchSize">The maximum number of trace events in a batch that is submitted to the on-premises hosted diagnostic service.</param> /// <param name="diagQueueListenerSleepTimeout">The interval in milliseconds during which a dequeue thread is waiting for new events to be deposited into the Azure queue.</param> public OnPremisesBufferedTraceListener(string diagnosticServiceEndpoint, string diagnosticStorageAccount, int inMemoryQueueCapacity, int inMemoryQueueListenerSleepTimeout, int diagQueueEventBatchSize, int diagQueueListenerSleepTimeout) { Guard.ArgumentNotNullOrEmptyString(diagnosticServiceEndpoint, "diagnosticServiceEndpoint"); Guard.ArgumentNotZeroOrNegativeValue(inMemoryQueueCapacity, "inMemoryQueueCapacity"); Guard.ArgumentNotZeroOrNegativeValue(inMemoryQueueListenerSleepTimeout, "inMemoryQueueListenerSleepTimeout"); Guard.ArgumentNotZeroOrNegativeValue(diagQueueEventBatchSize, "diagQueueEventBatchSize"); Guard.ArgumentNotZeroOrNegativeValue(diagQueueListenerSleepTimeout, "diagQueueListenerSleepTimeout"); // Configure the general properties of the trace listener. Name = ListenerName; NeedIndent = false; // Configure the in-memory queue and its parameters, set up a backup trace listener. this.inMemoryQueue = new ConcurrentQueue <TraceEventRecord>(); this.inMemoryQueueCapacity = inMemoryQueueCapacity; this.inMemoryQueueListenerSleepTimeout = inMemoryQueueListenerSleepTimeout; this.diagQueueEventBatchSize = diagQueueEventBatchSize; this.diagQueueListenerSleepTimeout = diagQueueListenerSleepTimeout; this.diagQueueName = GetServiceBusQueueName(CloudEnvironment.CurrentRoleInstanceId); this.backupTraceListener = new CloudDiagnosticTraceListener(); // Configure Service Bus endpoint for the Diagnostic Service. ServiceBusEndpointInfo diagServiceEndpointInfo = ApplicationConfiguration.Current.ServiceBusSettings.Endpoints[diagnosticServiceEndpoint]; // Validate Service Bus endpoints. if (null == diagServiceEndpointInfo) { throw new ConfigurationErrorsException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.SpecifiedServiceBusEndpointNotFound, diagnosticServiceEndpoint, ServiceBusConfigurationSettings.SectionName)); } // Retrieve the storage account settings from application configuration. StorageAccountConfigurationSettings storageSettings = ApplicationConfiguration.Current.GetConfigurationSection <StorageAccountConfigurationSettings>(StorageAccountConfigurationSettings.SectionName); // Validate the presence of storage account settings. if (null == storageSettings) { throw new ConfigurationErrorsException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.ConfigSectionNotFoundInConfigSource, StorageAccountConfigurationSettings.SectionName)); } // Determine the storage account for storing tracing data. By default, assume that storage account is defined in the trace listener configuration. string diagStorageAccountName = diagnosticStorageAccount; // If storage account is not defined in the trace listener configuration, switch to the storage account specified in the Application Diagnostic Settings section. if (String.IsNullOrEmpty(diagStorageAccountName)) { // Retrieve the diagnostic settings from application configuration. ApplicationDiagnosticSettings diagSettings = ApplicationConfiguration.Current.GetConfigurationSection <ApplicationDiagnosticSettings>(ApplicationDiagnosticSettings.SectionName); // Validate the presence of diagnostic settings. if (null == diagSettings) { throw new ConfigurationErrorsException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.ConfigSectionNotFoundInConfigSource, ApplicationDiagnosticSettings.SectionName)); } diagStorageAccountName = diagSettings.DiagnosticStorageAccount; } // Resolve the storage account details based on the account name defined in the diagnostic settings . StorageAccountInfo diagStorageAccount = storageSettings.Accounts.Get(diagStorageAccountName); // Validate storage account details. if (null == diagStorageAccount) { throw new ConfigurationErrorsException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.StorageAccountNotFoundInConfigSource, diagStorageAccountName)); } // Configure retry policies. this.sbRetryPolicy = new RetryPolicy <ServiceBusTransientErrorDetectionStrategy>(DefaultRetryCount); this.queueRetryPolicy = new RetryPolicy <StorageTransientErrorDetectionStrategy>(DefaultRetryCount); this.sbRetryPolicy.RetryOccurred += HandleServiceBusEndpointRetryState; this.queueRetryPolicy.RetryOccurred += HandleCloudQueueRetryState; // Configure Service Bus and Message Queue clients. this.diagnosticService = new ReliableServiceBusClient <IDiagnosticLoggingServiceChannel>(diagServiceEndpointInfo, this.sbRetryPolicy); this.diagQueueStorage = new ReliableCloudQueueStorage(diagStorageAccount, this.queueRetryPolicy); this.diagQueueReaderDone = new ManualResetEvent(false); this.diagQueueWriterDone = new ManualResetEvent(false); // Ensure that destination cloud queue exists, create if necessary. this.diagQueueStorage.CreateQueue(this.diagQueueName); // Enable background listeners to run. this.isRunning = true; StartInMemoryQueueListener(); StartServiceBusQueueListener(); }