Skip to content

基于数据库的消息队列/Database-based message queue

License

Notifications You must be signed in to change notification settings

li-zheng-hao/LightMQ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LightMQ

English | 中文

Introduction

Database-based message queues, currently supported databases.:

  1. MongoDB
  2. SqlServer

Features:

  1. Supports retries
  2. Supports multiple queues
  3. Supports concurrent consumption
  4. Support opentelemetry tracing

Test Coverage

test screenshot

Usage

Initialize:

serviceCollection.AddLightMQ(it =>
{
    // it.UseSqlServer("Data Source=.;Initial Catalog=Test;User ID=sa;Password=Abc12345;");
    it.UseMongoDB("mongodb://localhost:27017","Test");
});

Add a consumer:

public class Test2Consumer:IMessageConsumer
{

    public ConsumerOptions GetOptions()
    {
        return new ConsumerOptions()
        {
            ParallelNum = 1,
            Topic = "test"
        };
    }

    public async Task<bool> ConsumeAsync(string message, CancellationToken cancellationToken)
    {
        Console.WriteLine("consume message:"+message);
        await Task.Delay(2_000,cancellationToken);
        return true;
    }

  
}

Register the consumer:

builder.Services.AddScoped<TestConsumer>();

Consumer Options

public class ConsumerOptions
{
    /// <summary>
    /// Topic
    /// </summary>
    public string Topic { get; set; }
    
    /// <summary>
    /// Enable Random Queue
    /// </summary>
    public bool EnableRandomQueue {get;set;}
    
    /// <summary>
    /// Poll Interval
    /// </summary>
    public TimeSpan PollInterval { get; set; }=TimeSpan.FromSeconds(2);

    /// <summary>
    /// Retry Count (not including the first execution)
    /// </summary>
    public int RetryCount { get; set; } = 0;

    /// <summary>
    /// Retry Interval
    /// </summary>
    public TimeSpan RetryInterval { get; set; }=TimeSpan.FromSeconds(5);
    
    /// <summary>
    /// Concurrent Number
    /// </summary>
    public int ParallelNum { get; set; }
}

More examples can be found under the Sample category.

Develop Tool

JetBrains

About

基于数据库的消息队列/Database-based message queue

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages