Unified Realtime/API framework for .NET platform and Unity.
MIT License
Bot releases are visible (Hide)
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/6.1.2...6.1.3
Published by github-actions[bot] 7 months ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/6.1.1...6.1.2
Published by github-actions[bot] 7 months ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/6.1.0...6.1.1
Published by github-actions[bot] 7 months ago
Introduced the event OnConnected
after a connection is established with a client on the server's StreamingHub.
This differs from OnConnecting
in that the client is notified that the connection is complete and can then communicate via Broadcast.
This PR allows DynamicArgumentTuple as a reference type on Unity.
Unity IL2CPP builds often have issues with the code size due to generics and value types.
MAGICONION_USE_REFTYPE_DYNAMICARGUMENTTUPLE
build constant allows DynamicArgumentTuple
to be treated as a reference type.
This PR introduces an API for diagnosing and tracing the communication of StreamingHub. The API is in preview and may be subject to change in the future.
This API only supports the Source Generator at this moment and you need to set the EnableStreamingHubDiagnosticHandler
option to true
in the generation options. By setting this option, the StreamingHubDiagnosticHandler
property will be added to the generated class, allowing you to set a handler.
namespace MagicOnion.Client;
/// <summary>
/// [Preview] The interface of the handler for StreamingHub diagnostics. This API may change in the future.
/// </summary>
public interface IStreamingHubDiagnosticHandler
{
/// <summary>
/// The callback method at the beginning of a Hub method request. This API may change in the future.
/// </summary>
void OnRequestBegin<THub, TRequest>(THub hubInstance, Guid requestId, string methodName, TRequest request, bool isFireAndForget);
/// <summary>
/// [Preview] The callback method at the end of a Hub method request. This API may change in the future.
/// </summary>
void OnRequestEnd<THub, TResponse>(THub hubInstance, Guid requestId, string methodName, TResponse response);
/// <summary>
/// [Preview] The callback method when a method of HubReceiver is invoked. This API may change in the future.
/// </summary>
void OnBroadcastEvent<THub, T>(THub hubInstance, string methodName, T value);
}
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/6.0.1...6.1.0
Published by github-actions[bot] 9 months ago
[!NOTE]
This release is only for Unity users.
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/6.0.0...6.0.1
Published by github-actions[bot] 9 months ago
This release introduces a source generator for platform that require pre-generated client code (e.g. Unity, NativeAOT, MAUI ...).
The source generator also replaces MagicOnion.Generator (moc).
MagicOnion.Client.SourceGenerator is shipped with MagicOnion.Client package. This means that you no longer need to the install generator tool (moc) and setup additional build steps.
Define a partial
class with any name of your choosing within the application. Mark it with the MagicOnionClientGeneration
attribute, and specify any service type found within the assembly where you want to search for the service interface.
For example, if the MyApp.Shared
assembly contains MyApp.Shared.Services.IGreeterService
and MyApp.Shared.Hubs.IChatHub
, specify one of them.
using MagicOnion.Client;
[MagicOnionClientGeneration(typeof(MyApp.Shared.Services.IGreeterService))]
partial class MagicOnionGeneratedClientInitializer {}
Next, configure MessagePack to use the generated MessagePack Resolver. This is the same as when using the legacy MagicOnion.Generator.
#if UNITY_2019_4_OR_NEWER
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.BeforeSceneLoad)]
#elif NET5_0_OR_GREATER
[System.Runtime.CompilerServices.ModuleInitializer]
#endif
static void RegisterResolvers()
{
StaticCompositeResolver.Instance.Register(
// Add: Use MessagePack formatter resolver generated by the source generator.
MagicOnionGeneratedClientInitializer.Resolver,
MessagePack.Resolvers.GeneratedResolver.Instance,
BuiltinResolver.Instance,
PrimitiveObjectResolver.Instance
);
MessagePackSerializer.DefaultOptions = MessagePackSerializer.DefaultOptions
.WithResolver(StaticCompositeResolver.Instance);
}
You can specify options in the named constructor of the attribute.
DisableAutoRegistration
: Sets whether to disable automatically calling Register
during start-up. (Automatic registration requires .NET 5+ or Unity)MessagePackFormatterNamespace
: Sets the namespace of pre-generated MessagePackFormatters. The default value is MessagePack.Formatters
.Serializer
: Sets the serializer used for message serialization. The default value is GenerateSerializerType.MessagePack
.MagicOnion.Generator (moc) has been removed. The legacy generator is no longer supported.
[!WARNING]
While there is currently compatibility between MagicOnion.Client and MagicOnion.Generator (moc), there is no guarantee that this will be maintained.
This PR introduces ServiceContext.SetRawBytesResponse
method.
This method allows you to set raw byte sequences as a response. This makes it possible to send a cached response body without serialization.
public override async ValueTask Invoke(ServiceContext context, Func<ServiceContext, ValueTask> next)
{
if (ResponseBytesCache.TryGetValue(context.CallContext.Method, out var cachedBytes))
{
context.SetRawBytesResponse(cachedBytes);
return;
}
await next(context);
ResponseBytesCache[context.CallContext.Method] = MessagePackSerializer.Serialize(context.Result);
}
[!NOTE]
The raw byte sequence must be serialized as a MessagePack (or custom serialization) format. MagicOnion will write a byte requence directly into the response buffer.
This release introduces metrics related to StreamingHub using System.Diagnostics.Metrics.
Metric | Unit | Tags |
---|---|---|
magiconion.server.streaminghub.connections | {connection} |
rpc.system , rpc.service
|
magiconion.server.streaminghub.method_duration | ms |
rpc.system , rpc.service , rpc.method
|
magiconion.server.streaminghub.method_completed | {request} |
rpc.system , rpc.service , rpc.method , magiconion.streaminghub.is_error
|
magiconion.server.streaminghub.exceptions | {exception} |
rpc.system , rpc.service , rpc.method , error.type
|
Tag name | Value |
---|---|
rpc.system | magiconion |
rpc.service | StreamingHub interface name (e.g. IGreeterService ) |
rpc.method | StreamingHub method name (e.g. HelloAsync ) |
magiconion.streaminghub.is_error | Whether a StreamingHub method call succeeded or failed. (e.g. true or false ) |
error.type | Thrown exception type (e.g. System.InvalidOperationException ) |
This release changes the default gRPC library in Unity to grpc-dotnet.
From this release, the recommended gRPC library combination is YetAnotherHttpHandler and grpc-dotnet.
However, at this time, we are still supporting C-core. If you continue to use the C-core gRPC library, please define USE_GRPC_CCORE
in "Scripting Define Symbols". We recommend transitioning as there is the possibility of removing support in the future.
refs: #661
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.8...6.0.0
Published by github-actions[bot] over 1 year ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.7...5.1.8
Published by github-actions[bot] over 1 year ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.6...5.1.7
Published by github-actions[bot] over 1 year ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.5...5.1.6
Published by github-actions[bot] over 1 year ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.2...5.1.5
Published by github-actions[bot] over 1 year ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.2...5.1.4
Published by github-actions[bot] over 1 year ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.2...5.1.3
Published by github-actions[bot] over 1 year ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.0...5.1.2
Published by github-actions[bot] over 1 year ago
Version 5.0.x series cannot handle null
passed in the request and response.
If the request/response is value type (struct
) or if the method takes more than one argument, it is not affected, but we strongly recommend upgrading.
ResponseContext<T>
class is now abstract and ResponseContext<T>.Create
method is used instead of a constructor.
OpenTelemetry
to 1.3.2
version by @moreal in https://github.com/Cysharp/MagicOnion/pull/608
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.0.2...5.1.0
Published by github-actions[bot] almost 2 years ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.0.1...5.0.2
Published by github-actions[bot] almost 2 years ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.0.0...5.0.1
Published by github-actions[bot] almost 2 years ago
MagicOnion now supports .NET 7 and we drop support for .NET Core 3.1 and .NET 5 on servers.
Non-generic UnaryResult
is the return type of a service method that does not return a value. It replaces UnaryResult<Nil>
, which is similar to Task
and ValueTask
.
// Shared interface:
public interface IMyService : IService<IMyService>
{
UnaryResult MethodAsync(int arg0);
}
// Server-side:
public class MyService : ServiceBase<IMyService>, IMyService
{
public async UnaryResult MethodAsync(int arg0)
{
// Do something ...
// The method does not return any value. (like void, ValueTask, Task)
}
}
// Client-side:
await client.MethodAsync(1234);
UnaryResult
has changed from static class
to struct
.
MagicOnion 5.0 allows ValueTask
and ValueTask<T>
as a return type of the hub method. Previously, only Task
wereTask<T>
was allowed.
public interface IMyHub : IStreamingHub<IMyHub, IMyHubReceiver>
{
ValueTask FooAsync();
ValueTask<int> BarAsync();
}
IMagicOnionServiceFilter
, IStreamingHubFilter
The filter implementation changes from overriding attributes to implementing interfaces.
IMagicOnionServiceFilter
IStreamingHubFilter
IMagicOnionFilterFactory<T>
IMagicOnionOrderedFilter
This makes for a more flexible implementation, such as implementing both Unary filter and StreamingHub filter.
public class MyDualFilterAttribute : Attribute, IMagicOnionServiceFilter, IStreamingHubFilter, IMagicOnionOrderedFilter
{
public int Order { get; set; } = int.MaxValue;
ValueTask IMagicOnionServiceFilter.Invoke(ServiceContext context, Func<ServiceContext, ValueTask> next) { ... }
ValueTask IStreamingHubFilter.Invoke(StreamingHubContext context, Func<StreamingHubContext, ValueTask> next) { ... }
}
public class MyFilterAttribute : Attribute, IMagicOnionFilterFactory<IMagicOnionServiceFilter>, IMagicOnionOrderedFilter
{
public int Order { get; set; } = int.MaxValue;
public IMagicOnionServiceFilter CreateInstance(IServiceProvider serviceProvider)
=> new FilterImpl();
class FilterImpl : IMagicOnionServiceFilter
{
public ValueTask Invoke(ServiceContext context, Func<ServiceContext, ValueTask> next) { ... }
}
}
This changes MagicOnionFilterAttribute
, StreamingHubFilterAttribute
as follows:
// 4.x or earlier
public abstract class MagicOnionFilterAttribute : Attribute { ... }
public abstract class StreamingHubFilterAttribute : Attribute { ... }
// 5.0
public abstract class MagicOnionFilterAttribute : Attribute, IMagicOnionServiceFilter, IMagicOnionOrderedFilter { ... }
public abstract class StreamingHubFilterAttribute : Attribute, IStreamingHubFilter, IMagicOnionOrderedFilter { ... }
These have methods for implementation and can continue to be overridden.
IMagicOnionFilterFactory<T>
has been moved under MagicOnion.Server.Filters
namespace.[Manually ordered filters] -> [Global Filters] -> [Class Filters] -> [Method Filters]
int.MaxValue
as the implicit order by default.Read and write directly to the buffer using IBufferWriter when calling Unary.
Unary requests can be processed up to 5-10% more efficiently.
request
/response
parameter from IMagicOnionLogger
MagicOnionLogToLoggerWithDataDump
, MagicOnionLogToLoggerWithNamedDataDump
SetRawRequest
/ GetRawRequest
from byte[]
to object
Change {Server,Client,Duplex}Streaming message processing on the server to IBufferWriter-based.
data
parameter from IMagicOnionLogger.WriteToStream
, IMagicOnionLogger.ReadFromStream
MagicOnionClient client now uses IBufferWriter<T>
.
Marshaller wrapper API for encryption will be worked on in a separate PR.
RequestMutator
and ResponseMutator
are no longer supported.
Task<UnaryResult<T>>
is no longer supported as a return type of Unary method.
UnaryResult<T>
instead.moc
(MagicOnion.Generator) is no longer published to GitHub Releases.
MagicOnion uses MessagePack for serialization by default, but it also provides extension points to customize serialization.
It allows for customization, such as encryption and the using of serializers other than MessagePack.
IMagicOnionSerializerProvider
instead of MessagePackSerializerOptions
.MagicOnionOptions.MessageSerializer
instead of MagicOnionOptions.SerializerOptions
public interface IMagicOnionSerializerProvider
{
IMagicOnionSerializer Create(MethodType methodType, MethodInfo? methodInfo);
}
public interface IMagicOnionSerializer
{
void Serialize<T>(IBufferWriter<byte> writer, in T? value);
T? Deserialize<T>(in ReadOnlySequence<byte> bytes);
}
public static class MagicOnionSerializerProvider
{
public static IMagicOnionSerializerProvider Default { get; set; } = MessagePackMagicOnionSerializerProvider.Default;
}
Use ModuleInitializer for automatic registration on .NET 5+. When an application running on .NET 5+ uses a generated client, MagicOnionInitializer.Register()
is automatically called.
Option --no-use-unity-attr
is obsoleted, please use --disable-auto-register
instead.
Adds support for serialization using MemoryPack. (Preview)
Set MemoryPackMagicOnionSerializerProvider
to MagicOnionSerializerProvider
on the client and server to serialize using MemoryPack.
MagicOnionSerializerProvider.Default = MemoryPackMagicOnionSerializerProvider.Instance;
// or
await StreamingHubClient.ConnectAsync<IMyHub, IMyHubReceiver>(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
MagicOnionClient.Create<IMyService>(channel, MemoryPackMagicOnionSerializerProvider.Instance);
If you want to use MagicOnion.Generator (moc), you need to specify --serializer MemoryPack
as an option.
The generated code will use MemoryPack instead of MessagePack.
The application must also call MagicOnionMemoryPackFormatterProvider.RegisterFormatters()
on startup.
UnaryResult()
and ReturnNil()
helper methods by @mayuki in https://github.com/Cysharp/MagicOnion/pull/589
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/4.5.2...5.0.0
Published by github-actions[bot] about 2 years ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/4.5.1...4.5.2
Published by github-actions[bot] over 2 years ago
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/4.5.0...4.5.1
Published by github-actions[bot] over 2 years ago
Limit the number of parameters allowed in a Unary/StreamingHub method for Blazor WebAssembly (AOT) to 15.
using
when only Grpc.Net.Client is used on Unity in https://github.com/Cysharp/MagicOnion/pull/518
Full Changelog: https://github.com/Cysharp/MagicOnion/compare/4.4.1...4.5.0