public StateMachineSagaSpecification(SagaStateMachine <TInstance> stateMachine, ISagaRepository <TInstance> repository) { _stateMachine = stateMachine; _repository = repository; _pipeSpecifications = new List <IPipeSpecification <SagaConsumeContext <TInstance> > >(); }
public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector pipe, IKernel kernel) where TInstance : class, SagaStateMachineInstance { SagaStateMachine <TInstance> stateMachine = kernel.ResolveSagaStateMachine <TInstance>(); return(pipe.ConnectStateMachineSaga(stateMachine, kernel)); }
public void Configure(IReceiveEndpointConfigurator configurator, IConfigurationServiceProvider configurationServiceProvider) { ISagaStateMachineFactory stateMachineFactory = configurationServiceProvider.GetRequiredService <ISagaStateMachineFactory>(); SagaStateMachine <TInstance> stateMachine = stateMachineFactory.CreateStateMachine <TInstance>(); IStateMachineActivityFactory activityFactory = configurationServiceProvider.GetRequiredService <IStateMachineActivityFactory>(); void AddStateMachineActivityFactory(ConsumeContext context) { context.GetOrAddPayload(() => activityFactory); } var repositoryFactory = configurationServiceProvider.GetRequiredService <ISagaRepositoryFactory>(); ISagaRepository <TInstance> repository = repositoryFactory.CreateSagaRepository <TInstance>(AddStateMachineActivityFactory); var stateMachineConfigurator = new StateMachineSagaConfigurator <TInstance>(stateMachine, repository, configurator); GetSagaDefinition(configurationServiceProvider) .Configure(configurator, stateMachineConfigurator); foreach (Action <ISagaConfigurator <TInstance> > action in _configureActions) { action(stateMachineConfigurator); } configurator.AddEndpointSpecification(stateMachineConfigurator); }
public StateMachineEventConnectorFactory(SagaStateMachine <TInstance> stateMachine, EventCorrelation <TInstance, TMessage> correlation) { var consumeFilter = new StateMachineSagaMessageFilter <TInstance, TMessage>(stateMachine, correlation.Event); _connector = new StateMachineSagaMessageConnector <TInstance, TMessage>(consumeFilter, correlation.Policy, correlation.FilterFactory, correlation.MessageFilter, correlation.ConfigureConsumeTopology); }
/// <summary> /// Subscribe a state machine saga to the endpoint /// </summary> /// <typeparam name="TInstance">The state machine instance type</typeparam> /// <param name="configurator"></param> /// <param name="container">The Lamar Lifetime Container to resolve the repository</param> /// <param name="configure">Optionally configure the saga</param> /// <param name="configureScope">Configuration for scope container</param> /// <returns></returns> public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, IContainer container, Action <ISagaConfigurator <TInstance> > configure = null, Action <ConsumeContext> configureScope = null) where TInstance : class, SagaStateMachineInstance { SagaStateMachine <TInstance> stateMachine = GetSagaStateMachine <TInstance>(container); StateMachineSaga(configurator, stateMachine, container, configure, configureScope); }
public StateMachineEventConnectorFactory(SagaStateMachine <TInstance> stateMachine, EventCorrelation <TInstance, TMessage> correlation) { _consumeFilter = new StateMachineSagaMessageFilter <TInstance, TMessage>(stateMachine, correlation.Event); _sagaFilterFactory = correlation.FilterFactory; _policy = correlation.Policy; _messageFilter = correlation.MessageFilter; }
public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector pipe, IContainer container, Action <ConsumeContext> configureScope = null) where TInstance : class, SagaStateMachineInstance { SagaStateMachine <TInstance> stateMachine = GetSagaStateMachine <TInstance>(container); return(pipe.ConnectStateMachineSaga(stateMachine, container, configureScope)); }
/// <summary> /// Subscribe a state machine saga to the endpoint /// </summary> /// <typeparam name="TInstance">The state machine instance type</typeparam> /// <param name="configurator"></param> /// <param name="kernel">The Windsor Lifetime Container to resolve the repository</param> /// <param name="configure">Optionally configure the saga</param> /// <returns></returns> public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, IKernel kernel, Action <ISagaConfigurator <TInstance> > configure = null) where TInstance : class, SagaStateMachineInstance { SagaStateMachine <TInstance> stateMachine = kernel.ResolveSagaStateMachine <TInstance>(); StateMachineSaga(configurator, stateMachine, kernel, configure); }
/// <summary> /// Subscribe a state machine saga to the endpoint /// </summary> /// <typeparam name="TInstance">The state machine instance type</typeparam> /// <param name="configurator"></param> /// <param name="scope">The Autofac Lifetime Container to resolve the repository</param> /// <param name="configure">Optionally configure the saga</param> /// <param name="name">The name to use for the scope created for each message</param> /// <param name="configureScope">Configuration for scope container</param> /// <returns></returns> public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, ILifetimeScope scope, Action <ISagaConfigurator <TInstance> > configure = null, string name = "message", Action <ContainerBuilder, ConsumeContext> configureScope = null) where TInstance : class, SagaStateMachineInstance { SagaStateMachine <TInstance> stateMachine = ResolveSagaStateMachine <TInstance>(scope); StateMachineSaga(configurator, stateMachine, scope, configure, name, configureScope); }
public CorrelatedByEventCorrelationBuilder(SagaStateMachine <TInstance> machine, Event <TData> @event) { var configurator = new MassTransitEventCorrelationConfigurator <TInstance, TData>(machine, @event, null); configurator.CorrelateById(x => x.Message.CorrelationId); _configurator = configurator; }
public static TSaga ContainsInState <TSaga>(this ISagaList <TSaga> sagas, Guid sagaId, State state, SagaStateMachine <TSaga> machine) where TSaga : class, SagaStateMachineInstance { bool any = sagas.Select(x => x.CorrelationId == sagaId && machine.Accessor.GetState(x).Result.Equals(state)).Any(); return(any ? sagas.Contains(sagaId) : null); }
public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector pipe, ILifetimeScope scope, string name = "message", Action <ContainerBuilder, ConsumeContext> configureScope = null) where TInstance : class, SagaStateMachineInstance { SagaStateMachine <TInstance> stateMachine = ResolveSagaStateMachine <TInstance>(scope); return(pipe.ConnectStateMachineSaga(stateMachine, scope, name, configureScope)); }
public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector pipe, IWindsorContainer container) where TInstance : class, SagaStateMachineInstance { ISagaStateMachineFactory stateMachineFactory = new WindsorSagaStateMachineFactory(container.Kernel); SagaStateMachine <TInstance> stateMachine = stateMachineFactory.CreateStateMachine <TInstance>(); return(pipe.ConnectStateMachineSaga(stateMachine, container)); }
/// <summary> /// Subscribe a state machine saga to the endpoint /// </summary> /// <typeparam name="TInstance">The state machine instance type</typeparam> /// <param name="configurator"></param> /// <param name="stateMachine">The state machine</param> /// <param name="repository">The saga repository for the instances</param> /// <returns></returns> public static void StateMachineSaga <TInstance>( this IReceiveEndpointConfigurator configurator, SagaStateMachine <TInstance> stateMachine, ISagaRepository <TInstance> repository) where TInstance : class, SagaStateMachineInstance { var stateMachineConfigurator = new StateMachineSagaSpecification <TInstance>(stateMachine, repository); configurator.AddEndpointSpecification(stateMachineConfigurator); }
/// <summary> /// Subscribe a state machine saga to the endpoint /// </summary> /// <typeparam name="TInstance">The state machine instance type</typeparam> /// <param name="configurator"></param> /// <param name="container">The Lamar Lifetime Container to resolve the repository</param> /// <param name="configure">Optionally configure the saga</param> /// <param name="configureScope">Configuration for scope container</param> /// <returns></returns> public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, IContainer container, Action <ISagaConfigurator <TInstance> > configure = null, Action <ConsumeContext> configureScope = null) where TInstance : class, SagaStateMachineInstance { ISagaStateMachineFactory stateMachineFactory = new LamarSagaStateMachineFactory(container); SagaStateMachine <TInstance> stateMachine = stateMachineFactory.CreateStateMachine <TInstance>(); StateMachineSaga(configurator, stateMachine, container, configure, configureScope); }
/// <summary> /// Subscribe a state machine saga to the endpoint /// </summary> /// <typeparam name="TInstance">The state machine instance type</typeparam> /// <param name="configurator"></param> /// <param name="container">The Windsor Lifetime Container to resolve the repository</param> /// <param name="configure">Optionally configure the saga</param> /// <returns></returns> public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, IWindsorContainer container, Action <ISagaConfigurator <TInstance> > configure = null) where TInstance : class, SagaStateMachineInstance { ISagaStateMachineFactory stateMachineFactory = new WindsorSagaStateMachineFactory(container.Kernel); SagaStateMachine <TInstance> stateMachine = stateMachineFactory.CreateStateMachine <TInstance>(); StateMachineSaga(configurator, stateMachine, container, configure); }
public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector pipe, IContainer scope, Action <ConsumeContext> configureScope = null) where TInstance : class, SagaStateMachineInstance { ISagaStateMachineFactory stateMachineFactory = new LamarSagaStateMachineFactory(scope); SagaStateMachine <TInstance> stateMachine = stateMachineFactory.CreateStateMachine <TInstance>(); return(pipe.ConnectStateMachineSaga(stateMachine, scope, configureScope)); }
public SagaEventConnectorFactory(ISagaRepository <TSaga> sagaRepository, ISagaPolicyFactory policyFactory, DataEvent <TSaga, TMessage> dataEvent, IEnumerable <State> states) { _sagaRepository = sagaRepository; _policyFactory = policyFactory; _dataEvent = dataEvent; _states = states; _removeExpression = SagaStateMachine <TSaga> .GetCompletedExpression(); }
public MessageCorrelationIdEventCorrelationBuilder(SagaStateMachine <TInstance> machine, Event <TData> @event, IMessageCorrelationId <TData> messageCorrelationId) { var configurator = new MassTransitEventCorrelationConfigurator <TInstance, TData>(machine, @event, null); configurator.CorrelateById(x => messageCorrelationId.TryGetCorrelationId(x.Message, out var correlationId) ? correlationId : throw new ArgumentException($"The message {TypeMetadataCache<TData>.ShortName} did not have a correlationId")); _configurator = configurator; }
public StateMachineSagaConfigurator(SagaStateMachine <TInstance> stateMachine, ISagaRepository <TInstance> repository, ISagaConfigurationObserver observer) { _stateMachine = stateMachine; _repository = repository; _connector = new StateMachineConnector <TInstance>(_stateMachine); _specification = _connector.CreateSagaSpecification <TInstance>(); _specification.ConnectSagaConfigurationObserver(observer); }
public MassTransitEventCorrelation(SagaStateMachine <TInstance> machine, Event <TData> @event, SagaFilterFactory <TInstance, TData> sagaFilterFactory, IFilter <ConsumeContext <TData> > messageFilter, IPipe <ConsumeContext <TData> > missingPipe, ISagaFactory <TInstance, TData> sagaFactory, bool insertOnInitial) { _event = @event; FilterFactory = sagaFilterFactory; _messageFilter = messageFilter; _missingPipe = missingPipe; _sagaFactory = sagaFactory; _insertOnInitial = insertOnInitial; _machine = machine; _policy = new Lazy <ISagaPolicy <TInstance, TData> >(GetSagaPolicy); }
public StateMachineConnector(SagaStateMachine <TInstance> stateMachine) { _stateMachine = stateMachine; try { _connectors = StateMachineEvents().ToList(); } catch (Exception ex) { throw new ConfigurationException($"Failed to create the state machine connector for {TypeMetadataCache<TInstance>.ShortName}", ex); } }
public MassTransitEventCorrelationConfigurator(SagaStateMachine <TInstance> machine, Event <TData> @event, EventCorrelation existingCorrelation) { _event = @event; _machine = machine; _insertOnInitial = false; _sagaFactory = new DefaultSagaFactory <TInstance, TData>(); var correlation = existingCorrelation as EventCorrelation <TInstance, TData>; if (correlation != null) { _sagaFilterFactory = correlation.FilterFactory; _messageFilter = correlation.MessageFilter; } }
public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, IContainer container, Action <ISagaConfigurator <TInstance> > configure = null) where TInstance : class, SagaStateMachineInstance { ISagaStateMachineFactory stateMachineFactory = new LamarSagaStateMachineFactory(container); SagaStateMachine <TInstance> stateMachine = stateMachineFactory.CreateStateMachine <TInstance>(); ISagaRepositoryFactory repositoryFactory = new LamarStateMachineSagaRepositoryFactory(container); ISagaRepository <TInstance> sagaRepository = repositoryFactory.CreateSagaRepository <TInstance>(); var stateMachineConfigurator = new StateMachineSagaConfigurator <TInstance>(stateMachine, sagaRepository, configurator); configure?.Invoke(stateMachineConfigurator); configurator.AddEndpointSpecification(stateMachineConfigurator); }
/// <summary> /// Subscribe a state machine saga to the endpoint /// </summary> /// <typeparam name="TInstance">The state machine instance type</typeparam> /// <param name="configurator"></param> /// <param name="scope">The Autofac Lifetime Container to resolve the repository</param> /// <param name="configure">Optionally configure the saga</param> /// <param name="name">The name to use for the scope created for each message</param> /// <param name="configureScope">Configuration for scope container</param> /// <returns></returns> public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, ILifetimeScope scope, Action <ISagaConfigurator <TInstance> > configure = null, string name = "message", Action <ContainerBuilder, ConsumeContext> configureScope = null) where TInstance : class, SagaStateMachineInstance { ISagaStateMachineFactory stateMachineFactory = new AutofacSagaStateMachineFactory(scope); SagaStateMachine <TInstance> stateMachine = stateMachineFactory.CreateStateMachine <TInstance>(); ISagaRepositoryFactory repositoryFactory = new AutofacStateMachineSagaRepositoryFactory(new SingleLifetimeScopeProvider(scope), name, configureScope); ISagaRepository <TInstance> sagaRepository = repositoryFactory.CreateSagaRepository <TInstance>(); var stateMachineConfigurator = new StateMachineSagaConfigurator <TInstance>(stateMachine, sagaRepository, configurator); configure?.Invoke(stateMachineConfigurator); configurator.AddEndpointSpecification(stateMachineConfigurator); }
public void Configure(IReceiveEndpointConfigurator configurator, IConfigurationServiceProvider configurationServiceProvider) { ISagaStateMachineFactory stateMachineFactory = configurationServiceProvider.GetRequiredService<ISagaStateMachineFactory>(); SagaStateMachine<TInstance> stateMachine = stateMachineFactory.CreateStateMachine<TInstance>(); var repositoryFactory = configurationServiceProvider.GetRequiredService<ISagaRepositoryFactory>(); ISagaRepository<TInstance> repository = repositoryFactory.CreateSagaRepository<TInstance>(); var stateMachineConfigurator = new StateMachineSagaConfigurator<TInstance>(stateMachine, repository, configurator); LogContext.Debug?.Log("Configuring endpoint {Endpoint}, Saga: {SagaType}, State Machine: {StateMachineType}", configurator.InputAddress.GetLastPart(), TypeMetadataCache<TInstance>.ShortName, TypeMetadataCache.GetShortName(stateMachine.GetType())); GetSagaDefinition(configurationServiceProvider) .Configure(configurator, stateMachineConfigurator); foreach (Action<ISagaConfigurator<TInstance>> action in _configureActions) action(stateMachineConfigurator); configurator.AddEndpointSpecification(stateMachineConfigurator); }
public IEnumerable <ISagaSubscriptionConnector> Create() { IEventBinder <TSaga> eventBinder; if (SagaStateMachine <TSaga> .TryGetEventBinder(_dataEvent, out eventBinder)) { yield return((ISagaSubscriptionConnector)FastActivator.Create(typeof(PropertySagaSubscriptionConnector <,>), new[] { typeof(TSaga), typeof(TMessage) }, new object[] { _sagaRepository, _dataEvent, _states, _policyFactory, _removeExpression, eventBinder })); } else if (typeof(TMessage).Implements <ICorrelatedBy <Guid> >()) { yield return((ISagaSubscriptionConnector)FastActivator.Create(typeof(CorrelatedSagaSubscriptionConnector <,>), new[] { typeof(TSaga), typeof(TMessage) }, new object[] { _sagaRepository, _dataEvent, _states, _policyFactory, _removeExpression })); } else { throw new NotSupportedException("No method to connect to event was found for " + typeof(TMessage).FullName); } }
public IPipelineSink <TMessage> Create(DataEvent <TSaga, TMessage> eevent, IEnumerable <State> states) { Type messageType = typeof(TMessage); Expression <Func <TSaga, bool> > removeExpression = SagaStateMachine <TSaga> .GetCompletedExpression(); ISagaPolicy <TSaga, TMessage> policy = _policyFactory.GetPolicy <TSaga, TMessage>(states, removeExpression); Expression <Func <TSaga, TMessage, bool> > expression; if (SagaStateMachine <TSaga> .TryGetCorrelationExpressionForEvent(eevent, out expression)) { return(this.FastInvoke <SagaStateMachineMessageSinkFactory <TSaga, TMessage>, IPipelineSink <TMessage> >("CreateSink", eevent, policy, expression)); } // we check for a standard correlation interface second if (messageType.GetInterfaces().Where(x => x == typeof(CorrelatedBy <Guid>)).Count() > 0) { return(this.FastInvoke <SagaStateMachineMessageSinkFactory <TSaga, TMessage>, IPipelineSink <TMessage> >("CreateCorrelatedSink", eevent, policy)); } throw new NotSupportedException("No method to connect to event was found for " + typeof(TMessage).FullName); }
public void StateMachineSagaConfigured <TInstance>(ISagaConfigurator <TInstance> configurator, SagaStateMachine <TInstance> stateMachine) where TInstance : class, ISaga, SagaStateMachineInstance { _sagaObservers.StateMachineSagaConfigured(configurator, stateMachine); }
public void StateMachineSagaConfigured <TInstance>(ISagaConfigurator <TInstance> configurator, SagaStateMachine <TInstance> stateMachine) where TInstance : class, ISaga, SagaStateMachineInstance { }