Beispiel #1
0
        private static EventJournal PrepareEventJournal()
        {
            var factory = new StorageFactory();
            var journal = new EventJournal(
                new EventJournalTable(factory.CreateTable("UseDevelopmentStorage=true", "TestEventJournal")));

            return(journal);
        }
Beispiel #2
0
        public IEventStoreConnection Build()
        {
            if (m_configuration == null)
            {
                m_configuration = new EventStoreConnectionConfiguration();
                m_configure(m_configuration);

                m_configuration.AssertConfigurationCompleted();
                m_factory = new StorageFactory();
            }

            var connectivityState = new EventStoreConnectionState();

            var journalTable = new EventJournalTable(m_factory.CreateTable(
                                                         m_configuration.StorageConnectionString,
                                                         m_configuration.JournalTableName));

            var deploymentTable = m_factory.CreateTable(
                m_configuration.StorageConnectionString,
                m_configuration.EventStoreDeploymentTableName);

            var sessionFactory = new EventStreamConsumingSessionFactory(
                m_factory.CreateBlobContainer(
                    m_configuration.StorageConnectionString,
                    m_configuration.StreamConsumerSessionsBlobContainerName));

            var pipelineFactory = new EventMutationPipelineFactory(
                m_configuration.IncomingMessageMutators,
                m_configuration.OutgoingMessageMutators);

            var queues = Enumerable
                         .Range(0, m_configuration.NotificationQueuePartitionCount)
                         .Select(index => m_factory.CreateQueue(
                                     m_configuration.StorageConnectionString,
                                     m_configuration.NotificationQueueName + "-" + index.ToString("D3")))
                         .ToArray();

            var eventJournal = new EventJournal(journalTable);

            var consumersRegistry = new EventStreamConsumers(deploymentTable);
            var consumersService  = new ConsumersService(consumersRegistry, eventJournal);

            var notificationHub = new NotificationHub(
                new PollingJob("NotificationHubPollingJob", new PollingTimeout()),
                new NotificationsChannel(queues, new NotificationFormatter()),
                new ReceivedNotificationProcessor());

            var pendingNotificationTable          = m_factory.CreateTable(m_configuration.StorageConnectionString, m_configuration.PendingNotificationsTableName);
            var pendingNotifications              = new PendingNotifications(pendingNotificationTable);
            var pendingNotificationsChaserTimeout = new PollingTimeout(
                TimeSpan.FromMinutes(Constants.Settings.PENDING_NOTIFICATIONS_CHASER_INITIAL_TIMEOUT_IN_MINUTES),
                Constants.Settings.PENDING_NOTIFICATIONS_CHASER_TIMEOUT_MULTIPLIER,
                Constants.Settings.PENDING_NOTIFICATIONS_CHASER_TIMEOUT_INCREASING_THRESHOLD,
                TimeSpan.FromMinutes(Constants.Settings.PENDING_NOTIFICATIONS_CHASER_MAX_TIMEOUT_IN_MINUTES));

            var pendingNotificationsChaser = new PendingNotificationsChaser(
                pendingNotifications,
                notificationHub,
                new PollingJob("PendingNotificationsChaserPollingJob", pendingNotificationsChaserTimeout),
                m_factory.CreateBlobContainer(
                    m_configuration.StorageConnectionString,
                    m_configuration.PendingNotificationsChaserExclusiveAccessLockBlobContainerName).CreateBlockBlob(
                    m_configuration.PendingNotificationsChaserExclusiveAccessLockBlobName));

            connectivityState.ConnectionCreated += (sender, args) =>
            {
                if (m_configuration.BackgroundProcessingEnabled)
                {
                    foreach (var notificationListener in m_configuration.NotificationListeners)
                    {
                        notificationHub.Subscribe(notificationListener);
                    }

                    notificationHub.StartNotificationProcessing(args.Connection);
                    pendingNotificationsChaser.Start();
                }
            };

            connectivityState.ConnectionClosing += (sender, args) =>
            {
                if (m_configuration.BackgroundProcessingEnabled)
                {
                    notificationHub.StopNotificationProcessing();
                    pendingNotificationsChaser.Stop();
                }
            };

            connectivityState.ConnectionClosed += (sender, args) =>
            {
                if (m_configuration.BackgroundProcessingEnabled)
                {
                    foreach (var notificationListener in m_configuration.NotificationListeners)
                    {
                        notificationHub.Unsubscribe(notificationListener);
                    }
                }
            };

            return(new EventStoreConnection(
                       connectivityState,
                       eventJournal,
                       notificationHub,
                       pendingNotifications,
                       consumersRegistry,
                       sessionFactory,
                       pipelineFactory,
                       consumersService));
        }
Beispiel #3
0
 public CloudTableTests()
 {
     Factory = new StorageFactory();
     Table   = Factory.CreateTable("UseDevelopmentStorage=true", "T" + Guid.NewGuid().ToString("N"));
 }