Exemplo n.º 1
0
 public void Apply(HandlerGraph graph, GenerationRules rules, IContainer container)
 {
     foreach (var chain in graph.Chains)
     {
         applyToChain(chain);
     }
 }
Exemplo n.º 2
0
 public DiagnosticsListener(
     IDiagnosticsClient client,
     HandlerGraph graph)
 {
     _client = client;
     _graph  = graph;
 }
 public void Apply(HandlerGraph graph)
 {
     foreach (var chain in graph.Chains)
     {
         applyToChain(chain);
     }
 }
Exemplo n.º 4
0
        private async Task <ServiceRegistry> bootstrap(JasperRegistry registry)
        {
            var calls = await Handlers.FindCalls(registry).ConfigureAwait(false);

            _graph = new HandlerGraph();
            _graph.AddRange(calls);
            _graph.Add(HandlerCall.For <SubscriptionsHandler>(x => x.Handle(new SubscriptionsChanged())));

            _graph.Group();
            Handlers.ApplyPolicies(_graph);

            Services.AddSingleton(_graph);
            Services.AddSingleton <IChannelGraph>(_channels);
            Services.AddSingleton <ILocalWorkerSender>(_localWorker);

            Services.AddTransient <ServiceBusActivator>();


            if (registry.Logging.UseConsoleLogging)
            {
                Services.For <IBusLogger>().Use <ConsoleBusLogger>();
                Services.For <ITransportLogger>().Use <ConsoleTransportLogger>();
            }

            Services.ForSingletonOf <IDelayedJobProcessor>().UseIfNone <InMemoryDelayedJobProcessor>();

            return(Services);
        }
Exemplo n.º 5
0
        private async Task <ServiceRegistry> bootstrap(JasperRegistry registry)
        {
            var calls = await Handlers.FindCalls(registry).ConfigureAwait(false);

            _graph = new HandlerGraph();
            _graph.AddRange(calls);
            _graph.Add(HandlerCall.For <SubscriptionsHandler>(x => x.Handle(new SubscriptionsChanged())));

            _graph.Group();
            Handlers.ApplyPolicies(_graph);

            // Because the built in DI container is too stupid to just build out concrete types
            foreach (var type in _graph.Chains.SelectMany(x => x.Handlers).Select(x => x.HandlerType).Distinct())
            {
                Services.AddScoped(type, type);
            }

            Services.AddSingleton(_graph);
            Services.AddSingleton <IChannelGraph>(_channels);

            Services.AddTransient <ServiceBusActivator>();


            if (registry.Logging.UseConsoleLogging)
            {
                Services.For <IBusLogger>().Use <ConsoleBusLogger>();
            }

            Services.ForSingletonOf <IDelayedJobProcessor>().UseIfNone <InMemoryDelayedJobProcessor>();

            return(Services);
        }
Exemplo n.º 6
0
        public MessagingRoot(MessagingSerializationGraph serialization,
                             JasperOptions settings,
                             HandlerGraph handlers,
                             IDurableMessagingFactory factory,
                             ISubscriberGraph subscribers,
                             IMessageLogger messageLogger,
                             IContainer container,
                             ITransportLogger transportLogger)
        {
            Settings         = settings;
            _handlers        = handlers;
            _transportLogger = transportLogger;
            Factory          = factory;
            Subscribers      = subscribers;
            Transports       = container.QuickBuildAll <ITransport>().ToArray();


            Serialization = serialization;

            Logger = messageLogger;

            Pipeline = new HandlerPipeline(Serialization, handlers, Logger,
                                           container.QuickBuildAll <IMissingHandler>(),
                                           this);

            Workers = new WorkerQueue(Logger, Pipeline, settings);

            Router = new MessageRouter(this, handlers);

            // TODO -- ZOMG this is horrible, and I admit it.
            if (Factory is NulloDurableMessagingFactory f)
            {
                f.ScheduledJobs = ScheduledJobs;
            }
        }
