将定时任务改为,发布、订阅模式的消息队列执行任务

This commit is contained in:
alex
2023-08-15 13:53:04 +08:00
parent 4c1e3c8c40
commit 28b7800baf
13 changed files with 238 additions and 45 deletions

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.WarehouseMgr
{
/// <summary>
/// 任务消息通知
/// </summary>
public class TaskMesageNotify : ITaskMessageNotify
{
private readonly Channel<NotifyMessage> _channel = Channel.CreateUnbounded<NotifyMessage>();
public ChannelReader<NotifyMessage> Reader => _channel.Reader;
public ChannelWriter<NotifyMessage> Writer => _channel.Writer;
}
//public static class TaskMesageNotify
//{
// private static readonly Channel<string> _channel = Channel.CreateUnbounded<string>();
// public static ChannelReader<string> Reader => _channel.Reader;
// public static ChannelWriter<string> Writer => _channel.Writer;
//}
public static class TaskMessageNotifyExtensions
{
public static IServiceCollection AddTaskMessageNotify(this IServiceCollection services)
{
services.AddSingleton<ITaskMessageNotify, TaskMesageNotify>();
return services;
}
}
}