refactor: 拆分自动铺码服务为独立PrintWorker项目
1. 将原WorkService中的AutoDotCodeConsumer、RabbitMQHostedService、IQueueConsumer迁移至新的PrintWorker项目 2. 移除WorkService中冗余的PrintTool依赖文件复制配置 3. 将PrintToolV2.7相关资源移动到PrintWorker项目中统一管理 4. 从WorkService中移除AutoDotCodeConsumer的服务注册 5. 新增PrintWorker项目的完整宿主程序与配置文件
This commit is contained in:
59
QYZH.InteractiveMagazine.PrintWorker/Program.cs
Normal file
59
QYZH.InteractiveMagazine.PrintWorker/Program.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using QYZH.InteractiveMagazine.Infrastructure.RabbitMQ;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.Redis;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.SDK;
|
||||
using QYZH.InteractiveMagazine.PrintWorker.Consumers;
|
||||
using Serilog;
|
||||
using SqlSugar;
|
||||
using SqlSugar.IOC;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
builder.Configuration
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(builder.Configuration)
|
||||
.Enrich.FromLogContext()
|
||||
.CreateLogger();
|
||||
|
||||
builder.Services.AddSerilog();
|
||||
builder.Services.AddWindowsService(options => options.ServiceName = "QYZH InteractiveMagazine PrintWorker");
|
||||
|
||||
YitIdHelper.SetIdGenerator(new IdGeneratorOptions { WorkerId = 3 });
|
||||
|
||||
builder.Services.AddSqlSugar(new IocConfig
|
||||
{
|
||||
ConfigId = 0,
|
||||
DbType = IocDbType.MySql,
|
||||
ConnectionString = builder.Configuration.GetConnectionString("DefaultConnection"),
|
||||
IsAutoCloseConnection = true
|
||||
});
|
||||
|
||||
SugarIocServices.ConfigurationSugar(db =>
|
||||
{
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Log.Information("[SQL] {Sql}", UtilMethods.GetSqlString((DbType)IocDbType.MySql, sql, pars));
|
||||
};
|
||||
db.Aop.OnError = ex =>
|
||||
{
|
||||
Log.Error(ex, "[SQL Error] {Message}", ex.Message);
|
||||
};
|
||||
});
|
||||
|
||||
builder.Services.AddScoped<ISqlSugarClient>(_ => DbScoped.SugarScope);
|
||||
builder.Services.AddCSRedisCacheExtension(builder.Configuration.GetSection("RedisSettings"));
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddSDKService(builder.Configuration);
|
||||
builder.Services.AddRabbitMQ(builder.Configuration);
|
||||
|
||||
builder.Services.AddScoped<IQueueConsumer, AutoDotCodeConsumer>();
|
||||
builder.Services.AddHostedService<RabbitMQHostedService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
Log.Information("PrintWorker 已启动,仅消费自动铺码队列");
|
||||
|
||||
await app.RunAsync();
|
||||
Reference in New Issue
Block a user