60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
|
|
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();
|