NServiceBus.Compression 5.0.1

dotnet add package NServiceBus.Compression --version 5.0.1                
NuGet\Install-Package NServiceBus.Compression -Version 5.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NServiceBus.Compression" Version="5.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NServiceBus.Compression --version 5.0.1                
#r "nuget: NServiceBus.Compression, 5.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NServiceBus.Compression as a Cake Addin
#addin nuget:?package=NServiceBus.Compression&version=5.0.1

// Install NServiceBus.Compression as a Cake Tool
#tool nuget:?package=NServiceBus.Compression&version=5.0.1                

NServiceBus.Compression

Adds message body compression to the NServiceBus pipeline.

When to use

Compressing message bodies can be useful when the message body exceeds the transports its maximum message size or just in general to reduce network IO.

Transport Maximum size
MSMQ 4MB
Azure Service Bus Standard 256KB
Azure Service Bus Premium 100MB
RabbitMQ No limit

Note: In the past the maximum message size for Azure Service Bus was much smaller.

Alternatives

Compression only works well on text-based payloads like XML and Json any payload (text or binary) that contains repetitive data.

  1. Use a binary serializer
  2. Use the claim check pattern for binary message attachments via https://github.com/NServiceBusExtensions/NServiceBus.Attachments
  3. Use any of the above in combination with compression

Version compatibility

NServiceBus NServiceBus.Compression
v5.x v1.x
v6.x v2.x
v7.x v3.x
v8.x v4.x
v9.x v5.x

Please note that there might be versions targeting other NServiceBus versions. Please check the Releases for all versions. or check the root of the master branch of the repository.

Introduction

This package is based on the mutator example from the NServiceBus documentation website but is has these additional features:

  • Drop in auto enable compresssion, no need to recompile! Can be saviour if affected by production incidents due to unable to send too large messages.
  • Requires messages to be of a minimal size but this thresshold is configurable.
  • Compression level can be configured to have more flexibility between CPU cycles and message size.
  • Uses a header similar as the http specification Content-Encoding.

Configuration

The defaults are:

  • Size treshold: 1,000 bytes
  • Compression level: Fastest

This is to not spend CPU cycles on messages that are small. Compression not only costs CPU cycles but also introduces latency both during outgoing (compression) and incoming (decompression) messages.

The following only compresses messages over 16KB in size and uses the highest compression level.

endpointConfiguration.CompressMessageBody(System.IO.Compression.CompressionLevel.Optimal, 16 * 1024);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.0.1 2,600 6/14/2024
4.0.0 3,151 12/9/2022
3.0.0 5,926 5/26/2020
2.0.0 1,087 5/26/2020
1.0.0 574 5/26/2020