public static IDisposable TimerSubscribe(this IPubSubBus messageBus, string topic, int multiple, Action <IActionSubscriptionBuilder <MessageTimerEvent> > build) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); Assert.IsInRange(multiple, nameof(multiple), 1, int.MaxValue); Assert.ArgumentNotNull(build, nameof(build)); topic = topic ?? string.Empty; var module = messageBus.Modules.Get <MessageTimerModule>(); if (module == null) { messageBus.Logger.Warn($"Subscribed to Timer message {topic} but the message timer module has not been initialized. Did you forget to call .{nameof(InitializeMessageTimer)}() first?"); } else if (!module.TimerExists(topic)) { messageBus.Logger.Warn($"Subscribed to Timer message {topic} but that timer does not exist. You must call .{nameof(StartTimer)}({topic}) to activate that timer"); } return(messageBus.Subscribe <MessageTimerEvent>(builder => { var b2 = builder.WithTopic(topic); build?.Invoke(b2); var b3 = b2 as IDetailsSubscriptionBuilder <MessageTimerEvent>; b3?.WithFilter(t => t.Id % multiple == 0); })); }
/// <summary> /// Setup round-robin distribution rules for Publish operations /// </summary> /// <typeparam name="TPayload"></typeparam> /// <param name="messageBus"></param> /// <param name="inTopics"></param> /// <param name="outTopics"></param> /// <returns></returns> public static IDisposable SetupPublishDistribution <TPayload>(this IPubSubBus messageBus, string[] inTopics, IEnumerable <string> outTopics) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); var rule = new RoundRobinDistributeRule <TPayload>(outTopics); return(messageBus.PublishRouter.AddPublishRouteRule(inTopics, rule)); }
public Saga(IPubSubBus messageBus, ISagaDataRepository <TState, TKey> repository, int threadId) { MessageBus = messageBus; _repository = repository; _threadId = threadId; _tokens = new DisposableCollection(); }
public SubscriptionScanner(IPubSubBus messageBus, ILogger logger) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); _logger = logger ?? messageBus.Logger; _builder = new UntypedSubscriptionBuilder(messageBus); }
public EventSourceContext(IPubSubBus messageBus) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); _messageBus = messageBus; IterationDelayMs = -1; Modules = new ReadOnlyModules(messageBus); WorkerPool = new ReadOnlyWorkerPool(messageBus.WorkerPool); }
/// <summary> /// Setup rules to route the Published message by inspecting the contents of the payload /// </summary> /// <typeparam name="TPayload"></typeparam> /// <param name="messageBus"></param> /// <param name="inTopics"></param> /// <param name="getTopic"></param> /// <returns></returns> public static IDisposable SetupPublishByExamination <TPayload>(this IPubSubBus messageBus, string[] inTopics, Func <TPayload, string> getTopic) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); Assert.ArgumentNotNull(getTopic, nameof(getTopic)); var rule = new PayloadExamineRule <TPayload>(getTopic); return(messageBus.PublishRouter.AddPublishRouteRule(inTopics, rule)); }
public NodeRepublishSubscriptionHandler(ISubscriptionHandler <TPayload> inner, IPubSubBus messageBus, string nodeKey, string outputTopic, string errorTopic) { _inner = inner; _messageBus = messageBus; _nodeKey = nodeKey; _outputTopic = outputTopic; _errorTopic = errorTopic; }
public EventSourceModule(IPubSubBus messageBus, ILogger logger) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); _messageBus = messageBus; _logger = logger ?? messageBus.Logger; _threads = new ConcurrentDictionary <Guid, IntervalWorkerThread>(); _tokens = new ConcurrentDictionary <Guid, IDisposable>(); }
public SagasModule(IPubSubBus messageBus, int numberOfThreads) { Assert.IsInRange(numberOfThreads, nameof(numberOfThreads), 1, 50); _messageBus = messageBus; _numberOfThreads = numberOfThreads; _threadTokens = new WorkerToken[numberOfThreads]; _sagas = new ConcurrentDictionary <Guid, IDisposable>(); _currentThreadIndex = 0; }
public SubscriptionBuilder(IPubSubBus messageBus, IWorkerPool workerPool) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); Assert.ArgumentNotNull(workerPool, nameof(workerPool)); _dispatchType = DispatchThreadType.NoPreference; _workerPool = workerPool; MessageBus = messageBus; Topics = null; }
private static IDisposable Subscribe(IPubSubBus messageBus, Action <TPayload> action, Action <IThreadSubscriptionBuilder <TPayload> > build, string channelName) { var token = messageBus.Subscribe <TPayload>(b => { var c = b.WithTopic(channelName).Invoke(action); build?.Invoke(c); }); return(token); }
public static IDisposable InitializeSagas(this IPubSubBus messageBus, int numberOfThreads = 1) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); var existing = messageBus.Modules.Get <SagasModule>(); if (existing != null) { throw new Exception("Sagas module is already initialized"); } return(messageBus.Modules.Add(new SagasModule(messageBus, numberOfThreads))); }
public WrappedAction <TPayload> WrapAction(IPubSubBus messageBus, Action <TPayload> action, Action <IThreadSubscriptionBuilder <TPayload> > build) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); Assert.ArgumentNotNull(action, nameof(action)); var topic = Guid.NewGuid().ToString(); var token = Subscribe(messageBus, action, build, topic); var newAction = CreateAction(messageBus, topic); return(new WrappedAction <TPayload>(newAction, token, topic)); }
/// <summary> /// Add predicate-based routing rules for Publish operations /// </summary> /// <typeparam name="TPayload"></typeparam> /// <param name="messageBus"></param> /// <param name="build"></param> /// <returns></returns> public static IDisposable SetupPublishRouting <TPayload>(this IPubSubBus messageBus, Action <IFilterRouteBuilderMultiInput <TPayload> > build) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); Assert.ArgumentNotNull(build, nameof(build)); var builder = new FilterRouteBuilder <TPayload>(); build(builder); var router = builder.Build(); return(messageBus.PublishRouter.AddPublishRouteRule(builder.InTopics, router)); }
/// <summary> /// Build a subscription using common options /// </summary> /// <typeparam name="TPayload">The type of object to listen for</typeparam> /// <param name="messageBus">The message bus</param> /// <param name="build">Lambda function to setup the subscription builder.</param> /// <returns>The subscription token which, when disposed, cancels the subscription.</returns> public static IDisposable Subscribe <TPayload>(this IPubSubBus messageBus, Action <ITopicSubscriptionBuilder <TPayload> > build) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); Assert.ArgumentNotNull(build, nameof(build)); var builder = new SubscriptionBuilder <TPayload>(messageBus, messageBus.WorkerPool); build(builder); var subscription = builder.BuildSubscription(); var token = messageBus.Subscribe(builder.Topics, subscription); return(builder.WrapToken(token)); }
public static IDisposable CreateSaga <TState, TKey>(this IPubSubBus messageBus, Action <ISagaBuilder <TState, TKey> > build) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); Assert.ArgumentNotNull(build, nameof(build)); var module = messageBus.Modules.Get <SagasModule>(); if (module == null) { throw new Exception($"Must initialize the Sagas module first. Call .{nameof(InitializeSagas)}()"); } var builder = new SagaBuilder <TState, TKey>(); build(builder); var saga = module.CreateSaga <TState, TKey>(); builder.BuildTo(saga); return(module.AddSaga(saga)); }
public static IDisposable SubscribeEnvelopeUntyped(this IPubSubBus messageBus, Type payloadType, string[] topics, object target, MethodInfo subscriber, bool useWeakReference = false) { return(new UntypedSubscriptionBuilder(messageBus).SubscribeEnvelopeUntyped(payloadType, topics, target, subscriber, useWeakReference)); }
/// <summary> /// Convenience method to subscribe to a single topic /// </summary> /// <typeparam name="TPayload"></typeparam> /// <param name="messageBus"></param> /// <param name="topic"></param> /// <param name="subscription"></param> /// <returns>The subscription token which, when disposed, cancels the subscription</returns> public static IDisposable Subscribe <TPayload>(this IPubSubBus messageBus, string topic, ISubscription <TPayload> subscription) { return(messageBus.Subscribe(new[] { topic ?? string.Empty }, subscription)); }
public UntypedSubscriptionBuilder(IPubSubBus messageBus) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); _messageBus = messageBus; }
private static Action <TPayload> CreateAction(IPubSubBus messageBus, string channelName) { void NewAction(TPayload t) => messageBus.Publish(channelName, t); return(NewAction); }
public static IDisposable AutoWireupSubscribers(this IPubSubBus messageBus, object obj, bool useWeakReference = false) { var tokens = new SubscriptionScanner(messageBus, messageBus.Logger).DetectAndWireUpAll(obj, useWeakReference); return(new DisposableCollection(tokens)); }
public static IDisposable SubscribeUntyped(this IPubSubBus messageBus, Type payloadType, string[] topics, Action act, bool useWeakReference = false) { return(new UntypedSubscriptionBuilder(messageBus).SubscribeUntyped(payloadType, topics, act, useWeakReference)); }
public static WrappedAction <TPayload> WrapAction <TPayload>(this IPubSubBus messageBus, Action <TPayload> action, Action <IThreadSubscriptionBuilder <TPayload> > build = null) { return(new ActionWrapper <TPayload>().WrapAction(messageBus, action, build)); }
/// <summary> /// Initialize the EventSourceModule. This method must be called before calling any RunEventSource method variant /// </summary> /// <param name="messageBus"></param> /// <returns></returns> public static IDisposable InitializeEventSources(this IPubSubBus messageBus) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); return(messageBus.Modules.Add(new EventSourceModule(messageBus, messageBus.Logger))); }