public object DeserializeMessage(object value) { var buffer = (byte[])value; var typeHeaderLength = BitConverter.ToInt32(buffer.Take(4).ToArray(), 0); var typeHeader = Encoding.UTF8.GetString(buffer, 4, typeHeaderLength); var messageType = Type.GetType(typeHeader); var envelopeType = typeof(NamedPipeEnvelope <>).MakeGenericType(messageType); NamedPipeEnvelope pipeEnvelope = null; try { pipeEnvelope = Serializer.Deserialize(envelopeType, buffer.Skip(4 + typeHeaderLength).ToArray()) as NamedPipeEnvelope; pipeEnvelope.ReplyStream = this; if (pipeEnvelope.Message == null) { HandlePoisonMessage(value); } } catch (Exception e) { HandlePoisonMessage(value); } return(pipeEnvelope); }
public void Send <TMessage>(TMessage message, Action <IEnvelope> modifyEnvelope) { var envelope = new NamedPipeEnvelope( ) { CorrelationId = Definition.GetCorrelationId(message), RoutingKey = Definition.GetRoutingKey(message), Message = message, MessageType = typeof(TMessage) }; modifyEnvelope(envelope); Pipe.Send(envelope); }
public Future <TReply> ExpectReply <TReply, TMessage>(TMessage message, Action <IEnvelope> modifyEnvelope) { var envelope = new NamedPipeEnvelope( ) { CorrelationId = Definition.GetCorrelationId(message), RoutingKey = Definition.GetRoutingKey(message), Message = message, MessageType = typeof(TMessage) }; modifyEnvelope(envelope); var future = Future.Of <TReply>(() => Pipe.Send(envelope)); Dispatcher.ExpectResponse <TReply>(envelope.MessageId.ToString(), future); return(future); }
public void Send(NamedPipeEnvelope envelope) { var envelopeBuffer = Serializer.Serialize(envelope); var header = Encoding.UTF8.GetBytes(envelope.MessageType.AssemblyQualifiedName); var buffer = BitConverter .GetBytes(header.Length) .Concat(header) .Concat(envelopeBuffer) .ToArray(); Future.Of( x => Pipe.Stream.BeginWrite(buffer, 0, buffer.Length, x, null), x => { Pipe.Stream.EndWrite(x); Pipe.Stream.Flush(); Pipe.Stream.WaitForPipeDrain(); return(true); } ).Start(); }
public void Send(NamedPipeEnvelope envelope) { var envelopeBuffer = Serializer.Serialize( envelope ); var header = Encoding.UTF8.GetBytes( envelope.MessageType.AssemblyQualifiedName ); var buffer = BitConverter .GetBytes( header.Length ) .Concat( header ) .Concat( envelopeBuffer ) .ToArray(); Future.Of( x => Pipe.Stream.BeginWrite( buffer, 0, buffer.Length, x, null ), x => { Pipe.Stream.EndWrite( x ); Pipe.Stream.Flush(); Pipe.Stream.WaitForPipeDrain(); return true; } ).Start(); }