public void Send <T>(ISendContext <T> context) where T : class { if (_disposed) { throw new ObjectDisposedException(_disposedMessage); } try { context.SetDestinationAddress(Address.Uri); context.SetBodyWriter(stream => _serializer.Serialize(stream, context)); _transport.Send(context); context.NotifySend(_address); if (SpecialLoggers.Messages.IsInfoEnabled) { SpecialLoggers.Messages.InfoFormat("SEND:{0}:{1}:{2}", Address, typeof(T).Name, context.MessageId); } } catch (Exception ex) { throw new SendException(typeof(T), _address.Uri, "An exception was thrown during Send", ex); } }
/// <summary> /// Sets the destination address of the message to be send. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context">The context.</param> /// <param name="uriString">The URI string.</param> public static void SetDestinationAddress <T>(this ISendContext <T> context, [NotNull] string uriString) where T : class { if (uriString == null) { throw new ArgumentNullException("uriString"); } context.SetDestinationAddress(uriString.ToUri()); }
protected void TestSerialization <T>(T message) where T : class { byte[] data; var serializer = new TSerializer(); _sourceUri = new Uri("loopback://localhost/source"); _responseUri = new Uri("loopback://localhost/response"); _faultUri = new Uri("loopback://localhost/fault"); _destinationUri = new Uri("loopback://localhost/destination"); _retryCount = 69; using (var output = new MemoryStream()) { ISendContext <T> context = message.ToSendContext(); context.SetSourceAddress(_sourceUri); context.SendResponseTo(_responseUri); context.SendFaultTo(_faultUri); context.SetDestinationAddress(_destinationUri); context.SetRetryCount(_retryCount); serializer.Serialize(output, context); data = output.ToArray(); } // Trace.WriteLine(Encoding.UTF8.GetString(data)); using (MemoryStream input = new MemoryStream(data)) { IReceiveContext context = ReceiveContext.FromBodyStream(input); serializer.Deserialize(context); IConsumeContext <T> messageContext; context.TryGetContext <T>(out messageContext).ShouldBeTrue(); messageContext.ShouldNotBeNull(); message.Equals(messageContext.Message).ShouldBeTrue(); message.ShouldNotBeTheSameAs(messageContext.Message); Assert.AreEqual(_retryCount, context.RetryCount); Assert.AreEqual(_sourceUri, context.SourceAddress); Assert.AreEqual(_responseUri, context.ResponseAddress); Assert.AreEqual(_faultUri, context.FaultAddress); Assert.AreEqual(_destinationUri, context.DestinationAddress); // Assert.AreEqual(message.GetType().ToMessageName(), CurrentMessage.Headers.MessageType); } }
public void Send <T>(ISendContext <T> context) where T : class { if (_disposed) { throw new ObjectDisposedException(_disposedMessage); } try { context.SetDestinationAddress(Address.Uri); context.SetBodyWriter(stream => _serializer.Serialize(stream, context)); _transport.Send(context); context.NotifySend(_address); } catch (Exception ex) { throw new SendException(typeof(T), _address.Uri, "An exception was thrown during Send", ex); } }
public static void SetDestinationAddress <T>(this ISendContext <T> context, string uriString) where T : class { context.SetDestinationAddress(uriString.ToUri()); }