Exemplo n.º 1
0
        public async Task Activate(LocalWorkerSender localWorker, CapabilityGraph capabilities, JasperRuntime runtime,
                                   GenerationRules generation, PerfTimer timer)
        {
            timer.MarkStart("ServiceBusActivator");

            _handlers.Compile(generation, runtime, timer);


            var capabilityCompilation = capabilities.Compile(_handlers, Serialization, _channels, runtime, _transports, Lookup);



            var transports = _transports.Where(x => _settings.StateFor(x.Protocol) != TransportState.Disabled)
                             .ToArray();

            timer.Record("WorkersGraph.Compile", () =>
            {
                _settings.Workers.Compile(_handlers.Chains.Select(x => x.MessageType));
            });



            localWorker.Start(_persistence, Workers);

            if (!_settings.DisableAllTransports)
            {
                timer.MarkStart("ApplyLookups");

                await _settings.ApplyLookups(Lookup);

                timer.MarkFinished("ApplyLookups");


                timer.Record("ChannelGraph.Start",
                             () => { _channels.As <ChannelGraph>().Start(_settings, transports, Lookup, capabilities, Logger, Workers); });

                ScheduledJobs.Start(Workers);
            }

            runtime.Capabilities = await capabilityCompilation;
            if (runtime.Capabilities.Errors.Any() && _settings.ThrowOnValidationErrors)
            {
                throw new InvalidSubscriptionException(runtime.Capabilities.Errors);
            }

            timer.MarkFinished("ServiceBusActivator");
        }