Histórico da Página
...
Bloco de código | ||||||
---|---|---|---|---|---|---|
| ||||||
using Newtonsoft.Json.LinqRM.Glb.SGDP.SmartLink.Service.Domain; using RM.Glb.SGDP.SmartLink.Service.Domain.Interfaces; using RM.Lib.Data; using RM.Lib.Log; using RM.Lib.SmartLink.Domain.DataModel; using RM.Lib.SmartLink.Domain.Interfaces; using RM.Lib.SmartLink.Domain.Publisher; using System; using System.Collections.Generic; using System.Linq; namespace RM.Glb.SGDP.SmartLink.Service { public class GlbSGDPPublisherMessageService : IGlbSGDPPublisherMessageService { private readonly IGlbSGDPResolverService _SGDPResolverServicesgdpResolverService; private readonly IRMSSmartLinkPublisherService _SmartLinkPublisherServicesmartLinkPublisherService; private readonly IRMSLogger _LogServicelogService; private const string ctSGDPMaskResponseEndPointctSGDPUpdateTenantMetadataEndPoint = "/api/v1/link/send/SGDPMaskResponseSGDPUpdateTenantMetadata/SGDP"; private const string ctSGDPDataResponseEndPoint = "/api/v1/link/send/SGDPDataResponse/SGDP"; private const string ctSGDPUpdateTenantMetadataEndPointctSGDPUpdateTenantMetadata = "/api/v1/link/send/SGDPUpdateTenantMetadata/SGDP"; private const string ctSGDPUpdateTenantMetadatactSGDPDataCommand = "SGDPUpdateTenantMetadataSGDPDataCommand"; private const string ctSGDPDataCommandctSGDPResponseDataCommand = "SGDPDataCommandSGDPResponseDataCommand"; private const string ctSGDPMaskCommandctSGDPMaskResponseEndPoint = "SGDPMaskCommand/api/v1/link/send/SGDPMaskResponse/SGDP"; private const string ctSGDPResponseDataCommandctSGDPMaskCommand = "SGDPResponseDataCommandSGDPMaskCommand"; private const string ctSGDPResponseMaskCommand = "SGDPResponseMaskCommand"; private const string ctSmartLinkSetupCommandctSGDPLogResponseEndPoint = "Setup/api/v1/link/send/SGDPLogsResponse/SGDP"; private const string ctSmartLinkUnSetupCommandctSGDPLogsCommand = "UnSetupSGDPLogsCommand"; publicprivate GlbSGDPPublisherMessageService(IRMSSmartLinkPublisherService smartLinkPublisherService, const string ctSGDPResponseLogCommand = "SGDPResponseLogsCommand"; private const string ctSmartLinkSetupCommand = "setup"; private const string ctSmartLinkUnSetupCommand = "unSetup"; public GlbSGDPPublisherMessageService(IRMSSmartLinkPublisherService smartLinkPublisherService, IGlbSGDPResolverService sgdpResolverService, IRMSLogger logService) { _SmartLinkPublisherServicesmartLinkPublisherService = smartLinkPublisherService; _SGDPResolverServicesgdpResolverService = sgdpResolverService; _LogServicelogService = logService; } /// <summary> /// Adiciona uma mensagem de reposta para o comando "SGDPResponseDataCommand". /// </summary> /// <param name="parms"></param> public void AddResponseDataCommand(AddResponseDataCommandParms parms) { SmartLinkPublisherAddMessageParams parPublisher = new SmartLinkPublisherAddMessageParams(); { parPublisher.Command = ctSGDPResponseDataCommand;, parPublisher.CorrelatedId = parms.CorrelatedId }; ; parPublisher.Data = parms.Message; parPublisher.RouterMessage = ctSGDPDataResponseEndPoint; _LogServicelogService.NotifyLogInfo(Properties.Resources.sconTotvsAppSGDPResponseDataCommandGravadoNaFila); _SmartLinkPublisherServicesmartLinkPublisherService.AddMessage(parPublisher); } /// <summary> /// Adiciona uma mensagem de reposta para o comando "SGDPResponseMaskCommand". /// </summary> /// <param name="parms"></param> public void AddResponseMaskCommand(AddResponseMaskCommandParms parms) { SmartLinkPublisherAddMessageParams parPublisher = new SmartLinkPublisherAddMessageParams(); { parPublisher.Command = ctSGDPResponseMaskCommand;, parPublisher.CorrelatedId = parms.CorrelatedId;, parPublisher.Data Data = parms.Message;, parPublisher. RouterMessage = ctSGDPMaskResponseEndPoint }; _LogServicelogService.NotifyLogInfo(Properties.Resources.sconTotvsAppSGDPResponseMaskCommandGravadoNaFila); _SmartLinkPublisherServicesmartLinkPublisherService.AddMessage(parPublisher); } /// <summary> /// Adiciona uma mensagem parade envioreposta depara umo comando de sgldpdateapplicationmetada"SGDPResponseLogCommand". /// </summary> /// <param name="parms">Parms</param> public void AddMessageUpdateTenantMetadataAddResponseLogCommand(AddMessageUpdateTenantMetadataParmsAddResponseLogCommandParms parms) { SmartLinkPublisherAddMessageParams if (CanAddTenantMetadataMessage())parPublisher = new SmartLinkPublisherAddMessageParams { Command try= ctSGDPResponseLogCommand, { CorrelatedId = parms.CorrelatedId, List<string> jsonsData = GetUpdateTenandMetadata(parms.TenantId);Message, RouterMessage = foreachctSGDPLogResponseEndPoint (string json in jsons) }; {_logService.NotifyLogInfo(Properties.Resources.sconTotvsAppSGDPResponseLogCommandGravadoNaFila); _smartLinkPublisherService.AddMessage(parPublisher); } SmartLinkPublisherAddMessageParams smartLinkParms = new SmartLinkPublisherAddMessageParams();/// <summary> /// Adiciona uma mensagem para envio de um smartLinkParms.Commandcomando =de ctSGDPUpdateTenantMetadata;sgldpdateapplicationmetada. /// </summary> public void smartLinkParms.CorrelatedId = "";AddMessageUpdateTenantMetadata(AddMessageUpdateTenantMetadataParms parms) { if smartLinkParms.Data = json; (CanAddTenantMetadataMessage()) { try smartLinkParms.RouterMessage = ctSGDPUpdateTenantMetadataEndPoint;{ List<string> jsons = _LogService.NotifyLogInfo(Properties.Resources.sconTotvsAppSGDPTenantMetadaGravadoNaFilaGetUpdateTenandMetadata(parms.TenantId); foreach (string _SmartLinkPublisherService.AddMessage(smartLinkParms);json in jsons) }{ } SmartLinkPublisherAddMessageParams smartLinkParms = new catch SmartLinkPublisherAddMessageParams(Exception ex); { smartLinkParms.Command _LogService.NotifyLogWarning(ex, Properties.Resources.sconTotvsAppErroAoEnviarSGDPUpdateTenantMetadata)= ctSGDPUpdateTenantMetadata; } smartLinkParms.CorrelatedId = }""; } private bool CanAddTenantMetadataMessage() smartLinkParms.Data = {json; //Se existir alguma mensagem de sgdpsmartLinkParms.RouterMessage para= serctSGDPUpdateTenantMetadataEndPoint; processada, então não envia atualizaçaõ de medatdos pois esse processo é caro. _logService.NotifyLogInfo(Properties.Resources.sconTotvsAppSGDPTenantMetadaGravadoNaFila); var pendingMessages = _SmartLinkPublisherServicesmartLinkPublisherService.GetPendingMessagesAddMessage(smartLinkParms); List<SmartLinkMessageDataModel> messageUpstream = pendingMessages?.Messages?.Where( } } y => y.TypeEvent == ctSGDPUpdateTenantMetadata || catch (Exception ex) { y.TypeEvent == ctSGDPDataCommand || _logService.NotifyLogWarning(ex, Properties.Resources.sconTotvsAppErroAoEnviarSGDPUpdateTenantMetadata); y.TypeEvent == ctSGDPMaskCommand ||} } } y.TypeEvent ==private ctSGDPResponseDataCommand ||bool CanAddTenantMetadataMessage() { //Se existir alguma y.TypeEvent == ctSGDPResponseMaskCommand).ToList(); if (messageUpstream?.Count > 0)//Se existir alguma não inclua na fila..mensagem de sgdp para ser processada, então não envia atualizaçaõ de medatdos pois esse processo é caro. var pendingMessages return false; = _smartLinkPublisherService.GetPendingMessages(); List<SmartLinkMessageDataModel> messageUpstream = pendingMessages?.Messages?.Where( y => y.TypeEvent == ctSGDPUpdateTenantMetadata || y.TypeEvent == ctSGDPDataCommand || y.TypeEvent == ctSGDPMaskCommand || y.TypeEvent == ctSGDPResponseDataCommand || y.TypeEvent == ctSGDPResponseMaskCommand).ToList(); if (messageUpstream?.Count > 0)//Se existir alguma não inclua na fila... return false; return true; } private List<string> GetUpdateTenandMetadata(string tenantId) { return _sgdpResolverService.GetSGDPTenantMetadata( new MetadataTenantParms() { TenantId = tenantId } )?.JsonsResult; } public void AddMessageUnSetup() { var pendingMessages = _smartLinkPublisherService.GetPendingMessages(); List<SmartLinkMessageDataModel> messagesSGDP = pendingMessages?.Messages?.Where(y => y.TypeEvent.ToUpper() == ctSGDPUpdateTenantMetadata.ToUpper() && return true; } private List<string> GetUpdateTenandMetadata(string tenantId) { return _SGDPResolverService.GetSGDPTenantMetadata( new MetadataTenantParms() { TenantId = tenantId } y.TypeEvent.ToUpper() == ctSGDPDataCommand.ToUpper() && )?.JsonsResult; } public void AddMessageUnSetup() { var pendingMessages = _SmartLinkPublisherService.GetPendingMessages(); List<SmartLinkMessageDataModel> messagesSGDP = pendingMessages?.Messages?.Where(y => y.TypeEvent.ToUpper() == ctSGDPUpdateTenantMetadatactSGDPMaskCommand.ToUpper() && y.TypeEvent.ToUpper() == ctSGDPDataCommandctSGDPLogsCommand.ToUpper() && y.TypeEvent.ToUpper() == ctSGDPMaskCommandctSGDPResponseDataCommand.ToUpper() && y.TypeEvent.ToUpper() == ctSGDPResponseDataCommandctSGDPResponseMaskCommand.ToUpper() &&).ToList(); if (messagesSGDP != null) { foreach (SmartLinkMessageDataModel model in messagesSGDP) { y.TypeEvent.ToUpper() == ctSGDPResponseMaskCommand.ToUpper()).ToList( _smartLinkPublisherService.RemoveMessageById(model.Id); foreach (SmartLinkMessageDataModel model in messagesSGDP)} _SmartLinkPublisherService.RemoveMessageById(model.Id);} SmartLinkPublisherAddMessageParams parms = new SmartLinkPublisherAddMessageParams(); { parms.Command = ctSmartLinkUnSetupCommand;, parms.CorrelatedId = "";, parms. Data = _SGDPResolverServicesgdpResolverService.GetSGDPSetup().JsonResult }; _LogServicelogService.NotifyLogInfo(Properties.Resources.sconTotvsAppUnSetupGravadoNaFila); _SmartLinkPublisherServicesmartLinkPublisherService.AddMessage(parms); } public void AddMessageSetup() { SmartLinkPublisherAddMessageParams parms = new SmartLinkPublisherAddMessageParams(); { parms. Command = ctSmartLinkSetupCommand;, parms.CorrelatedId = "";, parms.Data = _SGDPResolverServicesgdpResolverService.GetSGDPSetup().JsonResult }; _LogServicelogService.NotifyLogInfo(Properties.Resources.sconTotvsAppSetupGravadoNaFila); _SmartLinkPublisherServicesmartLinkPublisherService.AddMessage(parms); } } } |
04. Implementando um consumidor de mensagens
...
Visão Geral
Import HTML Content
Conteúdo das Ferramentas
Tarefas