public void Send(ISendContext context) { if (_disposed) throw new ObjectDisposedException("The transport has already been disposed: " + Address); _outbound.Send(context); }
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); } }
public void Send <T>(T message) where T : class { ISendContext <T> context = ContextStorage.CreateSendContext(message); Send(context); }
public static void ForwardUsingOriginalContext(this ISendContext target, IConsumeContext source) { target.SetRequestId(source.RequestId); target.SetConversationId(source.ConversationId); target.SetCorrelationId(source.CorrelationId); target.SetSourceAddress(source.SourceAddress); target.SetResponseAddress(source.ResponseAddress); target.SetFaultAddress(source.FaultAddress); target.SetNetwork(source.Network); if (source.ExpirationTime.HasValue) { target.SetExpirationTime(source.ExpirationTime.Value); } target.SetRetryCount(source.RetryCount); foreach (var header in source.Headers) { target.SetHeader(header.Key, header.Value); } var inputAddress = source.InputAddress != null ? source.InputAddress.ToString() : source.DestinationAddress != null ? source.DestinationAddress.ToString() : null; if (!string.IsNullOrEmpty(inputAddress)) { target.SetHeader("mt.forwarder.uri", source.DestinationAddress.ToString()); } }
public override void Send(ISendContext context) { GuardAgainstDisposed(); LoopbackMessage message = null; try { message = new LoopbackMessage(); if (context.ExpirationTime.HasValue) { message.ExpirationTime = context.ExpirationTime.Value; } context.SerializeTo(message.Body); message.ContentType = context.ContentType; lock (_messageLock) { GuardAgainstDisposed(); _messages.AddLast(message); } } catch { if(message != null) message.Dispose(); throw; } _messageReady.Set(); }
public void Serialize <T>(Stream output, ISendContext <T> context) where T : class { try { context.SetContentType(ContentTypeHeaderValue); Envelope envelope = Envelope.Create(context); using (var nonClosingStream = new NonClosingStream(output)) using (var writer = new StreamWriter(nonClosingStream)) using (var jsonWriter = new JsonTextWriter(writer)) { jsonWriter.Formatting = Formatting.Indented; Serializer.Serialize(jsonWriter, envelope); jsonWriter.Flush(); writer.Flush(); } } catch (SerializationException) { throw; } catch (Exception ex) { throw new SerializationException("Failed to serialize message", ex); } }
public void Serialize <T>(Stream stream, ISendContext <T> context) where T : class { try { context.SetContentType(ContentTypeHeaderValue); XmlMessageEnvelope envelope = XmlMessageEnvelope.Create(context); _serializer.Serialize(stream, envelope, (declaringType, propertyType, value) => { if (declaringType == typeof(XmlMessageEnvelope) && propertyType == typeof(object)) { return(typeof(T)); } if (propertyType == typeof(object)) { return(value.GetType()); } return(propertyType); }); } catch (SerializationException) { throw; } catch (Exception ex) { throw new SerializationException("Failed to serialize message", ex); } }
public void Send(ISendContext context) { AddProducerBinding(); _connectionHandler.Use(connection => { try { IBasicProperties properties = _producer.CreateProperties(); properties.SetPersistent(context.DeliveryMode == DeliveryMode.Persistent); properties.MessageId = context.MessageId ?? properties.MessageId ?? NewId.Next().ToString(); if (context.ExpirationTime.HasValue) { DateTime value = context.ExpirationTime.Value; properties.Expiration = (value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now). TotalMilliseconds.ToString("F0", CultureInfo.InvariantCulture); } using (var body = new MemoryStream()) { context.SerializeTo(body); properties.Headers = context.Headers.ToDictionary(entry => entry.Key, entry => (object)entry.Value); properties.Headers["Content-Type"]=context.ContentType; #if NET40 var task = _producer.PublishAsync(_address.Name, properties, body.ToArray()); if(context.WaitForAck) task.Wait(); #else _producer.Publish(_address.Name, properties, body.ToArray()); #endif _address.LogSent(context.MessageId ?? properties.MessageId ?? "", context.MessageType); } } #if NET40 catch (AggregateException ex) { throw new TransportException(_address.Uri, "Publisher did not confirm message", ex.InnerException); } #endif catch (AlreadyClosedException ex) { throw new InvalidConnectionException(_address.Uri, "Connection was already closed", ex); } catch (EndOfStreamException ex) { throw new InvalidConnectionException(_address.Uri, "Connection was closed", ex); } catch (OperationInterruptedException ex) { throw new InvalidConnectionException(_address.Uri, "Operation was interrupted", ex); } }); }
PublishContext(T message, ISendContext context) : base(message, context) { _notifySend = context as IPublishContext; _wasEndpointAlreadySent = DefaultEndpointSent; _timer = Stopwatch.StartNew(); }
public void Send(ISendContext context) { AddProducerBinding(); _connectionHandler.Use(connection => { try { IBasicProperties properties = _producer.CreateProperties(); properties.SetPersistent(context.DeliveryMode == DeliveryMode.Persistent); properties.MessageId = context.MessageId ?? properties.MessageId ?? NewId.Next().ToString(); if (context.ExpirationTime.HasValue) { DateTime value = context.ExpirationTime.Value; properties.Expiration = (value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now). TotalMilliseconds.ToString("F0", CultureInfo.InvariantCulture); } using (var body = new MemoryStream()) { context.SerializeTo(body); properties.Headers = context.Headers.ToDictionary(entry => entry.Key, entry => (object)entry.Value); properties.Headers["Content-Type"] = context.ContentType; #if NET40 var task = _producer.PublishAsync(_address.Name, properties, body.ToArray()); task.Wait(); #else _producer.Publish(_address.Name, properties, body.ToArray()); #endif _address.LogSent(context.MessageId ?? properties.MessageId ?? "", context.MessageType); } } #if NET40 catch (AggregateException ex) { throw new TransportException(_address.Uri, "Publisher did not confirm message", ex.InnerException); } #endif catch (AlreadyClosedException ex) { throw new InvalidConnectionException(_address.Uri, "Connection was already closed", ex); } catch (EndOfStreamException ex) { throw new InvalidConnectionException(_address.Uri, "Connection was closed", ex); } catch (OperationInterruptedException ex) { throw new InvalidConnectionException(_address.Uri, "Operation was interrupted", ex); } }); }
public static XmlMessageEnvelope Create <T>(ISendContext <T> context) where T : class { var envelope = new XmlMessageEnvelope(typeof(T), context.Message); envelope.SetUsingContext(context); return(envelope); }
public void Send(ISendContext context) { if (_disposed) { throw new ObjectDisposedException("The transport has already been disposed: " + Address); } OutboundTransport.Send(context); }
public void Send <T>(T message, Action <ISendContext <T> > contextCallback) where T : class { ISendContext <T> context = ContextStorage.CreateSendContext(message); contextCallback(context); Send(context); }
public void Serialize <T>(Stream output, ISendContext <T> context) where T : class { CheckConvention.EnsureSerializable(context.Message); _formatter.Serialize(output, context.Message, GetHeaders(context)); context.SetContentType(ContentTypeHeaderValue); }
public void ApplyContext(ISendContext <TRequest> context, Uri responseAddress) { context.SetRequestId(_requestId); context.SetSourceAddress(responseAddress); context.SendResponseTo(responseAddress); context.SendFaultTo(responseAddress); _contextActions.Each(x => x(context)); }
/// <summary> /// Sets the fault address of the message to be send to the given <see cref="IServiceBus"/>. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context">The context.</param> /// <param name="bus">The bus.</param> public static void SendFaultTo <T>(this ISendContext <T> context, [NotNull] IServiceBus bus) where T : class { if (bus == null) { throw new ArgumentNullException("bus"); } context.SetFaultAddress(bus.Endpoint.Address.Uri); }
/// <summary> /// Creates a new envelope using the passed send context. /// </summary> /// <typeparam name="T">The type of message</typeparam> /// <param name="context">Context to write to the envelope</param> /// <returns>The constructed envelope</returns> public static Envelope Create <T>(ISendContext <T> context) where T : class { var envelope = new Envelope(context.Message, context.Message.GetType().GetMessageTypes()); envelope.SetUsingContext(context); return(envelope); }
/// <summary> /// Sets the fault address of the message to be send to the given <see cref="IEndpoint"/>. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context">The context.</param> /// <param name="endpoint">The endpoint.</param> public static void SendFaultTo <T>(this ISendContext <T> context, [NotNull] IEndpoint endpoint) where T : class { if (endpoint == null) { throw new ArgumentNullException("endpoint"); } context.SetFaultAddress(endpoint.Address.Uri); }
/// <summary> /// Sets the fault address of the message to be send to the given <see cref="Uri"/>. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context">The context.</param> /// <param name="uri">The URI.</param> public static void SendFaultTo <T>(this ISendContext <T> context, [NotNull] Uri uri) where T : class { if (uri == null) { throw new ArgumentNullException("uri"); } context.SetFaultAddress(uri); }
/// <summary> /// Sets the type of the message to be send. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context">The context.</param> /// <param name="messageType">Type of the message.</param> public static void SetMessageType <T>(this ISendContext <T> context, [NotNull] Type messageType) where T : class { if (messageType == null) { throw new ArgumentNullException("messageType"); } context.SetMessageType(messageType.ToMessageName()); }
/// <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()); }
// service bus best practices for performance: // http://msdn.microsoft.com/en-us/library/windowsazure/hh528527.aspx public void Send(ISendContext context) { _connectionHandler .Use(connection => { // don't have too many outstanding at same time SpinWait.SpinUntil(() => _messagesInFlight < _settings.MaxOutstanding); using (var body = new MemoryStream()) { context.SerializeTo(body); // the envelope is re-usable, so let's capture it in the below closure // as a value var envelope = new MessageEnvelope(body.ToArray()); var sending = Retries.Retry(FaultPolicies.FinalAzurePolicy, new Func <AsyncCallback, object, IAsyncResult>((cb, state) => { return(SendMessage(connection, () => { var brokeredMessage = new BrokeredMessage(envelope); if (!string.IsNullOrWhiteSpace(context.CorrelationId)) { brokeredMessage.CorrelationId = context.CorrelationId; } if (!string.IsNullOrWhiteSpace(context.MessageId)) { brokeredMessage.MessageId = context.MessageId; } return brokeredMessage; }, 1, cb, state)); }), (IAsyncResult ar) => { var state = (StateHolder)ar.AsyncState; Interlocked.Decrement(ref _messagesInFlight); try { state.Sender.EndSend(ar); Address.LogEndSend(state.Message.MessageId); } finally { // always dispose the message; it's only good once state.Message.Dispose(); } }); sending.Wait(); } }); }
public void Serialize <T>(Stream output, ISendContext <T> context) where T : class { context.SetContentType(ContentTypeHeaderValue); Envelope envelope = Envelope.Create(context); using (var outputStream = new NonClosingStream(output)) { ProtoBuf.Serializer.Serialize(outputStream, envelope); } }
public static PublishContext <T> FromMessage <TMessage>(TMessage message, ISendContext context) where TMessage : class { if (typeof(TMessage).IsAssignableFrom(typeof(T))) { return(new PublishContext <T>(message as T, context)); } return(null); }
protected SendContext(T message, ISendContext context) { _id = context.Id; _message = message; SetUsing(context); this.SetMessageType(typeof(T)); DeclaringMessageType = context.DeclaringMessageType; }
protected SendContext(T message, ISendContext context) : this(context.Id, message, context.DeclaringMessageType) { SetMessageId(_id.ToString()); SetUsing(context); // need to reset this since SetUsing copies the context value this.SetMessageType(typeof(T)); }
public IEnumerable <Action <ISendContext> > Enumerate(ISendContext context) { IBusPublishContext <TMessage> outputContext; if (!context.TryGetContext(out outputContext)) { return(Enumerable.Empty <Action <ISendContext> >()); } return(_output.Enumerate(outputContext).Select(consumer => (Action <ISendContext>)(x => consumer(outputContext)))); }
public static void SetUsingContext(this Envelope envelope, ISendContext headers) { envelope.SourceAddress = headers.SourceAddress.ToStringOrNull() ?? envelope.SourceAddress; envelope.DestinationAddress = headers.DestinationAddress.ToStringOrNull() ?? envelope.DestinationAddress; envelope.ResponseAddress = headers.ResponseAddress.ToStringOrNull() ?? envelope.ResponseAddress; envelope.FaultAddress = headers.FaultAddress.ToStringOrNull() ?? envelope.FaultAddress; envelope.Network = headers.Network; envelope.RetryCount = headers.RetryCount; if (headers.ExpirationTime.HasValue) envelope.ExpirationTime = headers.ExpirationTime.Value; }
public override void Send(ISendContext context) { GuardAgainstDisposed(); using (var body = new MemoryStream()) { context.SerializeTo(body); var msg = Encoding.UTF8.GetString(body.ToArray()); StompClient.Send(Address.Uri.PathAndQuery, msg); } }
public void PreDispatch(ISendContext context) { lock (_added) { Type messageType = context.DeclaringMessageType; if (_added.ContainsKey(messageType)) { return; } AddEndpointForType(messageType); } }
public void Send(ISendContext context) { _connectionHandler .Use(connection => { using (var body = new MemoryStream()) { context.SerializeTo(body); var msg = Encoding.UTF8.GetString(body.ToArray()); connection.Send(Address.Uri.PathAndQuery, msg); } }); }
public void PreDispatch(ISendContext context) { if (!string.IsNullOrEmpty(context.Headers[Constants.TenantIdKey])) { return; } object tenantId; if (_identificationStrategy.TryIdentifyTenant(out tenantId)) { context.SetHeader(Constants.TenantIdKey, tenantId.ToString()); } }
public bool Execute() { Uri uri = _uriString.ToUri("The from URI was invalid"); AbsolutePathName fullPath = PathName.GetAbsolutePathName(_name, Environment.CurrentDirectory); _log.DebugFormat("Using output path name: {0}", fullPath); string directoryName = Path.GetDirectoryName(fullPath.GetPath()); if (!System.IO.Directory.Exists(directoryName)) { System.IO.Directory.CreateDirectory(directoryName); } IOutboundTransport toTransport = Program.Transports.GetOutboundTransport(uri); ITextBlock text = new TextBlock() .BeginBlock("Load messages to URI: " + uri, ""); string[] files = System.IO.Directory.GetFiles(directoryName, fullPath.GetName() + "*.msg", SearchOption.TopDirectoryOnly) .OrderBy(x => x).ToArray(); int loadCount = 0; for (int i = 0; i < files.Length && loadCount < _count; i++) { string file = files[i]; string fileName = Path.Combine(directoryName, file); text.BodyFormat("Message File: {0}", file); ISendContext context = LoadMessageFromFile(fileName); toTransport.Send(context); if (_remove) { System.IO.File.Delete(fileName); } loadCount++; } _log.Info(text.ToString()); return(true); }
void IOutboundMessageInterceptor.PreDispatch(ISendContext context) { lock (_added) { Type messageType = context.DeclaringMessageType; if (_added.ContainsKey(messageType)) { return; } AddEndpointForType(messageType); } }
public static void SetUsingContext(this XmlMessageEnvelope envelope, ISendContext headers) { envelope.RequestId = headers.RequestId; envelope.ConversationId = headers.ConversationId; envelope.CorrelationId = headers.CorrelationId; envelope.SourceAddress = headers.SourceAddress.ToStringOrNull() ?? envelope.SourceAddress; envelope.DestinationAddress = headers.DestinationAddress.ToStringOrNull() ?? envelope.DestinationAddress; envelope.ResponseAddress = headers.ResponseAddress.ToStringOrNull() ?? envelope.ResponseAddress; envelope.FaultAddress = headers.FaultAddress.ToStringOrNull() ?? envelope.FaultAddress; envelope.Network = headers.Network; envelope.RetryCount = headers.RetryCount; envelope.MessageType = headers.MessageType ?? envelope.MessageType; if (headers.ExpirationTime.HasValue) envelope.ExpirationTime = headers.ExpirationTime.Value; }
private byte[] SerializeMessage(ISendContext context) { using (var stream = new MemoryStream()) { using (var streamWriter = new StreamWriter(stream)) { using (var jsonWriter = new JsonTextWriter(streamWriter)) { Serializer.Serialize(jsonWriter, context.Message); jsonWriter.Flush(); return stream.ToArray(); } } } }
public void Send(ISendContext context) { AddProducerBinding(); _connectionHandler.Use(connection => { try { IBasicProperties properties = _producer.CreateProperties(); properties.SetPersistent(true); properties.MessageId = context.MessageId ?? properties.MessageId ?? NewId.Next().ToString(); if (context.ExpirationTime.HasValue) { DateTime value = context.ExpirationTime.Value; properties.Expiration = (value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now). TotalMilliseconds.ToString("F0", CultureInfo.InvariantCulture); } using (var body = new MemoryStream()) { context.SerializeTo(body); properties.Headers = context.Headers.ToDictionary(entry => entry.Key, entry => entry.Value); properties.Headers["Content-Type"]=context.ContentType; _producer.Publish(_address.Name, properties, body.ToArray()); _address.LogSent(context.MessageId ?? "", context.MessageType); } } catch (AlreadyClosedException ex) { throw new InvalidConnectionException(_address.Uri, "Connection was already closed", ex); } catch (EndOfStreamException ex) { throw new InvalidConnectionException(_address.Uri, "Connection was closed", ex); } catch (OperationInterruptedException ex) { throw new InvalidConnectionException(_address.Uri, "Operation was interrupted", ex); } }); }
public void Send(ISendContext context) { GuardAgainstDisposed(); LoopbackMessage message = null; try { message = new LoopbackMessage(); if (context.ExpirationTime.HasValue) { message.ExpirationTime = context.ExpirationTime.Value; } context.SerializeTo(message.Body); message.ContentType = context.ContentType; message.OriginalMessageId = context.OriginalMessageId; if (!Monitor.TryEnter(_messageWriteLock, _deadlockTimeout)) throw new Exception("Deadlock detected!"); try { GuardAgainstDisposed(); _messages.AddLast(message); } finally { Monitor.Exit(_messageWriteLock); } Address.LogSent(message.MessageId, context.MessageType); } catch { if (message != null) message.Dispose(); throw; } _messageReady.Set(); }
public static void SetUsingContext(this Envelope envelope, ISendContext context) { envelope.RequestId = context.RequestId; envelope.ConversationId = context.ConversationId; envelope.CorrelationId = context.CorrelationId; envelope.SourceAddress = context.SourceAddress.ToStringOrNull() ?? envelope.SourceAddress; envelope.DestinationAddress = context.DestinationAddress.ToStringOrNull() ?? envelope.DestinationAddress; envelope.ResponseAddress = context.ResponseAddress.ToStringOrNull() ?? envelope.ResponseAddress; envelope.FaultAddress = context.FaultAddress.ToStringOrNull() ?? envelope.FaultAddress; envelope.Network = context.Network; envelope.RetryCount = context.RetryCount; if (context.ExpirationTime.HasValue) envelope.ExpirationTime = context.ExpirationTime.Value; foreach (var header in context.Headers) { envelope.Headers[header.Key] = header.Value; } }
public void Send(ISendContext context) { using (var message = new Message()) { if (!string.IsNullOrEmpty(context.MessageType)) message.Label = context.MessageType.Length > 250 ? context.MessageType.Substring(0, 250) : context.MessageType; message.Recoverable = _address.IsRecoverable; message.UseDeadLetterQueue = true; // in case lack of permission message will be redirected to dead letter if (context.ExpirationTime.HasValue) { DateTime value = context.ExpirationTime.Value; message.TimeToBeReceived = value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now; } context.SerializeTo(message.BodyStream); var headers = new TransportMessageHeaders(); if (!string.IsNullOrEmpty(context.ContentType)) headers.Add("Content-Type", context.ContentType); if (!string.IsNullOrEmpty(context.OriginalMessageId)) headers.Add("Original-Message-Id", context.OriginalMessageId); message.Extension = headers.GetBytes(); try { _connectionHandler.Use(connection => SendMessage(connection.Queue, message)); _address.LogSent(message.Id, context.MessageType); } catch (MessageQueueException ex) { HandleOutboundMessageQueueException(ex); } } }
public void Send(ISendContext context) { AddProducerBinding(); _connectionHandler.Use(connection => { try { IBasicProperties properties = _producer.Channel.CreateBasicProperties(); properties.SetPersistent(true); if (context.ExpirationTime.HasValue) { DateTime value = context.ExpirationTime.Value; properties.Expiration = (value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now). ToString(); } using (var body = new MemoryStream()) { context.SerializeTo(body); properties.Headers = new Hashtable {{"Content-Type", context.ContentType}}; _producer.Channel.BasicPublish(_address.Name, "", properties, body.ToArray()); _address.LogSent("", context.MessageType); } } catch (EndOfStreamException ex) { throw new InvalidConnectionException(_address.Uri, "Connection was closed", ex); } catch (OperationInterruptedException ex) { throw new InvalidConnectionException(_address.Uri, "Operation was interrupted", ex); } }); }
public void Send(ISendContext context) { GuardAgainstDisposed(); LoopbackMessage message = null; try { message = new LoopbackMessage(); if (context.ExpirationTime.HasValue) { message.ExpirationTime = context.ExpirationTime.Value; } context.SerializeTo(message.Body); message.ContentType = context.ContentType; lock (_messageLock) { GuardAgainstDisposed(); _messages.AddLast(message); } if (SpecialLoggers.Messages.IsInfoEnabled) SpecialLoggers.Messages.InfoFormat("SEND:{0}:{1}:{2}", Address, context.MessageType, message.MessageId); } catch { if (message != null) message.Dispose(); throw; } _messageReady.Set(); }
public void Send(ISendContext context) { using (var message = new Message()) { if (!string.IsNullOrEmpty(context.MessageType)) message.Label = context.MessageType.Length > 250 ? context.MessageType.Substring(0, 250) : context.MessageType; message.Recoverable = true; if (context.ExpirationTime.HasValue) { DateTime value = context.ExpirationTime.Value; message.TimeToBeReceived = value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now; } context.SerializeTo(message.BodyStream); if (context.ContentType != null) { var headers = new TransportMessageHeaders(); headers.Add("Content-Type", context.ContentType); message.Extension = headers.GetBytes(); } try { _connectionHandler.Use(connection => SendMessage(connection.Queue, message)); if (_messageLog.IsDebugEnabled) _messageLog.DebugFormat("SEND:{0}:{1}:{2}", _address.OutboundFormatName, message.Label, message.Id); } catch (MessageQueueException ex) { HandleOutboundMessageQueueException(ex); } } }
public void Send(ISendContext context) { DeclareBindings(); IBasicProperties properties = _channel.CreateBasicProperties(); properties.SetPersistent(true); if(context.ExpirationTime.HasValue) { var value = context.ExpirationTime.Value; properties.Expiration = (value.Kind == DateTimeKind.Utc ? value - SystemUtil.UtcNow : value - SystemUtil.Now).ToString(); } using(var body = new MemoryStream()) { context.SerializeTo(body); properties.Headers = new Hashtable {{"Content-Type", context.ContentType}}; _channel.BasicPublish(_address.Name, "", properties, body.ToArray()); if (SpecialLoggers.Messages.IsInfoEnabled) SpecialLoggers.Messages.InfoFormat("SEND:{0}:{1}", Address, context.MessageId); } }
// service bus best practices for performance: // http://msdn.microsoft.com/en-us/library/windowsazure/hh528527.aspx public void Send(ISendContext context) { AddProducerBinding(); _connectionHandler.Use(connection => { try { // don't have too many outstanding at same time // SpinWait.SpinUntil(() => _messagesInFlight < _settings.MaxOutstanding); using (var body = new MemoryStream()) { context.SerializeTo(body); body.Seek(0, SeekOrigin.Begin); // TODO put transient handling logic in here for retry var brokeredMessage = new BrokeredMessage(body, false); brokeredMessage.MessageId = context.MessageId ?? brokeredMessage.MessageId ?? NewId.Next().ToString(); if (context.ExpirationTime.HasValue) { DateTime value = context.ExpirationTime.Value; brokeredMessage.TimeToLive = (value.Kind == DateTimeKind.Utc ? value - DateTime.UtcNow : value - DateTime.Now); } if (!string.IsNullOrWhiteSpace(context.CorrelationId)) brokeredMessage.CorrelationId = context.CorrelationId; foreach (var header in context.Headers) brokeredMessage.Properties.Add(header.Key, header.Value); brokeredMessage.ContentType = context.ContentType; _producer.Send(brokeredMessage); } } catch (TimeoutException ex) { throw new InvalidConnectionException(_address.Uri, "Send operation timed out", ex); } catch (OperationCanceledException ex) { throw new InvalidConnectionException(_address.Uri, "Operation was cancelled", ex); } catch (Exception ex) { throw new InvalidConnectionException(_address.Uri, "Send threw an exception", ex); } }); }
public IEnumerable<Action<ISendContext>> Enumerate(ISendContext context) { return _output.Value.Enumerate(context); }
public abstract void Send(ISendContext context);
// service bus best practices for performance: // http://msdn.microsoft.com/en-us/library/windowsazure/hh528527.aspx public void Send(ISendContext context) { _connectionHandler .Use(connection => { // don't have too many outstanding at same time SpinWait.SpinUntil(() => _messagesInFlight < _settings.MaxOutstanding); using (var body = new MemoryStream()) { context.SerializeTo(body); // the envelope is re-usable, so let's capture it in the below closure // as a value var envelope = new MessageEnvelope(body.ToArray()); TrySendMessage(connection, () => { var brokeredMessage = new BrokeredMessage(envelope); if (!string.IsNullOrWhiteSpace(context.CorrelationId)) brokeredMessage.CorrelationId = context.CorrelationId; if (!string.IsNullOrWhiteSpace(context.MessageId)) brokeredMessage.MessageId = context.MessageId; return brokeredMessage; }, 1); } }); }
public override void Send(ISendContext context) { }
public override void Send(ISendContext context) { throw new NotImplementedException(); }
public Sent(ISendContext context, IEndpointAddress address, long timestamp) { _timestamp = timestamp; _context = context; _address = address; }
// service bus best practices for performance: // http://msdn.microsoft.com/en-us/library/windowsazure/hh528527.aspx public void Send(ISendContext context) { _connectionHandler .Use(connection => { // don't have too many outstanding at same time SpinWait.SpinUntil(() => _messagesInFlight < _settings.MaxOutstanding); using (var body = new MemoryStream()) { context.SerializeTo(body); // the envelope is re-usable, so let's capture it in the below closure // as a value var envelope = new MessageEnvelope(body.ToArray()); var sending = Retries.Retry(FaultPolicies.FinalAzurePolicy, new Func<AsyncCallback, object, IAsyncResult>((cb, state) => { return SendMessage(connection, () => { var brokeredMessage = new BrokeredMessage(envelope); if (!string.IsNullOrWhiteSpace(context.CorrelationId)) brokeredMessage.CorrelationId = context.CorrelationId; if (!string.IsNullOrWhiteSpace(context.MessageId)) brokeredMessage.MessageId = context.MessageId; return brokeredMessage; }, 1, cb, state); }), (IAsyncResult ar) => { var state = (StateHolder)ar.AsyncState; Interlocked.Decrement(ref _messagesInFlight); try { state.Sender.EndSend(ar); Address.LogEndSend(state.Message.MessageId); } finally { // always dispose the message; it's only good once state.Message.Dispose(); } }); sending.Wait(); } }); }
void LogSent(ISendContext context, IBasicProperties properties) { _address.LogSent(context.MessageId ?? properties.MessageId ?? "", context.MessageType); }
public void Send(ISendContext context) { _log.DebugFormat("Discarding message on {0}: {1}", _address, context.MessageType); }
public void Send(ISendContext context) { _outbound.Send(context); }