public TestRunStartEventSubscriber(IInterRoleCommunicationExtension communicator, CloudTableClient tableClient, string testRunsTableName, UnicastACKSubscriber ackSubscriber) { this.interRoleCommunicator = communicator; this.tableClient = tableClient; this.testRunsTableName = testRunsTableName; this.ackSubscriber = ackSubscriber; }
/// <summary> /// Called by Windows Azure service runtime to initialize the role instance. /// </summary> /// <returns>Return true if initialization succeeds, otherwise returns false.</returns> public override bool OnStart() { try { StartDiagnosticMonitor(); ServicePointManager.DefaultConnectionLimit = Environment.ProcessorCount * 12; ServicePointManager.UseNagleAlgorithm = false; TraceManager.WorkerRoleComponent.TraceIn(); var serviceBusSettings = ConfigurationManager.GetSection(ServiceBusConfigurationSettings.SectionName) as ServiceBusConfigurationSettings; var pubsubType = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingPubSubType]; var storageAccountName = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingStorageAccount]; var storageAccountKey = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingStorageAccountKey]; var testResultsTableName = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingTestResultsTableName]; var testRunsTableName = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingTestRunsTableName]; if (pubsubType.Equals(CommonConsts.ConfigSettingPubSubTypeValueTopic)) { var topicEndpoint = serviceBusSettings.Endpoints.Get(CommonConsts.TopicServiceBusEndpointName); var ircComponent = new InterRoleCommunicationExtension(topicEndpoint); ircComponent.Settings.RetryPolicy.RetryOccurred += (currentRetryCount, ex, delay) => { TraceManager.WorkerRoleComponent.TraceWarning("******> RETRY LOGIC KICKED IN <******"); TraceManager.WorkerRoleComponent.TraceError(ex); }; this.interRoleCommunicator = ircComponent; } else { var topicEndpoint = serviceBusSettings.Endpoints.Get(CommonConsts.EventRelayServiceBusEndpointName); this.interRoleCommunicator = new InterRoleEventRelayCommunicationExtension(topicEndpoint); } int instanceIndex = CommonFuncs.GetRoleInstanceIndex(RoleEnvironment.CurrentRoleInstance.Id); bool isFirstInstance = (instanceIndex == 0); if (isFirstInstance) { var creds = new StorageCredentialsAccountAndKey(storageAccountName, storageAccountKey); var storageAccount = new CloudStorageAccount(creds, true); resultTableStorage = storageAccount.CreateCloudTableClient(); resultTableStorage.CreateTableIfNotExist(testResultsTableName); resultTableStorage.CreateTableIfNotExist(testRunsTableName); resultTableStorage.RetryPolicy = RetryPolicies.Retry(RetryPolicies.DefaultClientRetryCount, TimeSpan.FromMilliseconds(100)); var ackSubscriber = new UnicastACKSubscriber(interRoleCommunicator, resultTableStorage, testResultsTableName); var startEventSubscriber = new TestRunStartEventSubscriber(interRoleCommunicator, resultTableStorage, testRunsTableName, ackSubscriber); // Register the subscriber for receiving inter-role communication events. this.activeSubscription.Add(this.interRoleCommunicator.Subscribe(ackSubscriber)); this.activeSubscription.Add(this.interRoleCommunicator.Subscribe(startEventSubscriber)); } else { var ircEventSubscriber = new MulticastEventSubscriber(instanceIndex.ToString(), interRoleCommunicator); // Register the subscriber for receiving inter-role communication events. this.activeSubscription.Add(this.interRoleCommunicator.Subscribe(ircEventSubscriber)); } } catch (Exception ex) { TraceManager.WorkerRoleComponent.TraceError(ex); RoleEnvironment.RequestRecycle(); return(false); } return(true); }