public void RunPipeline(PairSocket shim) { while (true) { try { NetMQMessage msg = shim.ReceiveMessage(); string command = msg[0].ConvertToString(); if (command == ActorKnownMessages.END_PIPE) { break; } //Simulate a failure that should be sent back to Actor //Simulate a failure that should be sent back to Actor //Simulate a failure that should be sent back to Actor //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 falut will bubble up to callers code catch (InvalidOperationException e) { shim.Send(string.Format("Error: Exception occurred {0}", e.Message)); } } //broken out of work loop, so should dispose shim socket now shim.Dispose(); }
public void RunPipeline(PairSocket shim) { 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.ReceiveMessage(); string command = msg[0].ConvertToString(); if (command == ActorKnownMessages.END_PIPE) { break; } if (msg[0].ConvertToString() == "AMEND ACCOUNT") { string accountActionJson = msg[1].ConvertToString(); AccountAction accountAction = JsonConvert.DeserializeObject <AccountAction>(accountActionJson); string accountJson = msg[2].ConvertToString(); Account 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 falut will bubble up to callers code catch (Exception e) { shim.Send(string.Format("Error: Exception occurred {0}", e.Message)); } } //broken out of work loop, so should dispose shim socket now shim.Dispose(); }
public void Run(PairSocket shim, object[] args, CancellationToken token) { if (args == null || args.Count() != 1) { throw new InvalidOperationException( "Args were not correct, expected one argument"); } AccountAction accountAction = JsonConvert.DeserializeObject <AccountAction>(args[0].ToString()); while (!token.IsCancellationRequested) { //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 "AMEND ACCOUNT" NetMQMessage msg = null; //this may throw NetMQException if we have disposed of the actor //end of the pipe, and the CancellationToken.IsCancellationRequested //did not get picked up this loop cycle msg = shim.ReceiveMessage(); if (msg == null) { break; } if (msg[0].ConvertToString() == "AMEND ACCOUNT") { string json = msg[1].ConvertToString(); Account account = JsonConvert.DeserializeObject <Account>(json); AmmendAccount(accountAction, account); shim.Send(JsonConvert.SerializeObject(account)); } else { throw NetMQException.Create("Unexpected command", ErrorCode.EFAULT); } } }
public void RunPipeline(PairSocket shim) { 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.ReceiveMessage(); string command = msg[0].ConvertToString(); if (command == ActorKnownMessages.END_PIPE) { 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 falut will bubble up to callers code catch (Exception e) { shim.Send(string.Format("Error: Exception occurred {0}", e.Message)); } } //broken out of work loop, so should dispose shim socket now shim.Dispose(); }
public void Run(PairSocket shim, object[] args, CancellationToken token) { if (args == null || args.Count() != 1) throw new InvalidOperationException( "Args were not correct, expected one argument"); AccountAction accountAction = JsonConvert.DeserializeObject<AccountAction>(args[0].ToString()); while (!token.IsCancellationRequested) { //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 "AMEND ACCOUNT" NetMQMessage msg = null; //this may throw NetMQException if we have disposed of the actor //end of the pipe, and the CancellationToken.IsCancellationRequested //did not get picked up this loop cycle msg = shim.ReceiveMessage(); if (msg == null) break; if (msg[0].ConvertToString() == "AMEND ACCOUNT") { string json = msg[1].ConvertToString(); Account account = JsonConvert.DeserializeObject<Account>(json); AmmendAccount(accountAction, account); shim.Send(JsonConvert.SerializeObject(account)); } else { throw NetMQException.Create("Unexpected command", ErrorCode.EFAULT); } } }
public void Run(PairSocket shim, object[] args, CancellationToken token) { if (args == null || args.Count() != 1 || (string)args[0] != "Hello World") { throw new InvalidOperationException( "Args were not correct, expected 'Hello World'"); } while (!token.IsCancellationRequested) { //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 = null; //this may throw NetMQException if we have disposed of the actor //end of the pipe, and the CancellationToken.IsCancellationRequested //did not get picked up this loop cycle msg = shim.ReceiveMessage(); if (msg == null) { break; } if (msg[0].ConvertToString() == "ECHO") { shim.Send(string.Format("ECHO BACK : {0}", msg[1].ConvertToString())); } else { throw NetMQException.Create("Unexpected command", ErrorCode.EFAULT); } } }
public void Run(PairSocket shim, object[] args, CancellationToken token) { if (args == null || args.Count() != 1 || (string)args[0] != "Hello World") throw new InvalidOperationException( "Args were not correct, expected 'Hello World'"); while (!token.IsCancellationRequested) { //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 = null; //this may throw NetMQException if we have disposed of the actor //end of the pipe, and the CancellationToken.IsCancellationRequested //did not get picked up this loop cycle msg = shim.ReceiveMessage(); if (msg == null) break; if (msg[0].ConvertToString() == "ECHO") { shim.Send(string.Format("ECHO BACK : {0}", msg[1].ConvertToString())); } else { throw NetMQException.Create("Unexpected command", ErrorCode.EFAULT); } } }
private void OnMessagePipeReady(object sender, NetMQSocketEventArgs e) { NetMQMessage request = m_messagesPipe.ReceiveMessage(); OnOutgoingMessage(request); }