Install
| Product | Versions |
|---|---|
| .NET | |
| .NET Standard |
README
Microsoft Orleans Serialization for Protobuf
Introduction
Microsoft Orleans Serialization for Protobuf provides Protocol Buffers (Protobuf) serialization support for Microsoft Orleans using Google.Protobuf. This package integrates Google's official Google.Protobuf library with Orleans, allowing you to use Protocol Buffers messages in your grain interfaces and implementations.
Getting Started
To use this package, install it via NuGet:
dotnet add package Microsoft.Orleans.Serialization.Protobuf
Example - Configuring Protobuf Serialization
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Orleans.Hosting;
using Orleans.Serialization;
var builder = Host.CreateApplicationBuilder(args)
.UseOrleans(siloBuilder =>
{
siloBuilder
.UseLocalhostClustering()
// Configure Protobuf as a serializer
.AddSerializer(serializerBuilder => serializerBuilder.AddProtobufSerializer());
});
// Run the host
await builder.RunAsync();
Using Protobuf Types with Orleans
This package supports types generated from .proto files using Google.Protobuf. For detailed information on creating Protobuf messages and configuring your project, see Create Protobuf messages for .NET apps.
Once you have defined your Protobuf messages and configured code generation, you can use them directly in your grain interfaces:
using Orleans;
using MyApp.Models;
public interface IMyGrain : IGrainWithStringKey
{
Task<MyProtobufClass> GetData();
Task SetData(MyProtobufClass data);
}
public class MyGrain : Grain, IMyGrain
{
private MyProtobufClass _data;
public Task<MyProtobufClass> GetData() => Task.FromResult(_data);
public Task SetData(MyProtobufClass data)
{
_data = data;
return Task.CompletedTask;
}
}
Note: Google.Protobuf collection types (RepeatedField<T>, MapField<TKey, TValue>, and ByteString) are automatically supported.
Documentation
For more comprehensive documentation, please refer to:
- Create Protobuf messages for .NET apps - Official guide for working with Protobuf in .NET
- Microsoft Orleans Documentation
- Orleans Serialization
Feedback & Contributing
- If you have any issues or would like to provide feedback, please open an issue on GitHub
- Join our community on Discord
- Follow the @msftorleans Twitter account for Orleans announcements
- Contributions are welcome! Please review our contribution guidelines
- This project is licensed under the MIT license
Changes from Previous Version
Adoption Assessment
A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.