private void Send() { foreach (var contact in MailBox.Contacts) { _rabbitMQService.SendMessage( RabbitMQConstants.ExchangeEmail, new JsonQueueObject <IContact>(contact.Value, "Contact", RabbitMQConstants.RoutingKeyEmailEventCreated )); } foreach (var contractor in MailBox.Contractors) { _rabbitMQService.SendMessage( RabbitMQConstants.ExchangeEmail, new JsonQueueObject <IContractor>(contractor.Value, "Contractor", RabbitMQConstants.RoutingKeyEmailEventCreated )); } }
public Task OnSaveAsync(EmailMessage emailMessage) { _rabbitMQService.SendMessage( RabbitMQConstants.ExchangeEmail, new JsonQueueObject <EmailMessage>(emailMessage, "EmailMessage", MailBox.User.OwnerQueue ?? RabbitMQConstants.RoutingKeyEmailEventCreated)); return(Task.CompletedTask); }
/// <summary> /// Создает резерв товара и средств со счета пользователя. /// </summary> /// <param name="transaction">Транзакция.</param> private void MakeReserve(TransactionModel transaction) { var transactionDTO = new TransactionDataTransferObject { ProfileId = transaction.ProfileId, ProductId = transaction.ProductId, Cost = transaction.TotalCost }; var messageToProfile = new RabbitMessageModel { Action = (int)RabbitMessageActions.Apply, Sender = "TransactionAPI", Model = transactionDTO }; var messageToProduct = new RabbitMessageModel { Action = (int)RabbitMessageActions.Apply, Sender = "TransactionAPI", Model = transactionDTO }; _rabbitService.SendMessage(JsonConvert.SerializeObject(messageToProduct), "ProductAPI"); _rabbitService.SendMessage(JsonConvert.SerializeObject(messageToProfile), "ProfileAPI"); }
public bool SendToQueueInput(CreateEventDto createEventDto) { string md5Hash; StringBuilder sb = new StringBuilder(); sb.Append(createEventDto.Address) .Append(createEventDto.Description) .Append(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff")); using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create()) { byte[] inputBytes = Encoding.ASCII.GetBytes(sb.ToString()); var hashBytes = md5.ComputeHash(inputBytes); sb.Clear(); for (int i = 0; i < hashBytes.Length; i++) { sb.Append(hashBytes[i].ToString("X2")); } md5Hash = sb.ToString(); } createEventDto.Md5 = md5Hash; HttpContext httpContext = _httpContextAccessor.HttpContext; if (httpContext?.User != null && httpContext.User.Identity.IsAuthenticated && int.TryParse(httpContext.User.Claims.FirstOrDefault(claim => claim.Type == JwtConstants.ID_CLAIM_NAME).Value, out int userId)) { createEventDto.UserId = userId; } string json = JsonConvert.SerializeObject(createEventDto, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); return(_rabbitMQService.SendMessage(json, _rabbitMqSettings.InputQueueName)); }
//TODO сделать без обращения в бд internal void SendToUpdate(IUserMailbox userMailbox) { var localUser = new LocalUser() { Fio = userMailbox.Owner.ToString(), UserId = (int)userMailbox.Owner.Id }; if (!string.IsNullOrWhiteSpace(userMailbox.Aliases)) { localUser.Aliases = userMailbox.Aliases .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(c => c.Trim()).ToList(); } var server = new Server() { ConnectionType = ConnectionType.IMAP, Host = userMailbox.Server.ImapHost, Port = (int)userMailbox.Server.ImapPort, UseSsl = userMailbox.Server.RequaredSSL }; var userMailboxEmailPassword = userMailbox.EmailPassword == DefaultPassword? EncryptionHelper.DecryptPwd(userMailbox.PasswordEncoded) : userMailbox.EmailPassword; var mailBox = new MailBox(server, localUser) { Id = userMailbox.Id, LastStartTimeUtc = userMailbox.LastMailUpdate.ToUniversalTime(), Login = userMailbox.EmailLogin, Password = StringCipher.Encrypt(userMailboxEmailPassword, userMailbox.EmailLogin) }; _rabbitMqService.SendMessage( new JsonQueueObject <MailBox>( mailBox, "Mailbox", QueueConstants.RoutingKeyMailBoxCmdDownload)); // если не удалось отправить сообщение - не обновляем время чтения писем UpdateLastMailUpdate(userMailbox); }
public IActionResult SendMessageToQueue(RabbitMQMessage message) { _rabbitMQService.SendMessage(message.Message); return(Ok()); }