Exemplo n.º 7
0
        public MessagingRoot(MessagingSerializationGraph serialization,
                             JasperOptions options,
                             HandlerGraph handlers,
                             ISubscriberGraph subscribers,
                             IMessageLogger messageLogger,
                             IContainer container,
                             ITransportLogger transportLogger
                             )
        {
            Options          = options;
            Handlers         = handlers;
            _transportLogger = transportLogger;
            Subscribers      = subscribers;
            Transports       = container.QuickBuildAll <ITransport>().ToArray();


            Serialization = serialization;

            Logger = messageLogger;

            Pipeline = new HandlerPipeline(Serialization, handlers, Logger,
                                           container.QuickBuildAll <IMissingHandler>(),
                                           this);

            Workers = new WorkerQueue(Logger, Pipeline, options);

            Router = new MessageRouter(this, handlers);

            _persistence = new Lazy <IEnvelopePersistence>(() => container.GetInstance <IEnvelopePersistence>());
        }
Exemplo n.º 8
0
        public override void SetUp()
        {
            _tracker = new AttemptTracker();

            var options = new JasperOptions();

            options.Extensions.UseMessageTrackingTestingSupport();
            options.Endpoints.As <TransportCollection>().Add(new StubTransport());

            options.Services.AddSingleton(_tracker);

            options.Endpoints.Publish(x => x.Message <ErrorCausingMessage>()
                                      .To("local://1".ToUri()));


            _host = JasperHost.For(options);

            _transport = _host.GetStubTransport();

            _graph = _host.Get <HandlerGraph>();
            _chain = _graph.ChainFor <ErrorCausingMessage>();


            _bus = _host.Get <IMessageContext>();
        }
Exemplo n.º 9
0
 public void Apply(HandlerGraph graph, JasperGenerationRules rules)
 {
     foreach (var chain in graph.Chains.Where(IsSagaRelated))
     {
         Apply(chain, rules.SagaPersistence);
     }
 }
Exemplo n.º 10
0
 public void Apply(HandlerGraph graph, GenerationRules rules, IContainer container)
 {
     foreach (var chain in graph.Chains.Where(IsSagaRelated))
     {
         Apply(chain, rules.GetSagaPersistence(), container);
     }
 }
Exemplo n.º 11
0
 public void Apply(HandlerGraph graph)
 {
     foreach (var chain in graph.Chains.Where(IsSagaRelated))
     {
         Apply(chain, graph.SagaPersistence);
     }
 }
Exemplo n.º 12
0
        public async Task Activate(HandlerGraph handlers, CapabilityGraph capabilities, JasperRuntime runtime, OutgoingChannels channels)
        {
            var capabilityCompilation = capabilities.Compile(handlers, _serialization, channels, runtime, _transports, _lookups);

            var transports = _transports.Where(x => x.State == TransportState.Enabled).ToArray();

            if (!_settings.DisableAllTransports)
            {
                await _settings.ApplyLookups(_lookups);



                channels.StartTransports(_pipeline, _settings, transports);

                _delayedJobs.Start(_pipeline, channels);

                var local = new TransportNode(channels, _settings.MachineName);

                await _nodes.Register(local);
            }

            runtime.Capabilities = await capabilityCompilation;
            if (runtime.Capabilities.Errors.Any() && _settings.ThrowOnValidationErrors)
            {
                throw new InvalidSubscriptionException(runtime.Capabilities.Errors);
            }
        }
Exemplo n.º 13
0
 public void Apply(HandlerGraph graph, JasperGenerationRules rules)
 {
     foreach (var chain in graph.Chains)
     {
         applyToChain(chain);
     }
 }
