예제 #1
0
        /// <summary>
        /// Configures and starts the bus.
        /// </summary>
        /// <returns></returns>
        private async static Task ConfigureAndStartBusAsync()
        {
            if (_transportComponent == null)
            {
                throw new Exception("An active transport component is required for Rock to run correctly");
            }

            _bus = _transportComponent.GetBusControl(RockConsumer.ConfigureRockConsumers);
            _bus.ConnectConsumeObserver(_statObserver);
            _bus.ConnectReceiveObserver(_receiveFaultObserver);

            // Allow the bus to try to connect for some seconds at most
            var cancelToken = new CancellationTokenSource();
            var task        = _bus.StartAsync(cancelToken.Token);

            const int delaySeconds = 45;
            var       delay        = Task.Delay(TimeSpan.FromSeconds(delaySeconds));

            if (await Task.WhenAny(task, delay) == task)
            {
                // Task completed within timeout.
                // Consider that the task may have faulted or been canceled.
                // We re-await the task so that any exceptions/cancellation is rethrown.
                // https://stackoverflow.com/a/11191070/13215483
                await task;
            }
            else
            {
                // The bus did not connect after some seconds
                cancelToken.Cancel();
                throw new Exception($"The bus failed to connect using {_transportComponent.GetType().Name} within {delaySeconds} seconds");
            }

            _isBusStarted = true;
        }
예제 #2
0
        public TwilioDownloader()
        {
            TransportComponent transportComponent = null;

            foreach (var serviceEntry in TransportContainer.Instance.Components)
            {
                transportComponent = serviceEntry.Value.Value;
                var entityType = EntityTypeCache.Get(transportComponent.GetType());
                if (entityType != null && entityType.Guid.Equals(EntityTypeCache.Get(typeof(Rock.Communication.Transport.Twilio)).Guid))
                {
                    accountSid = transportComponent.GetAttributeValue("SID");
                    authToken  = transportComponent.GetAttributeValue("Token");
                }
            }
        }