# Abp.EventBus.CAP

ABP version (opens new window) CAP version (opens new window) NuGet (opens new window) NuGet Download (opens new window) Discord online (opens new window) GitHub stars (opens new window)

ABP vNext framework CAP (opens new window) EventBus module.

# Installation

  1. Install the following NuGet packages. (see how (opens new window))

    • EasyAbp.Abp.EventBus.CAP
    • EasyAbp.Abp.EventBus.Dashboard (if you need the CAP dashboard)
    • EasyAbp.Abp.EventBus.EntityFrameworkCore (if you need CAP transactional outbox)
    • EasyAbp.Abp.EventBus.MongoDB (coming soon...)
    • DotNetCore.CAP.SqlServer (or other DB providers if you are using EF Core)
    • DotNetCore.CAP.MongoDB (if you are using MongoDB)
    • DotNetCore.CAP.RabbitMQ (or other MQ providers)
  2. Add DependsOn(typeof(AbpEventBusCapXxxModule)) attribute to configure the module dependencies. (see how (opens new window))

  3. Configure the CAP.

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        var configuration = context.Services.GetConfiguration();
        context.AddCapEventBus(capOptions =>
        {
            // If you are using EF, you need to add:
            options.SetCapDbConnectionString(configuration["ConnectionStrings:Default"]);
            options.UseEntityFramework<MyDbContext>();
    
            // CAP has multiple MQ implementations, e.g. RabbitMQ:
            options.UseRabbitMQ("localhost");
            
            // We provide permission named "CapDashboard.Manage" for authorization.
            options.UseAbpDashboard();
        });
    }
    

# Usage

See the ABP distributed event bus document (opens new window).

# How Do We Integrate CAP?

After ABP 5.0 released, the distributed event bus was redesigned. See: https://github.com/abpframework/abp/issues/6126

// ABP 5.0
Task PublishAsync<TEvent>(TEvent eventData, bool onUnitOfWorkComplete = true, bool useOutbox = true);

// ABP 4.0
Task PublishAsync<TEvent>(TEvent eventData);

Before ABP 5.0, when you invoke PublishAsync, the bus will push the event to MQ at once.

As you can see, after ABP 5.0, events are sent using outbox on UOW complete by default. CAP has a built-in transactional outbox, so we can implement it easily.

If you install the EasyAbp.Abp.EventBus.EntityFrameworkCore module, events are published with CAP's transactional outbox. Otherwise, they are published on UOW completed. See the CapDistributedEventBus (opens new window) for more information.

But there are also some problems (opens new window) with CAP in ABP. In short, an ABP app could have more than one DB connection string, but CAP can only have one, this cannot be solved at present. So if there is not any DB connection string of the current UOW is equal to CAP's, events will be published after the UOW is completed.

Now we have a better solution: https://github.com/EasyAbp/Abp.EventBus.Boxes.Dtm

Last Updated: 11/20/2022, 12:07:41 PM