Example #1
0
 internal MessageDeferred(TimeSpan delay, object commandMessage, Dictionary<string, string> optionalHeaders)
 {
     if (commandMessage == null) throw new ArgumentNullException(nameof(commandMessage));
     Delay = delay;
     CommandMessage = commandMessage;
     OptionalHeaders = optionalHeaders?.Clone();
 }
        /// <summary>
        /// Saves the data from the given source stream under the given ID
        /// </summary>
        public async Task Save(string id, Stream source, Dictionary<string, string> metadata = null)
        {
            metadata = metadata?.Clone() ?? new Dictionary<string, string>();

            if (_dataCompressionMode == DataCompressionMode.Explicit)
            {
                string contentEncoding;

                if (!metadata.TryGetValue(MetadataKeys.ContentEncoding, out contentEncoding))
                {
                    await _innerDataBusStorage.Save(id, source, metadata);
                    return;
                }

                // who knows what the user did to the data? the user must know how to decode this data
                if (!string.Equals(contentEncoding, "gzip", StringComparison.OrdinalIgnoreCase))
                {
                    await _innerDataBusStorage.Save(id, source, metadata);
                    return;
                }
            }
            
            metadata[MetadataKeys.ContentEncoding] = "gzip";

            using (var destination = new MemoryStream())
            {
                using (var gzipStream = new GZipStream(destination, CompressionLevel.Optimal, true))
                {
                    await source.CopyToAsync(gzipStream);
                }

                destination.Position = 0;

                await _innerDataBusStorage.Save(id, destination, metadata);
            }
        }
Example #3
0
 internal MessagePublished(object eventMessage, Dictionary<string, string> optionalHeaders)
 {
     if (eventMessage == null) throw new ArgumentNullException(nameof(eventMessage));
     EventMessage = eventMessage;
     OptionalHeaders = optionalHeaders?.Clone();
 }
Example #4
0
 internal MessageSent(object commandMessage, Dictionary<string, string> optionalHeaders)
 {
     if (commandMessage == null) throw new ArgumentNullException(nameof(commandMessage));
     OptionalHeaders = optionalHeaders?.Clone();
     CommandMessage = commandMessage;
 }
Example #5
0
 internal ReplyMessageSent(object replyMessage, Dictionary<string, string> optionalHeaders)
 {
     if (replyMessage == null) throw new ArgumentNullException(nameof(replyMessage));
     ReplyMessage = replyMessage;
     OptionalHeaders = optionalHeaders?.Clone();
 }