Exemplo n.º 14
0
        public async Task Activate(HandlerGraph handlers, CapabilityGraph capabilities, JasperRuntime runtime, ChannelGraph channels, LocalWorkerSender localWorker)
        {
            var capabilityCompilation = capabilities.Compile(handlers, _serialization, channels, runtime, _transports, _lookups);

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

            _settings.Workers.Compile(handlers.Chains.Select(x => x.MessageType));

            localWorker.Start(_persistence, _workerQueue);

            if (!_settings.DisableAllTransports)
            {
                await _settings.ApplyLookups(_lookups);

                channels.Start(_settings, transports, _lookups, capabilities);


                _delayedJobs.Start(_workerQueue);
            }

            runtime.Capabilities = await capabilityCompilation;
            if (runtime.Capabilities.Errors.Any() && _settings.ThrowOnValidationErrors)
            {
                throw new InvalidSubscriptionException(runtime.Capabilities.Errors);
            }
        }
Exemplo n.º 15
0
 public void Apply(HandlerGraph graph, JasperGenerationRules rules)
 {
     foreach (var chain in graph.Chains)
     {
         chain.Middleware.Add(new SimpleWrapper());
     }
 }
Exemplo n.º 16
0
 public void Apply(HandlerGraph graph)
 {
     foreach (var chain in graph.Chains)
     {
         chain.Middleware.Add(new SimpleWrapper());
     }
 }
Exemplo n.º 17
0
        public MessagingSerializationGraph(ObjectPoolProvider pooling, MessagingSettings messagingSettings, HandlerGraph handlers, Forwarders forwarders, IEnumerable <ISerializerFactory> serializers, IEnumerable <IMessageDeserializer> readers, IEnumerable <IMessageSerializer> writers)
            : base(pooling, messagingSettings.MediaSelectionMode, messagingSettings.JsonSerialization, forwarders, serializers, readers, writers)
        {
            _handlers = handlers;

            // Work around here to seed this type in the serialization
            RegisterType(typeof(Acknowledgement));
        }
Exemplo n.º 18
0
 public MessageExecutor(IPartialFactory factory, IFubuRequest request, HandlerGraph graph, ILogger logger, Envelope envelope)
 {
     _factory  = factory;
     _request  = request;
     _graph    = graph;
     _logger   = logger;
     _envelope = envelope;
 }
 public MessageExecutor(IPartialFactory factory, IFubuRequest request, HandlerGraph graph, ILogger logger, Envelope envelope)
 {
     _factory = factory;
     _request = request;
     _graph = graph;
     _logger = logger;
     _envelope = envelope;
 }
Exemplo n.º 20
0
        public HandlerPipeline(IEnvelopeSender sender, IEnvelopeSerializer serializer, HandlerGraph graph, IReplyWatcher replies, IBusLogger[] loggers)
        {
            _sender     = sender;
            _serializer = serializer;
            _graph      = graph;
            _replies    = replies;

            Logger = BusLogger.Combine(loggers);
        }
Exemplo n.º 21
0
 public void Apply(HandlerGraph graph, GenerationRules rules, IContainer container)
 {
     // We're adding the StopwatchFrame to all message types,
     // but we *could* filter the application
     foreach (var chain in graph.Chains)
     {
         chain.Middleware.Add(new StopwatchFrame(chain));
     }
 }
Exemplo n.º 22
0
 public MessageRouter(SerializationGraph serializers, IChannelGraph channels, ISubscriptionsRepository subscriptions, HandlerGraph handlers, CompositeLogger logger, UriAliasLookup lookup)
 {
     _serializers   = serializers;
     _channels      = channels;
     _subscriptions = subscriptions;
     _handlers      = handlers;
     _logger        = logger;
     _lookup        = lookup;
 }
Exemplo n.º 23
0
        public MessagingSerializationGraph(HandlerGraph handlers, IEnumerable <ISerializerFactory <IMessageDeserializer, IMessageSerializer> > serializers,
                                           IEnumerable <IMessageDeserializer> readers, IEnumerable <IMessageSerializer> writers)
            : base(serializers, readers, writers)
        {
            _handlers = handlers;

            // Work around here to seed this type in the serialization
            RegisterType(typeof(Acknowledgement));
        }
