MagicOnion

Unified Realtime/API framework for .NET platform and Unity.

MIT License

Stars
3.7K
Committers
44

Bot releases are visible (Hide)

MagicOnion - 6.1.3 Latest Release

Published by github-actions[bot] 6 months ago

What's Changed

Fixes

Housekeeping

New Contributors

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/6.1.2...6.1.3

MagicOnion - 6.1.2

Published by github-actions[bot] 7 months ago

What's Changed

  • Update pre-built Source Generator for Unity

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/6.1.1...6.1.2

MagicOnion - 6.1.1

Published by github-actions[bot] 7 months ago

What's Changed

Breaking Changes

Other Changes

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/6.1.0...6.1.1

MagicOnion - 6.1.0

Published by github-actions[bot] 7 months ago

Features

Add StreamingHub OnConnected support by @riversdark0 in https://github.com/Cysharp/MagicOnion/pull/745

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.

Allow DynamicArgumentTuple as a reference type on Unity in https://github.com/Cysharp/MagicOnion/pull/747

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.

[Preview] Introduce IStreamingHubDiagnosticHandler in https://github.com/Cysharp/MagicOnion/pull/746

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);
}

What's Changed

Breaking Changes

Other Changes

New Contributors

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/6.0.1...6.1.0

MagicOnion - 6.0.1

Published by github-actions[bot] 9 months ago

[!NOTE]
This release is only for Unity users.

What's Changed

Fixes

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/6.0.0...6.0.1

MagicOnion - 6.0.0

Published by github-actions[bot] 9 months ago

Highlights

MagicOnion.Client.SourceGenerator in https://github.com/Cysharp/MagicOnion/pull/688

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.

Supported development environments

  • Unity 2021.3.0f1 or later
  • .NET 6 or later
  • Visual Studio 2022 version 17.2 or later
  • Rider 2023.1 or later

Usage

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);
}

Source generation options

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.

Breaking changes

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.

Introduce ServiceContext.SetRawBytesResponse in https://github.com/Cysharp/MagicOnion/pull/677

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.

Add StreamingHub metrics in https://github.com/Cysharp/MagicOnion/pull/716

This release introduces metrics related to StreamingHub using System.Diagnostics.Metrics.

Meter: MagicOnion.Server

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

Tags

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)

Breaking Changes

Use Grpc.Net.Client by default on Unity in https://github.com/Cysharp/MagicOnion/pull/704

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

Other Breaking Changes

What's Changes

Features

Other Changes

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.8...6.0.0

MagicOnion - Ver.5.1.8

Published by github-actions[bot] over 1 year ago

What's Changed

Other Changes

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.7...5.1.8

MagicOnion - Ver.5.1.7

Published by github-actions[bot] over 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.6...5.1.7

MagicOnion - Ver.5.1.6

Published by github-actions[bot] over 1 year ago

What's Changed

Other Changes

New Contributors

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.5...5.1.6

MagicOnion - Ver.5.1.5

Published by github-actions[bot] over 1 year ago

What's Changed

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.2...5.1.5

MagicOnion - Ver.5.1.4

Published by github-actions[bot] over 1 year ago

What's Changed

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.2...5.1.4

MagicOnion - Ver.5.1.3

Published by github-actions[bot] over 1 year ago

What's Changed

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.2...5.1.3

MagicOnion - Ver.5.1.2

Published by github-actions[bot] over 1 year ago

What's Changed

Other Changes

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.1.0...5.1.2

MagicOnion - Ver.5.1.0

Published by github-actions[bot] over 1 year ago

⚠ Important: Fixes handling of null values in request/response. in https://github.com/Cysharp/MagicOnion/pull/610

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.

Breaking changes

ResponseContext<T> class is now abstract and ResponseContext<T>.Create method is used instead of a constructor.

What's Changed

Bug Fixes

Other Changes

New Contributors

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.0.2...5.1.0

MagicOnion - Ver.5.0.2

Published by github-actions[bot] almost 2 years ago

What's Changed

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.0.1...5.0.2

MagicOnion - Ver.5.0.1

Published by github-actions[bot] almost 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/5.0.0...5.0.1

MagicOnion - Ver.5.0.0

Published by github-actions[bot] almost 2 years ago

Highlights

