public bool Handle(TransportMessage message) { var timeoutId = message.Headers["Timeout.Id"]; var persisterV2 = TimeoutsPersister as IPersistTimeoutsV2; if (persisterV2 != null) { var timeoutData = persisterV2.Peek(timeoutId); if (timeoutData == null) { return true; } var sendOptions = timeoutData.ToSendOptions(Configure.LocalAddress); if (ShouldSuppressTransaction()) { sendOptions.EnlistInReceiveTransaction = false; } MessageSender.Send(timeoutData.ToTransportMessage(), sendOptions); return persisterV2.TryRemove(timeoutId); } else { TimeoutData timeoutData; if (TimeoutsPersister.TryRemove(timeoutId, out timeoutData)) { MessageSender.Send(timeoutData.ToTransportMessage(), timeoutData.ToSendOptions(Configure.LocalAddress)); } } return true; }
public void Send(TransportMessage msg) { msg.From = Host; Out.Add(msg); _logger.Debug(Host + " send " + _serializer.ToString(msg)); Thread.Sleep(1); }
public bool Handle(TransportMessage message) { //dispatch request will arrive at the same input so we need to make sure to call the correct handler if (message.Headers.ContainsKey(TimeoutIdToDispatchHeader)) HandleBackwardsCompatibility(message); else HandleInternal(message); return true; }
void HandleInternal(TransportMessage message) { var sagaId = Guid.Empty; string sagaIdString; if (message.Headers.TryGetValue(Headers.SagaId, out sagaIdString)) { sagaId = Guid.Parse(sagaIdString); } if (message.Headers.ContainsKey(TimeoutManagerHeaders.ClearTimeouts)) { if (sagaId == Guid.Empty) throw new InvalidOperationException("Invalid saga id specified, clear timeouts is only supported for saga instances"); TimeoutManager.RemoveTimeoutBy(sagaId); } else { string expire; if (!message.Headers.TryGetValue(TimeoutManagerHeaders.Expire, out expire)) { throw new InvalidOperationException("Non timeout message arrived at the timeout manager, id:" + message.Id); } var destination = message.ReplyToAddress; string routeExpiredTimeoutTo; if (message.Headers.TryGetValue(TimeoutManagerHeaders.RouteExpiredTimeoutTo, out routeExpiredTimeoutTo)) { destination = Address.Parse(routeExpiredTimeoutTo); } var data = new TimeoutData { Destination = destination, SagaId = sagaId, State = message.Body, Time = DateTimeExtensions.ToUtcDateTime(expire), CorrelationId = GetCorrelationIdToStore(message), Headers = message.Headers, OwningTimeoutManager = Configure.EndpointName }; //add a temp header so that we can make sure to restore the ReplyToAddress if (message.ReplyToAddress != null) { data.Headers[TimeoutData.OriginalReplyToAddress] = message.ReplyToAddress.ToString(); } TimeoutManager.PushTimeout(data); } }
public bool Handle(TransportMessage message) { var timeoutId = message.Headers["Timeout.Id"]; TimeoutData timeoutData; if (TimeoutsPersister.TryRemove(timeoutId, out timeoutData)) { MessageSender.Send(timeoutData.ToTransportMessage(), timeoutData.ToSendOptions(Configure.LocalAddress)); } return true; }
string GetCorrelationIdToStore(TransportMessage message) { var correlationIdToStore = message.CorrelationId; if (MessageSender is MsmqMessageSender) { Guid correlationId; if (Guid.TryParse(message.CorrelationId, out correlationId)) { correlationIdToStore = message.CorrelationId + "\\0";//msmq required the id's to be in the {guid}\{incrementing number} format so we need to fake a \0 at the end to make it compatible } } return correlationIdToStore; }
void HandleBackwardsCompatibility(TransportMessage message) { var timeoutId = message.Headers[TimeoutIdToDispatchHeader]; var destination = Address.Parse(message.Headers[TimeoutDestinationHeader]); //clear headers message.Headers.Remove(TimeoutIdToDispatchHeader); message.Headers.Remove(TimeoutDestinationHeader); string routeExpiredTimeoutTo; if (message.Headers.TryGetValue(TimeoutManagerHeaders.RouteExpiredTimeoutTo, out routeExpiredTimeoutTo)) { destination = Address.Parse(routeExpiredTimeoutTo); } TimeoutManager.RemoveTimeout(timeoutId); MessageSender.Send(message, destination); }
public void Inject(TransportMessage msg) { In.Add(msg); Thread.Sleep(1); }
public void Send(TransportMessage msg) { _pipeline.Send(msg); }
private void ShipIt(TransportMessage msg) { try { TcpClient client = null; lock (_lockObject) { if (Destinations.ContainsKey(msg.To) == false) client = OpenTcpConnection(msg.To); else { client = Destinations[msg.To]; if (!IsTcpConnectionOpen(client)) client = OpenTcpConnection(msg.To); } if (client != null) Destinations[msg.To] = client; else return; } var stream = client.GetStream(); var reader = new StreamReader(stream); var writer = new StreamWriter(stream) { AutoFlush = true }; msg.From = _host; var request = _serializer.ToString(msg); _logger.Debug(_host + " s req:" + request); writer.WriteLine(request); var replay = reader.ReadLine(); _logger.Debug(_host + " r rep:" + replay); if (replay == null) return; var rep = _serializer.FromString(replay); _pipeline.Delivery(rep); } catch (IOException e) { _logger.Info(_host + " busy: " + msg.To); } catch (SocketException e) { _logger.Info(_host + " unreachble: " + msg.To); } }
private void OnDispatchMessage(TransportMessage msg) { Task.Factory.StartNew(() => { ShipIt(msg); }, _ts.Token); }
private void OnDeliverMessage(TransportMessage message) { if (Deliver != null) Deliver(message); }
public string ToString(TransportMessage msg) { return JsonConvert.SerializeObject(msg); }
public TransportMessage Clone(TransportMessage target) { return FromString(ToString(target)); }