Exemplo n.º 24
0
 public void Apply(HandlerGraph graph, GenerationRules rules, IContainer container)
 {
     // Important! Create a brand new TransactionalFrame
     // for each chain
     graph
     .Chains
     .Where(x => x.MessageType.Name.EndsWith("Command"))
     .Each(x => x.Middleware.Add(new TransactionalFrame()));
 }
Exemplo n.º 25
0
 public MessageRouter(IMessagingRoot root, HandlerGraph handlers)
 {
     _serializers = root.Serialization;
     _subscribers = root.Subscribers;
     _handlers    = handlers;
     _logger      = root.Logger;
     _settings    = root.Settings;
     _workers     = _handlers.Workers;
 }
Exemplo n.º 26
0
        internal void Apply(HandlerGraph graph)
        {
            foreach (var policy in _globals)
            {
                policy.Apply(graph);
            }

            graph.ErrorHandlers.AddRange(this.As <IHasErrorHandlers>().ErrorHandlers);
        }
Exemplo n.º 27
0
        public HandlerPipeline(BusMessageSerializationGraph serializers, HandlerGraph graph, IReplyWatcher replies, CompositeMessageLogger logger, IEnumerable <IMissingHandler> missingHandlers, Lazy <IServiceBus> bus)
        {
            _serializer      = serializers;
            _graph           = graph;
            _replies         = replies;
            _bus             = bus;
            _missingHandlers = missingHandlers.ToArray();

            Logger = logger;
        }
Exemplo n.º 28
0
        public HandlerPipeline(MessagingSerializationGraph serializers, HandlerGraph graph, IMessageLogger logger,
                               IEnumerable <IMissingHandler> missingHandlers, IMessagingRoot root)
        {
            _serializer      = serializers;
            _graph           = graph;
            _root            = root;
            _missingHandlers = missingHandlers.ToArray();

            Logger = logger;
        }
Exemplo n.º 29
0
        public override void TearDown()
        {
            _host.Dispose();

            _graph     = null;
            _chain     = null;
            _transport = null;
            _bus       = null;
            _host      = null;
        }
Exemplo n.º 30
0
 public MessageRouter(MessagingSerializationGraph serializers, IChannelGraph channels, ISubscriptionsRepository subscriptions, HandlerGraph handlers, IMessageLogger logger, UriAliasLookup lookup, MessagingSettings settings)
 {
     _serializers   = serializers;
     _channels      = channels;
     _subscriptions = subscriptions;
     _handlers      = handlers;
     _logger        = logger;
     _lookup        = lookup;
     _settings      = settings;
 }
Exemplo n.º 31
0
        public HandlerPipeline(IEnvelopeSender sender, BusMessageSerializationGraph serializers, HandlerGraph graph, IReplyWatcher replies, CompositeLogger logger, IEnumerable <IMissingHandler> missingHandlers)
        {
            _sender          = sender;
            _serializer      = serializers;
            _graph           = graph;
            _replies         = replies;
            _missingHandlers = missingHandlers.ToArray();

            Logger = logger;
        }
Exemplo n.º 32
0
        public HandlersTableTag(HandlerGraph handlers)
        {
            AddClass("table");
            AddClass("handlers");

            AddHeaderRow(row => {
                row.Header("Message");
                row.Header("Exception Policies");
                row.Header("Other");
                row.Header("Handlers");
            });

            handlers.Where(x => !FubuCore.TypeExtensions.Closes(x.InputType(), typeof(JobRequest<>))).OrderBy(x => x.InputType().Name)
                .Each(chain => AddBodyRow(row => addRow(row, chain)));
        }
