public void Enqueue(TransportMessage transportMessage, Stream stream) { Guard.AgainstNull(transportMessage, "transportMessage"); Guard.AgainstNull(stream, "stream"); if (transportMessage.HasExpired()) { return; } AccessQueue(() => { var model = GetChannel().Model; var properties = model.CreateBasicProperties(); properties.Persistent = _parser.Persistent; properties.CorrelationId = transportMessage.MessageId.ToString(); if (transportMessage.HasExpiryDate()) { var milliseconds = (long)(transportMessage.ExpiryDate - DateTime.Now).TotalMilliseconds; if (milliseconds < 1) { return; } properties.Expiration = milliseconds.ToString(); } model.BasicPublish("", _parser.Queue, false, properties, stream.ToBytes()); }); }
public void Enqueue(TransportMessage transportMessage, Stream stream) { Guard.AgainstNull(transportMessage, nameof(transportMessage)); Guard.AgainstNull(stream, nameof(stream)); if (_disposed) { throw new RabbitMQQueueException(string.Format(Resources.QueueDisposed, Uri.Secured())); } if (transportMessage.HasExpired()) { return; } AccessQueue(() => { var model = GetChannel().Model; var properties = model.CreateBasicProperties(); properties.Persistent = _parser.Persistent; properties.CorrelationId = transportMessage.MessageId.ToString(); if (transportMessage.HasExpiryDate()) { var milliseconds = (long)(transportMessage.ExpiryDate - DateTime.Now).TotalMilliseconds; if (milliseconds < 1) { return; } properties.Expiration = milliseconds.ToString(); } if (transportMessage.HasPriority()) { if (transportMessage.Priority > 255) { transportMessage.Priority = 255; } properties.Priority = (byte)transportMessage.Priority; } ReadOnlyMemory <byte> data; if (stream is MemoryStream ms && ms.TryGetBuffer(out var segment)) { var length = (int)ms.Length; data = new ReadOnlyMemory <byte>(segment.Array, segment.Offset, length); }
public void Enqueue(TransportMessage transportMessage, Stream stream) { var timeToBeReceived = transportMessage.ExpiryDate - DateTime.Now; if (transportMessage.HasExpired() || (timeToBeReceived < _millisecondTimeSpan)) { return; } var sendMessage = new Message { Recoverable = true, UseDeadLetterQueue = _parser.UseDeadLetterQueue, Label = transportMessage.MessageId.ToString(), CorrelationId = string.Format(@"{0}\1", transportMessage.MessageId), BodyStream = stream }; if (transportMessage.HasExpiryDate()) { sendMessage.TimeToBeReceived = timeToBeReceived; } try { using (var queue = CreateQueue()) { queue.Send(sendMessage, MessageQueueTransactionType.Single); } } catch (MessageQueueException ex) { if (ex.MessageQueueErrorCode == MessageQueueErrorCode.AccessDenied) { AccessDenied(_log, _parser.Path); } _log.Error(string.Format(MsmqResources.SendMessageIdError, transportMessage.MessageId, Uri, ex.AllMessages())); throw; } catch (Exception ex) { _log.Error(string.Format(MsmqResources.SendMessageIdError, transportMessage.MessageId, Uri, ex.AllMessages())); throw; } }
public void Enqueue(TransportMessage transportMessage, Stream stream) { Guard.AgainstNull(transportMessage, nameof(transportMessage)); Guard.AgainstNull(stream, nameof(stream)); if (transportMessage.HasExpired()) { return; } AccessQueue(() => { var model = GetChannel().Model; var properties = model.CreateBasicProperties(); properties.Persistent = _parser.Persistent; properties.CorrelationId = transportMessage.MessageId.ToString(); if (transportMessage.HasExpiryDate()) { var milliseconds = (long)(transportMessage.ExpiryDate - DateTime.Now).TotalMilliseconds; if (milliseconds < 1) { return; } properties.Expiration = milliseconds.ToString(); } if (transportMessage.HasPriority()) { if (transportMessage.Priority > 255) { transportMessage.Priority = 255; } properties.Priority = (byte)transportMessage.Priority; } byte[] data = null; if (stream is MemoryStream ms && ms.TryGetBuffer(out var segment)) { data = segment.Array; var length = (int)ms.Length; if (segment.Offset != 0 || data.Length != length) { // we can't use any buffer pool since Rabbit needs the exact size buffer, so copy the data to a new array var destinationData = new byte[length]; Buffer.BlockCopy(data, segment.Offset, destinationData, 0, length); data = destinationData; } } if (data == null) { data = stream.ToBytes(); } model.BasicPublish(string.Empty, _parser.Queue, false, properties, data); }); }