public bool TryFire(Command command, TimeSpan?responseTimeout = null, TimeSpan?ackTimeout = null) { if (RedirectToNull) { return(true); } return(_target?.TryFire(command, responseTimeout, ackTimeout) ?? false); }
public bool TryFire(Command command, out CommandResponse response, TimeSpan?responseTimeout = null, TimeSpan?ackTimeout = null) { if (RedirectToNull || _target == null) { response = command.Succeed(); return(true); } return(_target.TryFire(command, out response, responseTimeout, ackTimeout)); }
public void Handle(Message message) { if (_trackedMessages.Remove(message.MsgId)) { return; } if (message is Command) { _bus.TryFire((Command)message); } else { _bus.Publish(message); } }
public void Handle(Message message) { var type1 = MessageHierarchy.MsgTypeByTypeId[message.MsgTypeId]; dynamic cmd = message; var type2 = cmd.GetType(); if (!type1.Equals(type2)) { var error = $"Command object-type mismatch. MsgTypeId={message.MsgTypeId}, which MessageHierarchy claims is a {type1.FullName}. However, .Net Reflection says that the command is a {type2.FullName}"; Log.Error(error); throw new Exception(error); } var command = message as Command; if (command == null) { Log.Error("Message " + type1.Name + " MsgId= " + message.MsgId + " received from TCP, but is not a Command"); return; } var before = DateTime.UtcNow; CommandReceived(cmd, type1, "TcpBusSide"); CommandResponse response; try { _mainBus.TryFire(command, out response); } catch (Exception ex) { response = command.Fail(ex); } _outboundCommandQueuedHandler.Publish(response); PostHandleCommand(command, type1, (DateTime.UtcNow - before), response); }
protected CommandQueueSpecification( int queueCount = 1, int slowCmdMs = 500, int slowAckMs = 500) { Bus = new CommandBus( "Fixture Bus", slowCmdThreshold: TimeSpan.FromMilliseconds(slowCmdMs), slowMsgThreshold: TimeSpan.FromMilliseconds(slowAckMs)); Queue = new MultiQueuedHandler( queueCount, index => new QueuedHandler( new AdHocHandler <Message>( msg => { if (msg is Command) { Bus.TryFire((Command)msg); } else { Bus.Publish(msg); } }), $"Queue {index}" ) ); Queue.Start(); TestQueue = new TestQueue(Bus); try { Given(); When(); } catch (Exception) { throw; } }