Exemplo n.º 33
0
        public Task<BehaviorChain[]> BuildChains(BehaviorGraph graph, IPerfTimer timer)
        {
            var finders = HandlerSources.Select(x => x.FindCalls(graph.ApplicationAssembly)).ToArray();
            return Task.WhenAll(finders).ContinueWith(all =>
            {
                var handlers = new HandlerGraph();

                var allCalls = all.Result.SelectMany(x => x).Distinct();

                handlers.Add(allCalls);

                handlers.Compile();

                return handlers.OfType<BehaviorChain>().ToArray();
            });
        }
Exemplo n.º 34
0
        private static IEnumerable<BehaviorChain> buildChains(BehaviorGraph graph)
        {
            var handlers = new HandlerGraph
            {
                HandlerCall.For<SubscriptionsHandler>(x => x.Handle(new SubscriptionRequested())),
                HandlerCall.For<SubscriptionsHandler>(x => x.Handle(new SubscriptionsChanged())),
                HandlerCall.For<SubscriptionsHandler>(x => x.Handle(new SubscriptionsRemoved())),
                HandlerCall.For<MonitoringControlHandler>(x => x.Handle(new TakeOwnershipRequest())),
                HandlerCall.For<MonitoringControlHandler>(x => x.Handle(new TaskHealthRequest())),
                HandlerCall.For<MonitoringControlHandler>(x => x.Handle(new TaskDeactivation()))
            };

            handlers.Compile();

            // TODO -- need to apply [ModifyChainAttribute]'s here. See GH-958

            return handlers;
        }
Exemplo n.º 35
0
 public MessagesFubuDiagnostics(HandlerGraph graph)
 {
     _graph = graph;
 }
Exemplo n.º 36
0
        public void SetUp()
        {
            theGraph = new HandlerGraph();

            concreteCall = HandlerCall.For<ConcreteHandler>(x => x.M1(null));

            concreteCall.Clone().ShouldEqual(concreteCall);

            concreteCall2 = HandlerCall.For<ConcreteHandler>(x => x.M2(null));
            concreteCall3 = HandlerCall.For<ConcreteHandler>(x => x.M3(null));
            concreteCall4 = HandlerCall.For<ConcreteHandler>(x => x.M4(null));
        }
Exemplo n.º 37
0
        public void merging_matching_chains_merges_the_handlers_for_the_same_message()
        {
            theGraph.Add(concreteCall);

            var other = new HandlerGraph();
            other.Add(concreteCall2);
            other.Add(concreteCall3);

            theGraph.Import(other);

            theGraph.ShouldHaveCount(1);

            var chain = theGraph.ChainFor(typeof (Input));
            chain.ElementAt(0).Equals(concreteCall).ShouldBeTrue();
            chain.ElementAt(1).Equals(concreteCall2).ShouldBeTrue();
            chain.ElementAt(2).Equals(concreteCall3).ShouldBeTrue();
        }
Exemplo n.º 38
0
        public void merging_adds_a_chain_for_all_new_message_type()
        {
            theGraph.Add(concreteCall);

            var other = new HandlerGraph();
            other.Add(concreteCall4);

            theGraph.Import(other);

            theGraph.Select(x => x.InputType())
                .ShouldHaveTheSameElementsAs(typeof(Input), typeof(DifferentInput));
        }
Exemplo n.º 39
0
        public void applies_general_action_from_imported_graph()
        {
            var general = HandlerCall.For<ConcreteHandler>(x => x.General(null));
            var specific1 = HandlerCall.For<ConcreteHandler>(x => x.Specific1(null));
            var specific2 = HandlerCall.For<ConcreteHandler>(x => x.Specific2(null));

            theGraph.Add(specific1);

            var other = new HandlerGraph();
            other.Add(general);
            other.Add(specific2);

            theGraph.Import(other);

            theGraph.ApplyGeneralizedHandlers();

            theGraph.ChainFor(typeof(Concrete1)).Last()
                .Equals(general).ShouldBeTrue();

            theGraph.ChainFor(typeof(Concrete2)).Last()
                .Equals(general).ShouldBeTrue();
        }