dotnetcore / CAP

Distributed transaction solution in micro-service base on eventually consistency, also an eventbus with Outbox pattern
http://cap.dotnetcore.xyz
MIT License
6.61k stars 1.28k forks source link

### CAP background task is starting. 日志运行到这一句整个项目就卡住了 #1569

Closed cethink closed 1 month ago

cethink commented 1 month ago

image

代码如下:

public override void ConfigureServices(ServiceConfigurationContext context)
{
    var hostingEnvironment = context.Services.GetHostingEnvironment();
    var configuration = context.Services.GetConfiguration();

    ConfigureUrls(configuration);
    ConfigureAutoMapper(context);
    ConfigureSwagger(context.Services, configuration);
    ConfigureAutoApiControllers();
    ConfigureVirtualFiles(hostingEnvironment);
    ConfigureLocalization();
    ConfigureCors(context, configuration);
    ConfigureDataProtection(context);
    ConfigureEfCore(context);

    AbpOpenIddictDbProperties.DbTablePrefix = "";
    AbpIdentityDbProperties.DbTablePrefix = "";
    AbpPermissionManagementDbProperties.DbTablePrefix = "";

    context.Services.AddAlwaysAllowAuthorization();

    context.Services.AddJsonNamingPolicyNull();

    context.Services.AddDisAntiForgery();

    context.Services.AddRegistryCenter(configuration);

    /*
     * 配置EventBus,其它代码都试过了,加了这句后就卡了,也试过把代码调换顺序,可以运行成功一次,然后又不行了
     */
    context.Services.AddEventBus<ES_UserServiceDbContext>(configuration);
}
public static IServiceCollection AddEventBus<T>(this IServiceCollection services, IConfiguration configuration) where T : DbContext
{
    services.AddCap(options =>
    {
        options.UseRabbitMQ(rb =>
        {
            rb.HostName = configuration.GetValue<string>("EventBus:HostName")!;
            rb.UserName = configuration.GetValue<string>("EventBus:UserName")!;
            rb.Password = configuration.GetValue<string>("EventBus:Password")!;
            rb.Port = configuration.GetValue<int>("EventBus:Port")!;
            rb.VirtualHost = configuration.GetValue<string>("EventBus:VirtualHost")!;
        });

        options.UseEntityFramework<T>();
        options.UseMySql(configuration.GetValue<string>("EventBus:ConnectionString")!);

        options.UseDashboard();

        options.FailedRetryCount = configuration.GetValue<int>("EventBus:FailedRetryCount")!;
        options.FailedRetryInterval = configuration.GetValue<int>("EventBus:FailedRetryInterval")!;
    });

    return services;
}
"EventBus": {
  "HostName": "alma.cethink.top",
  "UserName": "octo",
  "Password": "2355678",
  "Port": 5672,
  "VirtualHost": "/",
  "ConnectionString": "Server=alma.cethink.top;Port=3306;Database=ES_UserService;Uid=root;Pwd=root;",
  "FailedRetryCount": 10,
  "FailedRetryInterval": 30
}
public class ES_UserServiceDbContext : AbpDbContext<ES_UserServiceDbContext>
{
    public ES_UserServiceDbContext(DbContextOptions<ES_UserServiceDbContext> options)
        : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        AbpOpenIddictDbProperties.DbTablePrefix = "";
        builder.ConfigureOpenIddict();

        AbpIdentityDbProperties.DbTablePrefix = "";
        builder.ConfigureIdentity();

        AbpPermissionManagementDbProperties.DbTablePrefix = "";
        builder.ConfigurePermissionManagement();
    }
}
<PackageReference Include="DotNetCore.CAP" Version="8.2.0" />
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="8.2.0" />
<PackageReference Include="DotNetCore.CAP.InMemoryStorage" Version="8.2.0" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="8.2.0" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="8.2.0" />
yang-xiaodong commented 1 month ago

此类问题由于混合了外部代码,我们无法提供帮助,还请自行排查。

cethink commented 1 month ago

我提供源码能帮忙看看么?

yang-xiaodong commented 1 month ago

加QQ 615709110