Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion docs/guide/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -295,7 +295,44 @@ using var host = await Host.CreateDefaultBuilder()
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Extensions/Wolverine.MemoryPack.Tests/Samples.cs#L24-L39' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_memorypack_on_selected_endpoints' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### 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:

<!-- snippet: sample_using_protobuf_for_the_default_for_the_app -->
<a id='snippet-sample_using_protobuf_for_the_default_for_the_app'></a>
```cs
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
// Make Protobuf the default serializer throughout this application
opts.UseProtobufSerialization();
}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Extensions/Wolverine.Protobuf.Tests/Samples.cs#L10-L19' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_protobuf_for_the_default_for_the_app' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Likewise, you can use Protobuf on selected endpoints like this:

<!-- snippet: sample_using_protobuf_on_selected_endpoints -->
<a id='snippet-sample_using_protobuf_on_selected_endpoints'></a>
```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();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Extensions/Wolverine.Protobuf.Tests/Samples.cs#L24-L39' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_protobuf_on_selected_endpoints' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->



Expand Down
41 changes: 41 additions & 0 deletions src/Extensions/Wolverine.Protobuf.Tests/Samples.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading