diff --git a/docs/guide/messages.md b/docs/guide/messages.md index 10685a91a..43ab7a0de 100644 --- a/docs/guide/messages.md +++ b/docs/guide/messages.md @@ -12,7 +12,7 @@ to the proper handler that can handle that message. Here's some facts about mess The default serialization option is [System.Text.Json](https://learn.microsoft.com/en-us/dotnet/api/system.text.json?view=net-8.0), as this is now mature, seems to work with just about anything now, and sets you up for relatively easy integration with a range of external non-Wolverine applications. You also have the option to fall back -to Newtonsoft.JSON or to use higher performance [MemoryPack](/guide/messages.html#memorypack-serialization) or [MessagePack](/guide/messages.html#messagepack-serialization) integrations with Wolverine. +to Newtonsoft.JSON or to use higher performance [MemoryPack](/guide/messages.html#memorypack-serialization) or [MessagePack](/guide/messages.html#messagepack-serialization) or [Protobuf](/guide/messages.html#protobuf-serialization) integrations with Wolverine. ## Message Type Name or Alias @@ -295,7 +295,44 @@ using var host = await Host.CreateDefaultBuilder() snippet source | anchor +### Protobuf Serialization +Wolverine supports Google's data interchange format [Protobuf](https://github.com/protocolbuffers/protobuf) through the `WolverineFx.Protobuf` Nuget package. +To enable Protobuf serialization through the entire application, use: + + + +```cs +using var host = await Host.CreateDefaultBuilder() + .UseWolverine(opts => + { + // Make Protobuf the default serializer throughout this application + opts.UseProtobufSerialization(); + }).StartAsync(); +``` +snippet source | anchor + + +Likewise, you can use Protobuf on selected endpoints like this: + + + +```cs +using var host = await Host.CreateDefaultBuilder() + .UseWolverine(opts => + { + // Use Protobuf on a local queue + opts.LocalQueue("one").UseProtobufSerialization(); + + // Use Protobuf on a listening endpoint + opts.ListenAtPort(2223).UseProtobufSerialization(); + + // Use Protobuf on one subscriber + opts.PublishAllMessages().ToPort(2222).UseProtobufSerialization(); + }).StartAsync(); +``` +snippet source | anchor + diff --git a/src/Extensions/Wolverine.Protobuf.Tests/Samples.cs b/src/Extensions/Wolverine.Protobuf.Tests/Samples.cs new file mode 100644 index 000000000..2aa32ab49 --- /dev/null +++ b/src/Extensions/Wolverine.Protobuf.Tests/Samples.cs @@ -0,0 +1,41 @@ +using Microsoft.Extensions.Hosting; +using Wolverine.Transports.Tcp; + +namespace Wolverine.Protobuf.Tests; + +public class Samples +{ + public async Task bootstrap() + { + #region sample_using_protobuf_for_the_default_for_the_app + + using var host = await Host.CreateDefaultBuilder() + .UseWolverine(opts => + { + // Make Protobuf the default serializer throughout this application + opts.UseProtobufSerialization(); + }).StartAsync(); + + #endregion + } + + public async Task bootstrap_selectively() + { + #region sample_using_protobuf_on_selected_endpoints + + using var host = await Host.CreateDefaultBuilder() + .UseWolverine(opts => + { + // Use Protobuf on a local queue + opts.LocalQueue("one").UseProtobufSerialization(); + + // Use Protobuf on a listening endpoint + opts.ListenAtPort(2223).UseProtobufSerialization(); + + // Use Protobuf on one subscriber + opts.PublishAllMessages().ToPort(2222).UseProtobufSerialization(); + }).StartAsync(); + + #endregion + } +} \ No newline at end of file diff --git a/src/Wolverine/Configuration/HandlerDiscovery.Diagnostics.cs b/src/Wolverine/Configuration/HandlerDiscovery.Diagnostics.cs index 8d46fa6b3..39a45e8d3 100644 --- a/src/Wolverine/Configuration/HandlerDiscovery.Diagnostics.cs +++ b/src/Wolverine/Configuration/HandlerDiscovery.Diagnostics.cs @@ -124,7 +124,7 @@ private void writeAssemblyIsNotRegistered(WolverineOptions options, Type candida writer.WriteLine("To fix this, add the assembly to your application by either:"); writer.WriteLine("1. Either add the [assembly: WolverineModule] attribute to this assembly"); writer.WriteLine( - $"2. Or add WolverineOptions.Discovery.IncludeAssembly({candidateType.FullNameInCode()}.Assembly); within your UseWolverine() setup"); + $"2. Or add `WolverineOptions.Discovery.IncludeAssembly(typeof({candidateType.FullNameInCode()}).Assembly);` within your UseWolverine() setup"); writer.WriteLine(); if (options.ApplicationAssembly != null)