public void Run(PairSocket shim)
        {
            shim.SignalOK();

            while (true)
            {
                try
                {
                    NetMQMessage msg = shim.ReceiveMultipartMessage();

                    string command = msg[0].ConvertToString();

                    if (command == NetMQActor.EndShimMessage)
                        break;

                    //Simulate a failure that should be sent back to Actor
                    throw new InvalidOperationException("Actors Shim threw an Exception");
                }
                //You WILL need to decide what Exceptions should be caught here, this is for
                //demonstration purposes only, any unhandled fault will bubble up to caller's code
                catch (InvalidOperationException e)
                {
                    shim.Send(string.Format("Error: Exception occurred {0}", e.Message));
                }
            }
        }
        public void Run(PairSocket shim)
        {
            shim.SignalOK();

            while (true)
            {
                try
                {
                    //Message for this actor/shim handler is expected to be
                    //Frame[0] : Command
                    //Frame[2] : AccountAction as JSON
                    //Frame[1] : Account as JSON
                    //
                    //Result back to actor is a JSON message of the amended Account
                    NetMQMessage msg = shim.ReceiveMultipartMessage();

                    string command = msg[0].ConvertToString();

                    if (command == NetMQActor.EndShimMessage)
                        break;

                    if (msg[0].ConvertToString() == "AMEND ACCOUNT")
                    {
                        string accountActionJson = msg[1].ConvertToString();
                        var accountAction = JsonConvert.DeserializeObject<AccountAction>(accountActionJson);

                        string accountJson = msg[2].ConvertToString();
                        var account = JsonConvert.DeserializeObject<Account>(accountJson);
                        AmmendAccount(accountAction, account);
                        shim.Send(JsonConvert.SerializeObject(account));
                    }
                    else
                    {
                        shim.Send("Error: invalid message to actor");
                    }
                }
                // You WILL need to decide what Exceptions should be caught here, this is for
                // demonstration purposes only, any unhandled fault will bubble up to caller's code.
                catch (Exception e)
                {
                    shim.Send(string.Format("Error: Exception occurred {0}", e.Message));
                }
            }
        }
Beispiel #3
0
        public void Run(PairSocket shim)
        {
            shim.SignalOK();

            while (true)
            {
                try
                {
                    //Message for this actor/shim handler is expected to be
                    //Frame[0] : Command
                    //Frame[1] : Payload
                    //
                    //Result back to actor is a simple echoing of the Payload, where
                    //the payload is prefixed with "ECHO BACK "
                    NetMQMessage msg = shim.ReceiveMultipartMessage();

                    string command = msg[0].ConvertToString();

                    if (command == NetMQActor.EndShimMessage)
                        break;

                    if (command == "ECHO")
                    {
                        shim.Send(string.Format("ECHO BACK : {0}", msg[1].ConvertToString()));
                    }
                    else
                    {
                        shim.Send("Error: invalid message to actor");
                    }
                }
                // You WILL need to decide what Exceptions should be caught here, this is for
                // demonstration purposes only, any unhandled fault will bubble up to caller's code
                catch (Exception e)
                {
                    shim.Send(string.Format("Error: Exception occurred {0}", e.Message));
                }
            }
        }