示例#1
0
        /// <summary>
        /// Starts the bus and wires all listeners
        /// </summary>
        /// <returns></returns>
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            ConsoleWriter.WriteLine("KnightBus starting");
            if (_transports.Any())
            {
                _locator = new MessageProcessorLocator(_configuration, _transports.SelectMany(transport => transport.TransportChannelFactories).ToArray());
                var channelReceivers = _locator.Locate().ToList();
                ConsoleWriter.Write("Starting receivers [");
                foreach (var queueReader in channelReceivers)
                {
                    await queueReader.StartAsync(cancellationToken).ConfigureAwait(false);

                    Console.Write(".");
                }
                Console.WriteLine("]");
            }
            else
            {
                ConsoleWriter.WriteLine("No transports found");
            }

            if (_configuration.Plugins.Any())
            {
                foreach (var plugin in _configuration.Plugins)
                {
                    await plugin.StartAsync(cancellationToken).ConfigureAwait(false);
                }
            }
            else
            {
                ConsoleWriter.WriteLine("No plugins found");
            }

            ConsoleWriter.WriteLine("KnightBus started");
        }
示例#2
0
        /// <summary>
        /// Starts the bus and wires all listeners
        /// </summary>
        /// <returns></returns>
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            var combinedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _shutdownToken.Token);

            ConsoleWriter.WriteLine("KnightBus starting");
            if (_configuration.DependencyInjection == null)
            {
                throw new DependencyInjectionMissingException();
            }

            if (_configuration.DependencyInjection is IIsolatedDependencyInjection isolated)
            {
                isolated.Build();
            }

            if (_transports.Any())
            {
                _locator = new MessageProcessorLocator(_configuration, _transports.SelectMany(transport => transport.TransportChannelFactories).ToArray());
                var channelReceivers = _locator.Locate().ToList();
                ConsoleWriter.Write("Starting receivers [");
                foreach (var queueReader in channelReceivers)
                {
                    await queueReader.StartAsync(combinedToken.Token).ConfigureAwait(false);

                    Console.Write(".");
                }
                Console.WriteLine("]");
            }
            else
            {
                ConsoleWriter.WriteLine("No transports found");
            }

            if (_configuration.Plugins.Any())
            {
                foreach (var plugin in _configuration.Plugins)
                {
                    await plugin.StartAsync(combinedToken.Token).ConfigureAwait(false);
                }
            }
            else
            {
                ConsoleWriter.WriteLine("No plugins found");
            }

            ConsoleWriter.WriteLine("KnightBus started");
        }
示例#3
0
        /// <summary>
        /// Starts the bus and wires all listeners
        /// </summary>
        /// <returns></returns>
        public async Task StartAsync()
        {
            if (!_transports.Any())
            {
                throw new TransportMissingException("No transports configured");
            }
            ConsoleWriter.WriteLine("KnightBus starting");
            _locator = new MessageProcessorLocator(_configuration, _transports.SelectMany(transport => transport.TransportChannelFactories).ToArray());
            var queueReaders = _locator.Locate().ToList();

            ConsoleWriter.Write("Starting receivers [");
            foreach (var queueReader in queueReaders)
            {
                await queueReader.StartAsync().ConfigureAwait(false);

                Console.Write(".");
            }
            Console.WriteLine("]");
            ConsoleWriter.WriteLine("KnightBus started");
        }