Esempio n. 1
0
        /// <summary>
        /// Returns the implementation of the <see cref="ICloudQueueStorage"/> that corresponds to the Azure storage as defined in the specified location object.
        /// </summary>
        /// <param name="location">The specified location of a queue in the Azure storage infrastructure.</param>
        /// <returns>The object that provides access to the Azure queue storage.</returns>
        public ICloudQueueStorage GetQueueStorage(CloudQueueLocation location)
        {
            Guard.ArgumentNotNull(location, "location");
            Guard.ArgumentNotNull(this.cloudStorageProvider, "cloudStorageProvider");

            return(this.cloudStorageProvider.GetQueueStorage(location.StorageAccount));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of a queue listener that will be listening to messages arriving to the specified queue.
        /// </summary>
        /// <param name="queueLocation">The location of a queue in the Windows Azure storage infrastructure.</param>
        public CloudQueueListenerExtension(CloudQueueLocation queueLocation)
        {
            Guard.ArgumentNotNull(queueLocation, "queueLocation");
            Guard.ArgumentNotNullOrEmptyString(queueLocation.QueueName, "queueLocation.QueueName");

            this.queueLocation    = queueLocation;
            this.dequeueTasks     = new BlockingCollection <Task>(this.dequeueTaskList);
            this.DequeueBatchSize = DefaultDequeueBatchSize;
            this.DequeueInterval  = TimeSpan.FromMilliseconds(DefaultDequeueMaxReceiveInterval);
        }
Esempio n. 3
0
            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;
            }
Esempio n. 4
0
        /// <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);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Resolves the exact location of a given queue by its name.
        /// </summary>
        /// <param name="queueName">The name of the Windows Azure queue.</param>
        /// <returns>The location of the queue in the Windows Azure storage infrastructure.</returns>
        public CloudQueueLocation GetQueueLocation(string queueName)
        {
            Guard.ArgumentNotNullOrEmptyString(queueName, "queueName");
            var callToken = TraceManager.WorkerRoleComponent.TraceIn(queueName);

            // Assume an invalid (non-discoverable) location by default.
            CloudQueueLocation queueLocation = CloudQueueLocation.Unknown;

            try
            {
                if (queueName == "InputQueueTag")
                {
                    queueLocation = new CloudQueueLocation()
                    {
                        StorageAccount    = this.configSettingsExtension.Settings.CloudStorageAccount,
                        QueueName         = this.configSettingsExtension.Settings.WorkItemQueue,
                        VisibilityTimeout = this.configSettingsExtension.Settings.WorkItemQueueVisibilityTimeout
                    };
                }
                else if (queueName == "OutputQueueTag")
                {
                    queueLocation = new CloudQueueLocation()
                    {
                        StorageAccount    = this.configSettingsExtension.Settings.CloudStorageAccount,
                        QueueName         = this.configSettingsExtension.Settings.OutputQueue,
                        VisibilityTimeout = this.configSettingsExtension.Settings.OutputQueueVisibilityTimeout
                    };
                }
            }
            finally
            {
                TraceManager.WorkerRoleComponent.TraceOut(callToken, queueLocation.QueueName, queueLocation.StorageAccount, queueLocation.VisibilityTimeout);
            }

            return(queueLocation);
        }
Esempio n. 6
0
        /// <summary>
        /// Extends the OnStart phase that is called by Windows Azure runtime to initialize the role instance.
        /// </summary>
        /// <returns>True if initialization succeeds, otherwise false.</returns>
        protected override bool OnRoleStart()
        {
            this.EnsureExists <WorkItemProcessorConfigurationExtension>();
            this.EnsureExists <WorkQueueLocationResolverExtension>();
            this.EnsureExists <ScalableTransformServiceClientExtension>();
            this.EnsureExists <EndpointConfigurationDiscoveryExtension>();
            this.EnsureExists <RulesEngineServiceClientExtension>();
            this.EnsureExists <InterRoleEventSubscriberExtension>();

            IWorkItemProcessorConfigurationExtension configSettingsExtension = Extensions.Find <IWorkItemProcessorConfigurationExtension>();
            IEndpointConfigurationDiscoveryExtension discoveryExtension      = Extensions.Find <IEndpointConfigurationDiscoveryExtension>();
            IInterRoleCommunicationExtension         interCommExtension      = Extensions.Find <IInterRoleCommunicationExtension>();
            IInterRoleEventSubscriberExtension       interCommSubscriber     = Extensions.Find <IInterRoleEventSubscriberExtension>();

            CloudQueueLocation inputQueueLocation = new CloudQueueLocation()
            {
                StorageAccount    = configSettingsExtension.Settings.CloudStorageAccount,
                QueueName         = configSettingsExtension.Settings.WorkItemQueue,
                VisibilityTimeout = configSettingsExtension.Settings.WorkItemQueueVisibilityTimeout
            };

            CloudQueueLocation outputQueueLocation = new CloudQueueLocation()
            {
                StorageAccount    = configSettingsExtension.Settings.CloudStorageAccount,
                QueueName         = configSettingsExtension.Settings.OutputQueue,
                VisibilityTimeout = configSettingsExtension.Settings.OutputQueueVisibilityTimeout
            };

            // Instantiate queue listeners.
            var inputQueueListener  = new CloudQueueListenerExtension <XDocument>(inputQueueLocation);
            var outputQueueListener = new CloudQueueListenerExtension <XDocument>(outputQueueLocation);

            // Configure the input queue listener.
            inputQueueListener.QueueEmpty      += HandleQueueEmptyEvent;
            inputQueueListener.DequeueBatchSize = configSettingsExtension.Settings.DequeueBatchSize;
            inputQueueListener.DequeueInterval  = configSettingsExtension.Settings.MinimumIdleInterval;

            // Configure the output queue listener.
            outputQueueListener.QueueEmpty      += HandleQueueEmptyEvent;
            outputQueueListener.DequeueBatchSize = configSettingsExtension.Settings.DequeueBatchSize;
            outputQueueListener.DequeueInterval  = configSettingsExtension.Settings.MinimumIdleInterval;

            // Instantiate queue subscribers.
            InputQueueSubscriberExtension  inputQueueSubscriber  = new InputQueueSubscriberExtension();
            OutputQueueSubscriberExtension outputQueueSubscriber = new OutputQueueSubscriberExtension();

            // Register subscribers with queue listeners.
            inputQueueListener.Subscribe(inputQueueSubscriber);
            outputQueueListener.Subscribe(outputQueueSubscriber);

            // Register custom extensions for this worker role.
            Extensions.Add(inputQueueSubscriber);
            Extensions.Add(outputQueueSubscriber);
            Extensions.Add(outputQueueListener);
            Extensions.Add(inputQueueListener);

            var contractTypeMatchCondition = ServiceEndpointDiscoveryCondition.ContractTypeExactMatch(typeof(IScalableTransformationServiceContract));
            var bindingTypeMatchCondition  = ServiceEndpointDiscoveryCondition.BindingTypeExactMatch(typeof(NetTcpRelayBinding));

            discoveryExtension.RegisterDiscoveryAction(new[] { contractTypeMatchCondition, bindingTypeMatchCondition }, (endpoint) =>
            {
                NetTcpRelayBinding relayBinding = endpoint.Binding as NetTcpRelayBinding;
                if (relayBinding != null)
                {
                    relayBinding.TransferMode = TransferMode.Streamed;
                }
            });

            // Register a subscriber for all inter-role communication events.
            if (interCommExtension != null && interCommSubscriber != null)
            {
                this.interCommSubscription = interCommExtension.Subscribe(interCommSubscriber);
            }

            return(true);
        }