Open Closed

Distributed Event Bus Enabling event outbox #9092


User avatar
0
NH-Support created

Distributed **event outbox ** for MongoDB not Added records to database

I enable both inbox and outbox events and set all configuration related with them when I publish the event and received by consumer new record is added to inbox collection in database but outbox is always empty

I try to publish from application service and also from domain but both not working

this is from application service: await _priorRequestRepository.InsertAsync(new PriorRequest()); await _distributedEventBus.PublishAsync( new PriorRequestPostedEto { PriorRequestInput = input.PriorRequest, TransactionID = output.TransactionID, } );

this is from domain public PriorRequest() { AddDistributedEvent(new PriorRequestPostedEto1());

}

this is my db context: [ConnectionStringName(PriorRequestServiceDbProperties.ConnectionStringName)] public class PriorRequestServiceMongoDbContext : AbpMongoDbContext, IPriorRequestServiceMongoDbContext, IHasEventInbox, IHasEventOutbox { public IMongoCollection<IncomingEventRecord> IncomingEvents => Collection<IncomingEventRecord>(); public IMongoCollection<OutgoingEventRecord> OutgoingEvents => Collection<OutgoingEventRecord>(); public IMongoCollection<PriorRequest> PriorRequests => Collection<PriorRequest>();

protected override void CreateModel(IMongoModelBuilder modelBuilder)
{
    base.CreateModel(modelBuilder);
    modelBuilder.Entity&lt;PriorRequest&gt;(b => { b.CollectionName = PriorRequestServiceDbProperties.DbTablePrefix + "PriorRequests"; });

    modelBuilder.ConfigurePriorRequestService();
    modelBuilder.ConfigureEventInbox();
    modelBuilder.ConfigureEventOutbox();
}

}

and this is the module configuration private void ConfigureDistributedEventBus() { Configure<AbpDistributedEventBusOptions>(options => { options.Inboxes.Configure(config => { config.UseMongoDbContext<PriorRequestServiceMongoDbContext>(); });

     options.Outboxes.Configure(config =>
     {
         config.UseMongoDbContext&lt;PriorRequestServiceMongoDbContext&gt;();
     });
 });

}

the event is working and consumed from other service but the problem just in the outbox event not working


1 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi,

    If you have configured AbpDistributedEntityEventOptions as follows, this may be the problem:

    Configure<AbpDistributedEntityEventOptions>(options =>
    {
        options.AutoEventSelectors.AddAll();
    });
    
    

    Because the line options.AutoEventSelectors.AddAll(); causes an issue. I tested the following code instead, and it works as expected:

    Configure<AbpDistributedEntityEventOptions>(options =>
    {
        // options.AutoEventSelectors.AddAll(); // do not use this method until next version of ABP
        
        // Use following codes for your entities
        options.AutoEventSelectors.Add<MyEntity1>();
        options.AutoEventSelectors.Add<MyEntity2>();
    });
    
    

    We will address the AddAll issue in this PR: 🔧 https://github.com/abpframework/abp/pull/22471

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on April 16, 2025, 12:13