Exemple #1
0
        public void SendPayload(Account account, AccountAction accountAction)
        {
            if (_actor == null)
            {
                return;
            }
            Log.Information("About to send person to Actor");
            var message = new NetMQMessage();

            message.Append("AmendAccount");
            message.Append(JsonConvert.SerializeObject(account));
            message.Append(JsonConvert.SerializeObject(accountAction));
            _actor.SendMultipartMessage(message);
        }
Exemple #2
0
        public void SendPayload(Account account, AccountAction accountAction)
        {
            if (actor == null)
            {
                return;
            }
            Console.WriteLine("About to send person to Actor");
            var message = new NetMQMessage();

            message.Append("AmmendAccount");
            message.Append(JsonConvert.SerializeObject(account));
            message.Append(JsonConvert.SerializeObject(accountAction));
            actor.SendMultipartMessage(message);
            Thread.Sleep(1000);
            Console.WriteLine(" Woke up from the sleep ");
        }
Exemple #3
0
        /// <summary>
        /// Reply from client.
        /// </summary>
        /// <param name="message"></param>
        private void RepSocketOnReceiveReadyImpl([NotNull] Tuple <byte[], INyxMessage> message)
        {
            try
            {
                // Get the cliendid
                var clientAddress = message.Item1;
                var result        = "1";
                var msg           = message.Item2;
                var abort         = false;
                var error         = string.Empty;

                // Optimized for the first false found. No need to run all filters.
                // Filters are not message processors so they should only filter to block or do background processing on messages
                // Before they can be used by the system.
                try
                {
                    var filterFound = _plugman.GetFilters(f => f.Direction.HasFlag(MessageDirection.In) && f.CanFilter(this)).FirstOrDefault(filter => msg != null && !filter.AllowMessage(msg, this, out error));
                    if (filterFound != null)
                    {
                        _logger.Warn("Message was filtered by {0}. Reason: {1}", filterFound.GetType().Name, error);
                        result = string.IsNullOrWhiteSpace(error) ? result : error;
                        abort  = true;
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error("Error filtering message.", ex);
                }

                // Send message and doesn't wait. Always returns the id of the message that we processed
                lock (_syncLock)
                {
                    var responseMsg = new NetMQMessage();
                    responseMsg.Append("response");
                    responseMsg.Append(clientAddress);
                    responseMsg.AppendEmptyFrame();
                    responseMsg.Append(result);
                    _hubActor.SendMultipartMessage(responseMsg);
                }

                if (abort)
                {
                    return;
                }
                _logger.Debug("New message. S:{0} T:{1}", StringExtensions.Trimmer(msg.Source), StringExtensions.Trimmer(msg.Target));

                try
                {
                    var hubPlugins = _plugman.GetActions <IHubAction>().Where(p => p.SupportedActions.Contains(msg.Action.ToLowerInvariant())).ToList();
                    if (hubPlugins.Any())
                    {
                        _logger.Trace("Executing action '{0}'...", msg.Action);
                        foreach (var hubAction in hubPlugins)
                        {
                            hubAction.ProcessMessage(msg.AsReadOnly());
                        }
                    }
                    else
                    {
                        _logger.Info("Direct pass-throught to channel '{0}'...", StringExtensions.Trimmer(msg.Target));
                        BroadcastMessage(msg);
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error("Error processing message.", ex);
                }
                _inMessageStatus.OnNext(new MessageStatus(this, msg.AsReadOnly(), MessageCondition.Received));
            }
            catch (Exception ex)
            {
                _logger.Error("Error occured processing nyx message.", ex);
                _inMessageStatus.OnNext(new MessageStatus(this, NyxMessage.EmptyIn, MessageCondition.Failed, ex.ToString()));
            }
        }