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

Incorrect order of messages sent between version 7.2 and 8.1 #1565

Closed catsoul closed 1 month ago

catsoul commented 1 month ago

当极短的时间内发布连续消息,消费端接受的消息不是按顺序消费,而是乱序。使用的是内存队列。 `using DotNetCore.CAP; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Savorboard.CAP.InMemoryMessageQueue;

namespace ConsoleApp3 { internal class Program { static async Task Main(string[] args) { var container = new ServiceCollection();

        container.AddCap(config =>
        {
            config.UseInMemoryMessageQueue();
            config.UseInMemoryStorage();
        });
        container.AddLogging(p =>
        {
            p.AddFilter(n => n == LogLevel.Error);
            p.AddConsole();
        });
        container.TryAddSingleton<TestCapSubscribe>();
        container.AddSingleton<TestPublish>();
        IServiceProvider serviceProvider = container.BuildServiceProvider();
        var bootstrapper = serviceProvider.GetService<IBootstrapper>();
        await bootstrapper.BootstrapAsync();
        var testPublish = serviceProvider.GetService<TestPublish>();
        await testPublish.TestPublishAsync();
        Console.ReadLine();
    }
}
public class TestPublish
{
    private readonly ICapPublisher _capPublisher;

    public TestPublish(ICapPublisher capPublisher)
    {
        _capPublisher = capPublisher;
    }
    public async Task TestPublishAsync()
    {
        for (int i = 0; i < 1000; i++)
        {
          //  _capPublisher.Publish();
           await _capPublisher.PublishAsync("Test", $"{DateTime.Now}+{i}");
        }
    }
}

public class TestCapSubscribe : ICapSubscribe
{
    [CapSubscribe("Test")]
    public async Task SubscribeInfoAsync(string content)
    {
        Console.WriteLine(content);
    }
}

}

` 这是测试代码,请排查下

catsoul commented 1 month ago

在7.2.2的版本会错乱,如果使用延迟发布的方法,消费端 消费几百条消息后,就无法消费了。8.0版本也有这个问题

yang-xiaodong commented 1 month ago

See Release notes of version 7.2 and version 8.1 Breaking Changes.