Skip to content

Commit

Permalink
更新readme
Browse files Browse the repository at this point in the history
  • Loading branch information
li-zheng-hao committed Aug 22, 2024
1 parent 4d37263 commit e64edb0
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 21 deletions.
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
# LightMQ

## 介绍
[English](README.md) | [中文](./README_CN.md)

基于数据库的消息队列,目前支持的数据库:
## Introduction

Database-based message queues, currently supported databases.:

1. MongoDB
2. SqlServer

特性
Features

1. 支持重试
2. 支持多队列
3. 支持并发消费
1. Supports retries
2. Supports multiple queues
3. Supports concurrent consumption

## 测试覆盖率
## Test Coverage

![测试截图](./doc/test_coverage_20240822100230.jpg)
![test screenshot](./doc/test_coverage_20240822100230.jpg)

## 使用方式
## Usage

初始化
Initialize

```c#

Expand All @@ -31,7 +33,7 @@ serviceCollection.AddLightMQ(it =>

```

新增消费者
Add a consumer

```c#
public class Test2Consumer:IMessageConsumer
Expand All @@ -48,7 +50,7 @@ public class Test2Consumer:IMessageConsumer

public async Task<bool> ConsumeAsync(string message, CancellationToken cancellationToken)
{
Console.WriteLine("消费消息"+message);
Console.WriteLine("consume message:"+message);
await Task.Delay(2_000,cancellationToken);
return true;
}
Expand All @@ -57,47 +59,47 @@ public class Test2Consumer:IMessageConsumer
}
```

注册消费者
Register the consumer

```C#
builder.Services.AddScoped<TestConsumer>();
```

## 消费者配置
## Consumer Options

```c#
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; }
}
```

更多可以查看Sample示例
More examples can be found under the Sample category.
105 changes: 105 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# LightMQ

[English](README.md) | [中文](./README_CN.md)

## 介绍

基于数据库的消息队列,目前支持的数据库:

1. MongoDB
2. SqlServer

特性:

1. 支持重试
2. 支持多队列
3. 支持并发消费

## 测试覆盖率

![测试截图](./doc/test_coverage_20240822100230.jpg)

## 使用方式

初始化:

```c#

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

```

新增消费者:

```c#
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("消费消息"+message);
await Task.Delay(2_000,cancellationToken);
return true;
}


}
```

注册消费者:

```C#
builder.Services.AddScoped<TestConsumer>();
```

## 消费者配置

```c#
public class ConsumerOptions
{
/// <summary>
/// 主题
/// </summary>
public string Topic { get; set; }

/// <summary>
/// 开启随机队列消费
/// </summary>
public bool EnableRandomQueue {get;set;}

/// <summary>
/// 拉取间隔
/// </summary>
public TimeSpan PollInterval { get; set; }=TimeSpan.FromSeconds(2);

/// <summary>
/// 重试次数(不包括第一次执行)
/// </summary>
public int RetryCount { get; set; } = 0;

/// <summary>
/// 重试间隔
/// </summary>
public TimeSpan RetryInterval { get; set; }=TimeSpan.FromSeconds(5);

/// <summary>
/// 并发数量
/// </summary>
public int ParallelNum { get; set; }
}
```

更多可以查看Sample示例
6 changes: 6 additions & 0 deletions src/LightMQ.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{64A31597-3
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LightMQ.IntegrationTest", "LightMQ.IntegrationTest\LightMQ.IntegrationTest.csproj", "{3DE3B192-F395-478B-BBAD-A40E403AD8FF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{E018A9B3-9951-401B-A39F-85F3D3A5426B}"
ProjectSection(SolutionItems) = preProject
..\README.md = ..\README.md
..\README_CN.md = ..\README_CN.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down

0 comments on commit e64edb0

Please sign in to comment.