Update supporting platforms

  • Bump supported Unity version to 2020.3 (LTS) or later (C# 8.0)
  • Add support for .NET 7 and drop support for .NET Core 3.1, .NET 5 on servers

Adopt to .NET 7 and drop support for .NET Core 3.1, .NET 5 on servers #573

MagicOnion now supports .NET 7 and we drop support for .NET Core 3.1 and .NET 5 on servers.

  • MagicOnion.Server supports only .NET 7 and .NET 6.
  • MagicOnion.Client continues to support .NET Standard 2.x.
    • If the client application which built/run on .NET 5 or .NET Core 3.1 runtime, it still can depend on the package for .NET Standard.

Non-Generic UnaryResult #579

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);

Breaking changes

UnaryResult has changed from static class to struct.

Allow ValueTask as a return type of the hub method. #583

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();
}

Rework Server-side Filter APIs #552

Introduce 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.

Breaking changes

  • IMagicOnionFilterFactory<T> has been moved under MagicOnion.Server.Filters namespace.

Minor changes

  • Use ServiceProvider and ActivatorUtilities to create an instance of filter or filter factory
  • Specifying the implicit order of filters: [Manually ordered filters] -> [Global Filters] -> [Class Filters] -> [Method Filters]
    • The filters have int.MaxValue as the implicit order by default.

Read and write directly to the buffer using IBufferWriter when calling Unary #496

Read and write directly to the buffer using IBufferWriter when calling Unary.
Unary requests can be processed up to 5-10% more efficiently.

Breaking changes

  • Remove request/response parameter from IMagicOnionLogger
  • Remove MagicOnionLogToLoggerWithDataDump, MagicOnionLogToLoggerWithNamedDataDump
  • Change the signature of SetRawRequest / GetRawRequest from byte[] to object

Rework {Server,Client,Duplex}Streaming #558

Change {Server,Client,Duplex}Streaming message processing on the server to IBufferWriter-based.

Breaking changes

  • Remove data parameter from IMagicOnionLogger.WriteToStream, IMagicOnionLogger.ReadFromStream

Rework MagicOnionClient #530

MagicOnionClient client now uses IBufferWriter<T>.
Marshaller wrapper API for encryption will be worked on in a separate PR.

Improvements

  • More efficient memory usages
    • Use buffers directly for serialization to reduce unnecessary byte allocation.
  • DynamicClientBuilder and MagicOnionGenerator produce very similar code generation.

Breaking changes

  • Bump supported Unity version to 2020.3 (LTS) or later (C# 8.0)
  • RequestMutator and ResponseMutator are no longer supported.
    • We plan to introduce a new wrapper API for Marshaller.
  • Task<UnaryResult<T>> is no longer supported as a return type of Unary method.
    • Use UnaryResult<T> instead.
  • moc (MagicOnion.Generator) is no longer published to GitHub Releases.
    • We recommend that the generator be used with .NET CLI Tool.

Extensible message serialization #577

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.

Breaking changes

  • Client: MagicOnionClient and StreamingHubClient now receives IMagicOnionSerializerProvider instead of MessagePackSerializerOptions.
  • Server: Use MagicOnionOptions.MessageSerializer instead of MagicOnionOptions.SerializerOptions

New APIs

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+ #578

Use ModuleInitializer for automatic registration on .NET 5+. When an application running on .NET 5+ uses a generated client, MagicOnionInitializer.Register() is automatically called.

Notable changes

Option --no-use-unity-attr is obsoleted, please use --disable-auto-register instead.

Support for serialization using MemoryPack #590

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);

Using with Code Generator

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.

What's Changed

Breaking Changes

Features

Other Changes

New Contributors

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/4.5.2...5.0.0

MagicOnion - Ver.4.5.2

Published by github-actions[bot] about 2 years ago

What's Changed

Other Changes

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/4.5.1...4.5.2

MagicOnion - Ver.4.5.1

Published by github-actions[bot] over 2 years ago

What's Changed

Other Changes

New Contributors

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/4.5.0...4.5.1

MagicOnion - Ver.4.5.0

Published by github-actions[bot] over 2 years ago

What's Changed

Breaking Changes

Reduce the maximum number of method parameters in https://github.com/Cysharp/MagicOnion/pull/519

Limit the number of parameters allowed in a Unary/StreamingHub method for Blazor WebAssembly (AOT) to 15.

Other Changes

New Contributors

Full Changelog: https://github.com/Cysharp/MagicOnion/compare/4.4.1...4.5.0