2021-11-09 18:50:49 +08:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Yi.Framework.Common.IOCOptions;
|
|
|
|
|
|
using Yi.Framework.Common.Models;
|
|
|
|
|
|
using Yi.Framework.Core;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Yi.Framework.ElasticSearchProcessor
|
|
|
|
|
|
{
|
|
|
|
|
|
public class InitESIndexWorker : BackgroundService
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
|
private readonly ILogger<InitESIndexWorker> _logger;
|
|
|
|
|
|
private readonly RabbitMQInvoker _RabbitMQInvoker;
|
|
|
|
|
|
private readonly ElasticSearchInvoker _elasticSearchInvoker;
|
|
|
|
|
|
|
|
|
|
|
|
public InitESIndexWorker(ILogger<InitESIndexWorker> logger, RabbitMQInvoker rabbitMQInvoker, IConfiguration configuration, ElasticSearchInvoker elasticSearchInvoker)
|
|
|
|
|
|
{
|
|
|
|
|
|
this._logger = logger;
|
|
|
|
|
|
this._RabbitMQInvoker = rabbitMQInvoker;
|
|
|
|
|
|
this._configuration = configuration;
|
|
|
|
|
|
this._elasticSearchInvoker = elasticSearchInvoker;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
RabbitMQConsumerModel rabbitMQConsumerModel = new RabbitMQConsumerModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
ExchangeName = RabbitMQExchangeQueueName.SKUCQRS_Exchange,
|
|
|
|
|
|
QueueName = RabbitMQExchangeQueueName.SKUCQRS_Queue_ESIndex
|
|
|
|
|
|
};
|
|
|
|
|
|
HttpClient _HttpClient = new HttpClient();
|
|
|
|
|
|
this._RabbitMQInvoker.RegistReciveAction(rabbitMQConsumerModel, message =>
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
//<2F><><EFBFBD>õ<EFBFBD>ģ<EFBFBD>͡<EFBFBD>
|
|
|
|
|
|
//SPUCQRSQueueModel spuCQRSQueueModel = JsonConvert.DeserializeObject<SPUCQRSQueueModel>(message);
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>ɾ<EFBFBD>ģ<EFBFBD>es<65><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
//switch (spuCQRSQueueModel.CQRSType)
|
|
|
|
|
|
//{
|
2021-11-09 18:55:11 +08:00
|
|
|
|
// case (int)SPUCQRSQueueModelType.Insert:
|
|
|
|
|
|
// case (int)SPUCQRSQueueModelType.Update:
|
|
|
|
|
|
// {
|
|
|
|
|
|
// Goods goods = this._ISearchService.GetGoodsBySpuId(spuCQRSQueueModel.SpuId);
|
|
|
|
|
|
// this._IElasticSearchService.InsertOrUpdata<Goods>(goods);
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// case (int)SPUCQRSQueueModelType.Delete:
|
|
|
|
|
|
// this._IElasticSearchService.Delete<Goods>(spuCQRSQueueModel.SpuId.ToString());
|
|
|
|
|
|
// break;
|
2021-11-09 18:50:49 +08:00
|
|
|
|
// default:
|
|
|
|
|
|
// throw new Exception("wrong spuCQRSQueueModel.CQRSType");
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
this._logger.LogInformation($"{nameof(InitESIndexWorker)}.Init ESIndex succeed SpuId");
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogModel logModel = new LogModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
OriginalClassName = this.GetType().FullName,
|
|
|
|
|
|
OriginalMethodName = nameof(ExecuteAsync),
|
|
|
|
|
|
Remark = "<22><>ʱ<EFBFBD><CAB1>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־"
|
|
|
|
|
|
};
|
|
|
|
|
|
this._logger.LogError(ex, $"{nameof(InitESIndexWorker)}.Init ESIndex failed message={message}, Exception:{ex.Message}", JsonConvert.SerializeObject(logModel));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
await Task.CompletedTask;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|