/ServiceBus.CompressionPlugin

Azure Service Bus Compression Plugin

Primary LanguageC#MIT LicenseMIT

Icon

Allows sending and receiving compressed messages.

license develop opened issues

NuGet package

NuGet Status

Available here http://nuget.org/packages/ServiceBus.CompressionPlugin

To Install from the NuGet Package Manager Console

PM> Install-Package ServiceBus.CompressionPlugin

Examples

Using default compression (GZip, body of at least 1500 bytes)

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

Overriding minimum body size

var sender = new MessageSender(connectionString, queueName);
sender.RegisterCompressionPlugin(1024); // compress messages using GZip with at least 1024 bytes

Custom compressions

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

Transitioning to a different compression or receiving a different compression

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);

Who's trusting this plugin in production

Proudly list your company here if use this plugin in production

Icon

Created by Eucalyp from the Noun Project.