public static TriggerConfigurer FromMessage <TStateMachine, TMessage, TMessageContext>( this TriggerConfigurer configurer, Func <TMessage, TMessageContext, Guid> correlationFunc, Func <TStateMachine, TMessage, TMessageContext, Task> machineFunc, Action <IConsumerConfigurationBuilder> consumeConfig = null ) { Func <object[], Task <Acknowledgement> > genericHandler = args => machineFunc((TStateMachine)args[0], (TMessage)args[1], (TMessageContext)args[2]) .ContinueWith <Acknowledgement>(t => new Ack()); Func <object, object, Guid> genericCorrFunc = (msg, ctx) => correlationFunc((TMessage)msg, (TMessageContext)ctx); return(configurer.From(SubscribePipe, context => { var stateMachineContext = new StateMachineContext(context); stateMachineContext.Properties.Add(StateMachineKey.Type, typeof(TStateMachine)); stateMachineContext.AddMessageContextType <TMessageContext>(); stateMachineContext.Properties.Add(StateMachineKey.CorrelationFunc, genericCorrFunc); stateMachineContext.UseLazyCorrelationArgs(ctx => new[] { ctx.GetMessage(), ctx.GetMessageContext() }); stateMachineContext.Properties.Add(PipeKey.MessageType, typeof(TMessage)); stateMachineContext.Properties.Add(PipeKey.ConfigurationAction, consumeConfig); stateMachineContext.Properties.Add(PipeKey.MessageHandler, genericHandler); stateMachineContext.UseLazyHandlerArgs(ctx => new[] { ctx.GetStateMachine(), ctx.GetMessage(), ctx.GetMessageContext() }); })); }
public MessageSequence(IBusClient client, INamingConventions naming, RawRabbitConfiguration clientCfg, SequenceModel model = null) : base(model) { _client = client; _naming = naming; _clientCfg = clientCfg; _triggerConfigurer = new TriggerConfigurer(); _stepDefinitions = new Queue <StepDefinition>(); _subscriptions = new List <Subscription.ISubscription>(); }
public static TriggerConfigurer FromMessage <TStateMachine, TMessage, TMessageContext>( this TriggerConfigurer configurer, Func <TMessage, TMessageContext, Guid> correlationFunc, Action <TStateMachine, TMessage, TMessageContext> stateMachineAction, Action <IConsumerConfigurationBuilder> consumeConfig = null) { return(configurer.FromMessage <TStateMachine, TMessage, TMessageContext>( correlationFunc, (machine, message, context) => { stateMachineAction(machine, message, context); return Task.FromResult(0); }, consumeConfig)); }
public MessageSequence(IBusClient client, INamingConventions naming, ZyRabbitConfiguration clientCfg, ILogger <MessageSequence> logger, SequenceModel model = null) : base(model) { _client = client ?? throw new ArgumentNullException(nameof(client)); _naming = naming ?? throw new ArgumentNullException(nameof(naming)); _clientCfg = clientCfg ?? throw new ArgumentNullException(nameof(clientCfg)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _triggerConfigurer = new TriggerConfigurer(); _stepDefinitions = new Queue <StepDefinition>(); _subscriptions = new List <Subscription.ISubscription>(); }
public override void ConfigureTriggers(TriggerConfigurer trigger) { trigger .FromMessage <GenericProcess, CreateTask>( process => Guid.NewGuid(), (task, msg) => task.CreateAsync(msg.Name, msg.DeadLine)) .FromMessage <GenericProcess, StartTask>( start => start.TaskId, (task, msg) => task.StartAsync(msg.Assignee)) .FromMessage <GenericProcess, PauseTask>( pause => pause.TaskId, (task, pause) => task.PauseAsync(pause.Reason)) .FromMessage <GenericProcess, ResumeTask>( pause => pause.TaskId, (task, msg) => task.ResumeAsync()) .FromMessage <GenericProcess, CompleteTask>( complete => complete.TaskId, (task, complete) => task.CompleteAsync()) .FromMessage <GenericProcess, AbortTask>( abort => abort.TaskId, (task, abort) => task.Abort(abort.Reason) ); }