public static void SubscribeMarketDataBus(this IActor actor)
        {
            var marketDataBus = actor.GetConnectedBus <IMarketDataBus>();

            var dispose = marketDataBus.Subscribe(actor.Id, (marketDataChanged) =>
            {
                actor.OnMessageReceived(marketDataChanged);

                return(Task.CompletedTask);
            });

            actor.AddDisposable(dispose);
        }
Example #2
0
        public static void SubscribeToExchange <TEvent>(this IActor actor,
                                                        string exchange,
                                                        Expression <Func <TEvent, bool> >?routingStrategy = null,
                                                        string queueName                        = "",
                                                        string exchangeType                     = "topic",
                                                        bool isExchangeDurable                  = true,
                                                        bool isExchangeAutoDelete               = true,
                                                        bool createExchangeIfNotExist           = true,
                                                        bool createDeadLetterExchangeIfNotExist = true,
                                                        bool isQueueDurable                     = false,
                                                        bool isQueueAutoAck                     = false,
                                                        bool isQueueAutoDelete                  = true,
                                                        bool isQueueExclusive                   = true)
            where TEvent : class, IRabbitMqEvent
        {
            var rabbitMqBus = actor.GetConnectedBus <IRabbitMqBus>();

            var rabbitMqQueueConfiguration = new RabbitMqQueueConfiguration <TEvent>(routingStrategy,
                                                                                     queueName,
                                                                                     isQueueAutoAck,
                                                                                     isQueueDurable,
                                                                                     isQueueAutoDelete,
                                                                                     isQueueExclusive);

            var rabbitMqExchangeConfiguration = new RabbitMqExchangeConfiguration(exchange,
                                                                                  exchangeType,
                                                                                  createExchangeIfNotExist,
                                                                                  createDeadLetterExchangeIfNotExist,
                                                                                  isExchangeAutoDelete,
                                                                                  isExchangeDurable);

            var onMessage = new Func <IRabbitMqQueueMessage, Task>((@event) =>
            {
                actor.OnMessageReceived(@event);

                return(Task.CompletedTask);
            });

            var rabbitMqSubscription = new RabbitMqEventSubscription <TEvent>(onMessage,
                                                                              rabbitMqQueueConfiguration,
                                                                              rabbitMqExchangeConfiguration);

            rabbitMqBus.SubscribeToExchange(rabbitMqSubscription);

            var disposable = Disposable.Create(() => rabbitMqBus.UnsubscribeFromExchange(rabbitMqSubscription));

            actor.AddDisposable(disposable);
        }
        public static void SubscribeFromEndToAllStreams(
            this IActor actor,
            Action <SubscribeFromEndEventStoreStreamConfiguration>?getSubscribeFromEndEventStoreStreamConfiguration = null,
            IEventTypeProvider?eventTypeProvider = null)
        {
            var eventProvider = eventTypeProvider ?? new ConsumerBasedEventProvider(actor.GetType());

            var eventStoreBus = actor.GetConnectedBus <IEventStoreBus>();

            var subscribeFromEndEventStoreStream = eventStoreBus.SubscribeFromEndToAllStreams(
                actor.OnMessageReceived,
                eventProvider,
                getSubscribeFromEndEventStoreStreamConfiguration);

            actor.AddDisposable(subscribeFromEndEventStoreStream);
        }
        public static void SubscribeFromEndToOneStream(
            this IActor actor,
            string streamId,
            Action <SubscribeToOneStreamFromStartOrLaterEventStoreStreamConfiguration>?subscribeToOneStreamFromStartOrLaterEventStoreStreamConfiguration = null,
            IEventTypeProvider?eventTypeProvider = null)
        {
            var eventProvider = eventTypeProvider ?? new ConsumerBasedEventProvider(actor.GetType());

            var eventStoreBus = actor.GetConnectedBus <IEventStoreBus>();

            var subscribeFromEndToOneStreamEventStoreStream = eventStoreBus.SubscribeFromEndToOneStream(
                streamId,
                actor.OnMessageReceived,
                eventProvider,
                subscribeToOneStreamFromStartOrLaterEventStoreStreamConfiguration);

            actor.AddDisposable(subscribeFromEndToOneStreamEventStoreStream);
        }
        public static void SubscribeToPersistentSubscriptionStream(
            this IActor actor,
            string streamId,
            string groupId,
            IEventTypeProvider?eventTypeProvider = null,
            Action <PersistentSubscriptionEventStoreStreamConfiguration>?getPersistentSubscriptionEventStoreStreamConfiguration = null)
        {
            var eventProvider = eventTypeProvider ?? new ConsumerBasedEventProvider(actor.GetType());

            var eventStoreBus = actor.GetConnectedBus <IEventStoreBus>();

            var persistentSubscriptionEventStoreStream = eventStoreBus.SubscribeToPersistentSubscriptionStream(
                streamId,
                groupId,
                actor.OnMessageReceived,
                eventProvider,
                getPersistentSubscriptionEventStoreStreamConfiguration);

            actor.AddDisposable(persistentSubscriptionEventStoreStream);
        }