public EventBusSpec() { _bus = new TestActorEventBus(); _evt = new Notification(TestActor, 1); _classifier = typeof(Notification); _subscriber = TestActor; }
/// <summary> /// Create <see cref="Props"/> for an <see cref="ActorEventBusManager"/> to manage the specified <see cref="ActorEventBus{TEvent,TClassifier}">actor-based event bus</see>. /// </summary> /// <typeparam name="TEvent"> /// The base event type used by the bus. /// </typeparam> /// <typeparam name="TClassifier"> /// The type used by the bus to classify events. /// </typeparam> /// <param name="eventBus"> /// The event bus to be managed by the actor. /// </param> /// <returns> /// The configured <see cref="Props"/>. /// </returns> public static Props Props <TEvent, TClassifier>(ActorEventBus <TEvent, TClassifier> eventBus) { if (eventBus == null) { throw new ArgumentNullException(nameof(eventBus)); } Type eventBusType = MakeActorEventBusType <TEvent, TClassifier>(); return(Actor.Props.Create(eventBusType, eventBus)); }
/// <summary> /// Create a new <see cref="IObservable{T}">observable</see> that forwards messages from an <see cref="ActorEventBus{TEvent,TClassifier}">actor-based event bus</see> subscription to subscribed <see cref="IObserver{T}">observer</see>s. /// </summary> /// <typeparam name="TEventMessage"> /// The base message type used to represent events from the bus. /// </typeparam> /// <typeparam name="TEventClassifier"> /// The type used to classify events on the bus (i.e. select the "channel" or "audience" for which a given event is intented). /// </typeparam> /// <param name="eventBus"> /// The actor-based event bus. /// </param> /// <param name="system"> /// The actor system that will host the subscribing actor (usually, this is the actor system that hosts the event bus). /// </param> /// <param name="subscriptionClassifier"> /// The classifier value that is passed to the event bus when subscribing. /// </param> /// <returns> /// The <see cref="IObservable{T}">observable</see>. /// </returns> public static IObservable <TEventMessage> ToObservable <TEventMessage, TEventClassifier>(this ActorEventBus <TEventMessage, TEventClassifier> eventBus, ActorSystem system, TEventClassifier subscriptionClassifier) { if (eventBus == null) { throw new ArgumentNullException(nameof(eventBus)); } if (system == null) { throw new ArgumentNullException(nameof(system)); } // When an observer subscribes, create an actor to represent them and subscribe it to the bus. return(Observable.Create <TEventMessage>(async observer => { // TODO: Push both subscriber creation and subscription to event bus down to the subscriber manager and have it unsubscribe when the subscribed actor stops (looks like this behaviour - ManagedActorClassification - is missing from CLR Akka). // TODO: Consider having an actor to manage all interaction with the event bus. IActorRef subscriber = await system.Reactive().CreateSubscriberAsync(observer); eventBus.Subscribe(subscriber, subscriptionClassifier); })); }