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 17, 2024
1 parent 72b60bc commit 138d13d
Showing 1 changed file with 57 additions and 12 deletions.
69 changes: 57 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
1. MongoDB
2. SqlServer

特性:

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

## 使用方式

初始化:
Expand All @@ -24,31 +30,70 @@ serviceCollection.AddLightMQ(it =>
新增消费者:

```c#
public class TestConsumer:MessageConsumerBase
public class Test2Consumer:IMessageConsumer
{
public TestConsumer(IStorageProvider storageProvider) : base(storageProvider)
{
}

public override ConsumerOptions GetOptions()
public ConsumerOptions GetOptions()
{
return new ConsumerOptions()
{
Topic = "test",
PollInterval = TimeSpan.FromSeconds(2)
ParallelNum = 1,
Topic = "test"
};
}

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


}
```

注册消费者:

```C#
serviceCollection.AddHostedService<TestConsumer>();
```
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实例

0 comments on commit 138d13d

Please sign in to comment.