Mass transit does not track my command after publish

242 Views Asked by At

my goal is to use mass transit transactional outbox pattern with rabbitmq and here is the configuration:

 private static void AddOutboxPattern(IServiceCollection services)
        {
            services.AddMassTransit(configuration =>
            {
                configuration.AddEntityFrameworkOutbox<PersonalGoodsDbContext>(o =>
                {
                    o.QueryDelay = TimeSpan.FromSeconds(1);
                    o.UseSqlServer();
                    o.UseBusOutbox();
                });

                configuration.UsingRabbitMq((ctx, cfg) =>
                {
                    cfg.Host("rabbitmq");
                    //cfg.AutoStart = true;
                });
            });
        }

and my dbcontext:

       protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ApplyConfigurationsFromAssembly(typeof(CenterMapping).Assembly);

            modelBuilder.AddInboxStateEntity();

            modelBuilder.AddOutboxMessageEntity();

            modelBuilder.AddOutboxStateEntity();
        }

and my command handler that publish the command to the certain endpoint:

        public async Task Handle(CreateCommand request, CancellationToken cancellationToken)
        {
                var personnelDoc = new NonPersonnelDocument(
                request.ImportationReason);
            
                documentsRepository.Create(personnelDoc);
                _eventBus.Publish(request);
        }

and here is my Create and publisher method that use mass transit:

        public new void Create(Document document)
        {
            dbContext.Set<Document >().Add(document);
            dbContext.SaveChanges();
        }

        public void Publish<T>(T command) where T : IEvent
        {
            _publishendpoint.Publish(command);
        }

now there is a question:

  • Why there is no date seed in my 3 tables created by mass transit even if my rabbit is down?

Note: I am using docker and every thing is up and running.

1

There are 1 best solutions below

0
HassanJalali On

I figure out the problem was my migration but I still confused about it

instead of using this code:

       await writeContext.Database.EnsureDeletedAsync();
       await writeContext.Database.EnsureCreatedAsync();

I changed it to this code:

        await writeContext.Database.MigrateAsync();

and now it work perfectly fine.