Exemple #1
0
 public EFRepository(DbContext context, IOutbox outbox)
 {
     Guard.NotNull(context, nameof(context));
     Guard.NotNull(outbox, nameof(outbox));
     this.context = context;
     this.outbox  = outbox;
 }
        public async Task EnsureSchemaInitialized()
        {
            // `receptionDelay` should include transaction timeout + clock drift. Otherwise, it may skip events during reception.
            var receptionDelay = TimeSpan.FromMilliseconds(3000);
            var eventStore     = Wireup.Init()
                                 .UsingSqlPersistence(null, "System.Data.SqlClient", ConnectionString)
                                 .WithDialect(new MsSqlDialect())
                                 .UsingJsonSerialization()
                                 .Build();

            _eventStore = eventStore;
            Outbox      = new NEventStoreOutbox(eventStore, receptionDelay);
            var options = new DbContextOptionsBuilder().UseSqlServer(ConnectionString).Options;
            var db      = new TestDbContextWithOutbox(options, Outbox);

            try
            {
                _ = db.Users.FirstOrDefault();
            }
            catch (SqlException)
            {
                await db.Database.EnsureDeletedAsync();

                await db.Database.EnsureCreatedAsync();
            }

            eventStore.Advanced.Initialize();
            eventStore.Advanced.Purge();
        }
Exemple #3
0
        public MessagingService(IOutbox outbox, IServiceFactory factory, Profile profile = null, MessagingConfiguration configuration = null)
        {
            ProcessId           = Process.GetCurrentProcess().Id;
            MachineName         = Environment.MachineName;
            MachineAndProcessId = $"{MachineName}-{ProcessId}";

            _configuration = configuration ?? new MessagingConfiguration();

            if (outbox == null)
            {
                throw new InvalidOperationException("Outbox cannot be null. An Outbo is required to instantiate MessagingService");
            }
            _outboxManager = new OutboxManager(outbox, this.DispatchCore, 1, _configuration.OutboxConsumerSemaphore, this.MachineAndProcessId);

            if (factory == null)
            {
                throw new InvalidOperationException("IServiceFactory cannot be null. An IServiceFactory is required to instantiate MessagingService");
            }
            _messageHandlerDispatcher = new MessageDispatcher(factory);

            if (profile != null)
            {
                _configure(profile);
            }

            _immediateHandleRetryPolicy = Policy
                                          .Handle <Exception>(x => !(x is NonTransientException))
                                          .RetryAsync(_maxImmediateRetryCount);
        }
        public async Task InitializeAndWarmUp()
        {
            var eventStore = Wireup.Init()
                             .UsingSqlPersistence(SqlClientFactory.Instance, ConnectionString)
                             .WithDialect(new MsSqlDialect())
                             .UsingJsonSerialization()
                             .Build();

            _outbox = new NEventStoreOutbox(eventStore, TimeSpan.Zero);
            var options = new DbContextOptionsBuilder().UseSqlServer(ConnectionString).Options;
            var db      = new TestDbContextWithOutbox(options, _outbox);

            try
            {
                _ = db.Users.FirstOrDefault();
            }
            catch (SqlException)
            {
                await db.Database.EnsureDeletedAsync();

                await db.Database.EnsureCreatedAsync();
            }

            eventStore.Advanced.Initialize();
            await WarmUp();
        }
Exemple #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        public RaspMailHandler(IMailHandlerConfiguration configuration)
        {
            IMailServerConfiguration sendingServerConfiguration   = configuration.SendingServerConfiguration;
            IMailServerConfiguration recievingServerConfiguration = configuration.RecievingServerConfiguration;
            Type outBoxImplementationType = configuration.OutBoxImplementationType;
            Type inBoxImplementationType  = configuration.InBoxImplementationType;

            _inboxFactory = InboxFactory.GetInstance();

            _inbox = _inboxFactory.GetInbox(recievingServerConfiguration, inBoxImplementationType, this);

            _outbox = (IOutbox)outBoxImplementationType.GetConstructor(new Type[0]).Invoke(null);
            _outbox.OutboxServerConfiguration = sendingServerConfiguration;


            if (_inbox != null)
            {
                _inbox.OnExceptionThrown  += new MailboxExceptionThrown(CallbackExceptionThrown);
                _inbox.OnInboxStateChange += new OnInboxStateChangeDelegate(CallbackOnInboxStateChange);
            }
            if (_outbox != null)
            {
                _outbox.OnExceptionThrown += new MailboxExceptionThrown(CallbackExceptionThrown);
            }
        }
Exemple #6
0
 protected DbContextWithOutbox(
     DbConnection existingConnection,
     bool contextOwnsConnection,
     IOutbox outbox)
     : base(existingConnection, contextOwnsConnection)
 {
     _outbox = outbox;
 }
