예제 #1
0
        public async Task ProcessUserUpdates(UserUpdateEntityBackendContract userUpdate)
        {
            var queueName = QueueHelper.BuildQueueName(_settings.MarginTradingFront.RabbitMqQueues.UserUpdates.ExchangeName, _settings.MarginTradingFront.Env);

            _consoleWriter.WriteLine($"Get user update from {queueName} queue for {userUpdate.ClientIds.Length} clients");

            foreach (var clientId in userUpdate.ClientIds)
            {
                try
                {
                    var notificationId = await _clientNotificationService.GetNotificationId(clientId);

                    var userTopic =
                        _realm.Services.GetSubject <NotifyResponse <UserUpdateEntityClientContract> >(
                            $"user.{notificationId}");

                    var response = new NotifyResponse <UserUpdateEntityClientContract>
                    {
                        Entity = userUpdate.ToClientContract(),
                        Type   = NotifyEntityType.UserUpdate
                    };

                    userTopic.OnNext(response);

                    var eventType = string.Empty;

                    if (userUpdate.UpdateAccountAssetPairs)
                    {
                        eventType = "account assets";
                    }

                    if (userUpdate.UpdateAccounts)
                    {
                        eventType = "accounts";
                    }

                    _operationsLog.AddLog($"topic user.{notificationId} ({eventType} changed)", clientId, null, null,
                                          response.ToJson());
                    _consoleWriter.WriteLine(
                        $"topic user.{notificationId} ({eventType} changed) for clientId = {clientId}");

                    var userUpdateTopic         = _realm.Services.GetSubject <NotifyResponse>($"user.updates.{notificationId}");
                    var userUpdateTopicResponse = new NotifyResponse {
                        UserUpdate = response.Entity
                    };

                    userUpdateTopic.OnNext(userUpdateTopicResponse);

                    _operationsLog.AddLog($"topic user.updates.{notificationId} ({eventType} changed)", clientId, null,
                                          null, userUpdateTopicResponse.ToJson());
                    _consoleWriter.WriteLine(
                        $"topic user.updates.{notificationId} (account assets changed) for clientId = {clientId}");
                }
                catch (Exception ex)
                {
                    await _log.WriteErrorAsync(nameof(RabbitMqHandler), nameof(ProcessUserUpdates), clientId, ex);
                }
            }
        }
예제 #2
0
 public static UserUpdateEntityClientContract ToClientContract(this UserUpdateEntityBackendContract src)
 {
     return(new UserUpdateEntityClientContract
     {
         UpdateAccountAssetPairs = src.UpdateAccountAssetPairs,
         UpdateAccounts = src.UpdateAccounts
     });
 }