This is a plugin for Microsoft.Azure.ServiceBus client
Allows sending and receiving compressed messages.
Available here http://nuget.org/packages/ServiceBus.CompressionPlugin
To Install from the NuGet Package Manager Console
PM> Install-Package ServiceBus.CompressionPlugin
Configuration and registration
var sender = new MessageSender(connectionString, queueName);
sender.RegisterCompressionPlugin();
Sending
var payload = new MyMessage { ... };
var serialized = JsonConvert.SerializeObject(payload);
var payloadAsBytes = Encoding.UTF8.GetBytes(serialized);
var message = new Message(payloadAsBytes);
Receiving
var receiver = new MessageReceiver(connectionString, entityPath, ReceiveMode.ReceiveAndDelete);
receiver.RegisterCompressionPlugin();
var msg = await receiver.ReceiveAsync().ConfigureAwait(false);
// msg will contain the original payload
var sender = new MessageSender(connectionString, queueName);
sender.RegisterCompressionPlugin(1024); // compress messages using GZip with at least 1024 bytes
Configuration and registration
var configuration = new CompressionConfiguration(compressionMethodName: "noop", compressor: bytes => Task.FromResult, decompressor: bytes => Task.FromResult, minimumSize: 1);
var sender = new MessageSender(connectionString, queueName);
sender.RegisterCompressionPlugin(configuration);
Sending
var payload = new MyMessage { ... };
var serialized = JsonConvert.SerializeObject(payload);
var payloadAsBytes = Encoding.UTF8.GetBytes(serialized);
var message = new Message(payloadAsBytes);
Receiving
var receiver = new MessageReceiver(connectionString, entityPath, ReceiveMode.ReceiveAndDelete);
receiver.RegisterCompressionPlugin(configuration);
var msg = await receiver.ReceiveAsync().ConfigureAwait(false);
// msg will contain the original payload
To transition to a different compression or process messages compressed used a different method, additional decompressors can be registered to ensure messages in flight compressed using older/other methods are handled properly.
configuration = new CompressionConfiguration(/* new version of compression */);
configuration.AddDecompressor(compressionMethodName: "old compression method name", decompressor: bytes => Task.FromResult);
configuration.AddDecompressor(compressionMethodName: "other compression method name", decompressor: bytes => Task.FromResult);
Proudly list your company here if use this plugin in production
Created by Eucalyp from the Noun Project.