Exemple #7
0
        public OutboxAndToken(IOutbox <TMessage> outbox, IDisposable token)
        {
            Assert.ArgumentNotNull(outbox, nameof(outbox));
            Assert.ArgumentNotNull(token, nameof(token));

            Outbox = outbox;
            Token  = token;
        }
 public UnitOfWorkManager(IDb db, IMessageSession messageSession, IUnitOfWorkContext unitOfWorkContext, IOutbox outbox, ReadOnlySettings settings)
 {
     _db                = db;
     _messageSession    = messageSession;
     _unitOfWorkContext = unitOfWorkContext;
     _outbox            = outbox;
     _settings          = settings;
 }
        public IDisposable AddOutboxToBeMonitored <TMessage>(IOutbox <TMessage> outbox, Action <Envelope <TMessage> > send)
        {
            Assert.ArgumentNotNull(outbox, nameof(outbox));
            Assert.ArgumentNotNull(send, nameof(send));

            var sender = new OutboxSender <TMessage>(_messageBus.Logger, outbox, send);

            return(Monitor.AddOutboxToBeMonitored(sender));
        }
        public OutboxSender(ILogger logger, IOutbox <TPayload> outbox, Action <Envelope <TPayload> > send, int maxBatchSize = 100)
        {
            Assert.ArgumentNotNull(outbox, nameof(outbox));
            Assert.ArgumentNotNull(send, nameof(send));

            _logger       = logger;
            _outbox       = outbox;
            _send         = send;
            _maxBatchSize = maxBatchSize;
        }
 public InMemoryMessageBroker(IModuleClient moduleClient, IAsyncMessageDispatcher asyncMessageDispatcher,
                              IContext context, IOutbox outbox, MessagingOptions messagingOptions, ILogger <InMemoryMessageBroker> logger)
 {
     _moduleClient           = moduleClient;
     _asyncMessageDispatcher = asyncMessageDispatcher;
     _context          = context;
     _outbox           = outbox;
     _messagingOptions = messagingOptions;
     _logger           = logger;
 }
Exemple #12
0
 public DomainEventsDispatcher(
     IMediator mediator,
     ILifetimeScope scope,
     IOutbox outbox,
     IDomainEventsAccessor domainEventsProvider)
 {
     _mediator             = mediator;
     _scope                = scope;
     _outbox               = outbox;
     _domainEventsProvider = domainEventsProvider;
 }
Exemple #13
0
 public DomainEventsDispatcher(
     IMediator mediator,
     ILifetimeScope scope,
     IOutbox outbox,
     IDomainEventsAccessor domainEventsProvider)
 {
     this.mediator             = mediator;
     this.scope                = scope;
     this.outbox               = outbox;
     this.domainEventsProvider = domainEventsProvider;
 }
 public PaymentsUnitOfWork(
     IOutbox outbox,
     IAggregateStore aggregateStore,
     IDomainEventsDispatcher domainEventsDispatcher,
     ISqlConnectionFactory sqlConnectionFactory)
 {
     _outbox                 = outbox;
     _aggregateStore         = aggregateStore;
     _domainEventsDispatcher = domainEventsDispatcher;
     _sqlConnectionFactory   = sqlConnectionFactory;
 }
        public async Task InitializeAndWarmUp()
        {
            var eventStore = new MsSqlStreamStoreV3(new MsSqlStreamStoreV3Settings(ConnectionString));
            await eventStore.CreateSchemaIfNotExists();

            _outbox = new SqlStreamStoreOutbox(eventStore, TimeSpan.Zero);
            var db = new TestDbContextWithOutbox(ConnectionString, _outbox);

            db.Database.CreateIfNotExists();
            await WarmUp();
        }
Exemple #16
0
 public OutboxManager(IOutbox outbox,
                      Dispatcher dispatcher,
                      int maxConcurrency = 1,
                      ICountingSemaphore outboxConsumerSemaphore = null,
                      string uniqueIdentifier = null)
 {
     _dispatcher              = dispatcher;
     _outbox                  = outbox;
     _maxConcurrency          = maxConcurrency;
     _outboxConsumerSemaphore = outboxConsumerSemaphore;
     _uniqueIdentifier        = !String.IsNullOrEmpty(uniqueIdentifier) ? uniqueIdentifier : Guid.NewGuid().ToString();
 }
 public DomainEventsDispatcher(
     IMediator mediator,
     ILifetimeScope scope,
     IOutbox outbox,
     IDomainEventsAccessor domainEventsAccessor,
     IDomainNotificationsMapper domainNotificationsMapper)
 {
     this._mediator                  = mediator;
     this._scope                     = scope;
     this._outbox                    = outbox;
     this._domainEventsAccessor      = domainEventsAccessor;
     this._domainNotificationsMapper = domainNotificationsMapper;
 }
        public async Task InitializeAndWarmUp()
        {
            _outbox = new NEventStoreOutbox(Wireup.Init()
                                            .UsingSqlPersistence(null, "System.Data.SqlClient", ConnectionString)
                                            .WithDialect(new MsSqlDialect())
                                            .InitializeStorageEngine()
                                            .UsingJsonSerialization()
                                            .Build(), TimeSpan.Zero);
            var db = new TestDbContextWithOutbox(ConnectionString, _outbox);

            db.Database.CreateIfNotExists();
            await WarmUp();
        }
Exemple #19
0
        /// <summary>
        /// Constructor that duplicates another RaspMailHandler
        /// </summary>
        /// <param name="original">original mailhandler</param>
        public RaspMailHandler(RaspMailHandler original)
        {
            _inbox  = original._inbox;
            _outbox = original._outbox;

            if (_inbox != null)
            {
                _inbox.OnExceptionThrown  += new MailboxExceptionThrown(CallbackExceptionThrown);
                _inbox.OnInboxStateChange += new OnInboxStateChangeDelegate(CallbackOnInboxStateChange);
            }
            if (_outbox != null)
            {
                _outbox.OnExceptionThrown += new MailboxExceptionThrown(CallbackExceptionThrown);
            }
        }
Exemple #20
0
 public TestDbContextWithOutbox(DbContextOptions options, IOutbox outbox)
     : base(options, outbox)
 {
 }
Exemple #21
0
 public TestCommandHandler(ILogger <TestCommandHandler> logger, IOutbox outbox)
 {
     _logger = logger;
     _outbox = outbox;
 }
 public SendingOutbox(IOutbox <TPayload> outbox, IOutboxSender sender, IDisposable monitorToken = null)
 {
     _monitorToken = monitorToken;
     Outbox        = outbox;
     Sender        = sender;
 }
Exemple #23
0
 public CustomerBalanceRepository(DbContext context, IOutbox outbox)
     : base(context, outbox)
 {
 }
 public OutBoxPublisherFilter(IOutbox outbox)
 {
     Guard.NotNull(outbox, nameof(outbox));
     this.outbox = outbox;
 }
 protected DbContextWithOutbox(DbContextOptions options, IOutbox outbox) : base(options)
 {
     _outbox = outbox;
 }
Exemple #26
0
        /// <summary>
        /// Add the outbox to be monitored by the OutboxModule
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="messageBus"></param>
        /// <param name="outbox"></param>
        /// <param name="send"></param>
        /// <returns></returns>
        public static IDisposable AddOutboxToBeMonitored <TMessage>(this IBusBase messageBus, IOutbox <TMessage> outbox, Action <Envelope <TMessage> > send)
        {
            Assert.ArgumentNotNull(messageBus, nameof(messageBus));
            Assert.ArgumentNotNull(outbox, nameof(outbox));
            Assert.ArgumentNotNull(send, nameof(send));

            var module = GetOutboxModuleOrThrow(messageBus);

            return(module.AddOutboxToBeMonitored(outbox, send));
        }
Exemple #27
0
 public ProcessOutboxMessageCommandHandler(IOutbox outbox)
 {
     _outbox = outbox;
 }
Exemple #28
0
 public TestDbContextWithOutbox(string connectionString, IOutbox outbox)
     : base(connectionString, outbox)
 {
 }
Exemple #29
0
        public ForwardToRabbitSubscription(IBusBase messageBus, IBus rabbitBus, string queueName, IOutbox <TPayload> outbox)
        {
            Assert.ArgumentNotNull(messageBus, nameof(messageBus));
            Assert.ArgumentNotNull(rabbitBus, nameof(rabbitBus));
            Assert.ArgumentNotNull(outbox, nameof(outbox));

            _rabbitBus = rabbitBus;
            _queueName = queueName;
            var sender      = new OutboxSender <TPayload>(messageBus.Logger, outbox, PublishInternal);
            var outboxToken = messageBus.AddOutboxToBeMonitored(sender);

            _outbox = new SendingOutbox <TPayload>(outbox, sender, outboxToken);
        }
        /// <summary>
        /// Use an outbox as a temporary cache between the publisher and the final destination of the message.
        /// The outbox will be a stage in the delivery pipeline, invoked after filtering and liveliness checks,
        /// and will flush to the next stage in the pipeline.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="outbox"></param>
        /// <returns></returns>
        public static IDetailsSubscriptionBuilder <TPayload> UseOutbox <TPayload>(this IDetailsSubscriptionBuilder <TPayload> builder, IOutbox <TPayload> outbox)
        {
            Assert.ArgumentNotNull(builder, nameof(builder));
            Assert.ArgumentNotNull(outbox, nameof(outbox));

            return(builder.WrapSubscriptionBase(s => OutboxSubscription <TPayload> .WrapSubscription(builder.MessageBus, s, outbox)));
        }